当前位置: 首页>>代码示例>>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;未经允许,请勿转载。