Edits history of script submission #17205 for ' Search for places. Complete words required. (meteosource)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    /**
     * Search for places. Complete words required.
     * ## Search for places
    
    You can use this endpoint to obtain `place_id` of the location you want, to be used in `point` endpoint.
     */
    export async function main(
    	auth: RT.Meteosource,
    	text: string | undefined,
    	language?: 'cs' | 'en' | 'de' | 'es' | 'fr' | 'pl' | 'pt' | undefined,
    	key?: string | undefined
    ) {
    	const url = new URL(`https://www.meteosource.com/api/v1/${auth.tier}/find_places`)
    	for (const [k, v] of [
    		['text', text],
    		['language', language],
    		['key', key]
    	]) {
    		if (v !== undefined && v !== '') {
    			url.searchParams.append(k, v)
    		}
    	}
    	const response = await fetch(url, {
    		method: 'GET',
    		headers: {
    			'X-API-Key': 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