當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript common.HttpService類代碼示例

本文整理匯總了TypeScript中@nestjs/common.HttpService的典型用法代碼示例。如果您正苦於以下問題:TypeScript HttpService類的具體用法?TypeScript HttpService怎麽用?TypeScript HttpService使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了HttpService類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: ForecastRain

    getRainPrediction3Hours(lat: number, lon: number): Observable<ForecastRain[]> {
        const result$ = this.httpService.get('https://graphdata.buienradar.nl/forecast/json/?lat=' + lat + '&lon=' + lon);

        return result$.pipe(map((data: AxiosResponse) => {
            const rainForecasts: ForecastRain[] = [];

            if (data.data && data.data.forecasts) {
                for (const forecast of data.data.forecasts) {
                    rainForecasts.push(new ForecastRain(moment(forecast.utcdatetime), forecast.precipitation));
                }
            }
            return rainForecasts;
        }));
    }
開發者ID:beele,項目名稱:WeatherGenieV2-Backend,代碼行數:14,代碼來源:buienradar.service.ts

示例2: locateIp

 private async locateIp(ip: string = ''): Promise<Coordinates> {
     try {
         // Note: ip-api returns 200 OK even on invalid requests.
         const data = await this.http.get(`http://ip-api.com/json/${ip}`).toPromise();
         if (data['data'].status === 'fail') {
             throw new Error(data['data'].message);
         }
         const point = {
             lat: data['data'].lat,
             lng: data['data'].lon,
         };
         return point;
     }
     catch (e) {
         const message = e !== undefined ? e : 'IP location service request failed.';
         throw new Error(message);
     }
 }
開發者ID:elisiondesign,項目名稱:meteo-api,代碼行數:18,代碼來源:geo-locate.service.ts

示例3: ForecastHour

    getForecastedWeather(id: number): Observable<Forecast> {
        const result$ = this.httpService.get('https://api.buienradar.nl/data/forecast/1.1/all/' + id);

        return result$.pipe(map((data: AxiosResponse) => {

            const days: ForecastDay[] = [];
            for (const forecastedDay of data.data.days) {

                const hours: ForecastHour[] = [];
                if (forecastedDay.hours && forecastedDay.hours.length > 0) {
                    for (const forecastedHour of forecastedDay.hours) {
                        hours.push(
                            new ForecastHour(
                                // Times are in UTC!
                                moment(forecastedHour.date),
                                forecastedHour.temperature, forecastedHour.feeltemperature,
                                forecastedHour.iconcode, this.convertForecastIconCodeToWeatherCondition(forecastedHour.iconcode),
                                forecastedHour.windspeed, forecastedHour.beaufort, forecastedHour.winddirection,
                                forecastedHour.humidity, forecastedHour.precipitation, forecastedHour.precipitationmm,
                                forecastedHour.uvindex, forecastedHour.sunshine, forecastedHour.sunpower,
                            ),
                        );
                    }
                }

                days.push(
                    new ForecastDay(
                        // Times are in UTC!
                        moment(forecastedDay.date),
                        moment(forecastedDay.sunrise), moment(forecastedDay.sunset),
                        forecastedDay.temperature, forecastedDay.feeltemperature, forecastedDay.mintemp, forecastedDay.maxtemp,
                        forecastedDay.iconcode, this.convertForecastIconCodeToWeatherCondition(forecastedDay.iconcode),
                        forecastedDay.windspeed, forecastedDay.beaufort, forecastedDay.winddirection,
                        forecastedDay.precipitation, forecastedDay.uvindex,
                        hours,
                    ),
                );
            }

            return new Forecast(data.data.location.lat, data.data.location.lon, data.data.altitude, data.data.elevation, days);
        }));
    }
開發者ID:beele,項目名稱:WeatherGenieV2-Backend,代碼行數:42,代碼來源:buienradar.service.ts

示例4: findLocationId

    findLocationId(city: string): Observable<City[]> {
        const uri = 'https://api.buienradar.nl/data/search/1.0/?query=' + city + '&country=BE&locale=nl-BE';
        const result$: Observable<AxiosResponse> = this.httpService.get(uri);

        return Observable.create((obs) => {
            const cities: City[] = [];
            result$.subscribe((data: AxiosResponse) => {
                    const dataIndex: number = data.data.length > 1 ? (data.data.length - 1) : 0;
                    if (data.data.length > 0) {
                        for (const singleCity of data.data[dataIndex].results) {
                            const uriPieces: string[] = singleCity.uri.split('/');
                            cities.push(new City(Number(uriPieces[uriPieces.length - 1]), singleCity.main, singleCity.sub));
                        }
                    }
                }, (error) => {
                    console.log(error);
                },
                () => {
                    obs.next(cities);
                    obs.complete();
                });
        });
    }
開發者ID:beele,項目名稱:WeatherGenieV2-Backend,代碼行數:23,代碼來源:buienradar.service.ts


注:本文中的@nestjs/common.HttpService類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。