Edits history of script submission #21037 for ' Event Search (yelp)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Yelp = {
      apiKey: string;
    };
    /**
     * Event Search
     * Returns events that match search criteria
     */
    export async function main(
      auth: Yelp,
      locale: string | undefined,
      offset: string | undefined,
      limit: string | undefined,
      sort_by: "asc" | "desc" | undefined,
      sort_on: "popularity" | "time_start" | undefined,
      start_date: string | undefined,
      end_date: string | undefined,
      categories: string | undefined,
      is_free: string | undefined,
      excluded_events: string | undefined,
      location: string | undefined,
      latitude: string | undefined,
      longitude: string | undefined,
      radius: string | undefined,
    ) {
      const url = new URL(`https://api.yelp.com//v3/events`);
      for (const [k, v] of [
        ["locale", locale],
        ["offset", offset],
        ["limit", limit],
        ["sort_by", sort_by],
        ["sort_on", sort_on],
        ["start_date", start_date],
        ["end_date", end_date],
        ["categories", categories],
        ["is_free", is_free],
        ["excluded_events", excluded_events],
        ["location", location],
        ["latitude", latitude],
        ["longitude", longitude],
        ["radius", radius],
      ]) {
        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