Edits history of script submission #21039 for ' Food Delivery Search (yelp)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Yelp = {
      apiKey: string;
    };
    /**
     * Food Delivery Search
     * This endpoint returns a list of businesses which support requested transaction type.
    
    **Note:**
    * At this time, the API does not return businesses without any reviews.
    * Currently, this endpoint only supports food delivery in the US.
    
     */
    export async function main(
      auth: Yelp,
      transaction_type: "delivery" = "delivery",
      latitude: string | undefined,
      longitude: string | undefined,
      location: string | undefined,
      term: string | undefined,
      categories: string | undefined,
      price: string | undefined,
    ) {
      const url = new URL(
        `https://api.yelp.com/v3/transactions/${transaction_type}/search`,
      );
      for (const [k, v] of [
        ["latitude", latitude],
        ["longitude", longitude],
        ["location", location],
        ["term", term],
        ["categories", categories],
        ["price", price],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Bearer " + auth.apiKey,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago