New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

openweathermap-ts

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openweathermap-ts - npm Package Compare versions

Comparing version

to
1.2.3

@@ -0,1 +1,5 @@

#### 1.2.3 (2020-05-20)
- Fix unit and langauge bugs.
#### 1.2.2 (2020-05-20)

@@ -2,0 +6,0 @@

@@ -6,7 +6,7 @@ import { Unit, CountryCode, Language, QueryType, InitialSettings, Location, SetCurrentWeatherByCityName, GetByCityName, GetByCityId, GetByGeoCoordinates } from './types';

private location;
constructor({ apiKey, units, language, }: InitialSettings);
constructor({ apiKey, units, language }: InitialSettings);
setApiKey(apiKey: string): void;
setUnits(units: Unit): void;
setLanguage(language: Language): void;
setCityName({ cityName, state, countryCode, }: SetCurrentWeatherByCityName): void;
setCityName({ cityName, state, countryCode }: SetCurrentWeatherByCityName): void;
setCityId(cityId: number): void;

@@ -22,5 +22,5 @@ setGeoCoordinates(latitude: number, longitude: number): void;

getByCityId({ cityId, queryType }: GetByCityId): Promise<unknown>;
getByGeoCoordinates({ latitude, longitude, queryType, }: GetByGeoCoordinates): Promise<unknown>;
getByGeoCoordinates({ latitude, longitude, queryType }: GetByGeoCoordinates): Promise<unknown>;
getByZipcode(zipcode: number, queryType: QueryType, countryCode?: CountryCode): Promise<unknown>;
}
export default OpenWeather;

@@ -58,3 +58,3 @@ "use strict";

units: units,
language: language,
language: language
};

@@ -65,3 +65,3 @@ this.location = {

geoCoordinates: {},
zipcode: {},
zipcode: {}
};

@@ -105,3 +105,3 @@ this.BASE_URL = helpers_1.HOST + helpers_1.API_VERSION;

units: 'imperial',
language: 'en',
language: 'en'
};

@@ -114,3 +114,3 @@ };

geoCoordinates: {},
zipcode: {},
zipcode: {}
};

@@ -136,3 +136,3 @@ };

var _a = this, BASE_URL = _a.BASE_URL, settings = _a.settings;
return BASE_URL + queryType + "?" + query + "&appid=" + settings.apiKey;
return BASE_URL + queryType + "?" + query + "&appid=" + settings.apiKey + "&units=" + settings.units + "&lang=" + settings.language;
};

@@ -139,0 +139,0 @@ // ***

{
"name": "openweathermap-ts",
"version": "1.2.2",
"version": "1.2.3",
"description": "An abstract layer over openWeatherMap APIs",

@@ -5,0 +5,0 @@ "main": "dist/app.js",

@@ -1,2 +0,2 @@

import fetch from 'node-fetch'
import fetch from 'node-fetch';
import {

@@ -12,10 +12,10 @@ Unit,

GetByCityId,
GetByGeoCoordinates,
} from './types'
import { HOST, API_VERSION } from './helpers'
GetByGeoCoordinates
} from './types';
import { HOST, API_VERSION } from './helpers';
class OpenWeather {
private settings: InitialSettings
private BASE_URL: string
private location: Location
private settings: InitialSettings;
private BASE_URL: string;
private location: Location;

@@ -25,3 +25,3 @@ constructor({

units = 'imperial',
language = 'en',
language = 'en'
}: InitialSettings) {

@@ -31,4 +31,4 @@ this.settings = {

units,
language,
}
language
};
this.location = {

@@ -38,5 +38,5 @@ city: {},

geoCoordinates: {},
zipcode: {},
}
this.BASE_URL = HOST + API_VERSION
zipcode: {}
};
this.BASE_URL = HOST + API_VERSION;
}

@@ -51,11 +51,11 @@

public setApiKey(apiKey: string) {
this.settings.apiKey = apiKey
this.settings.apiKey = apiKey;
}
public setUnits(units: Unit) {
this.settings.units = units
this.settings.units = units;
}
public setLanguage(language: Language) {
this.settings.language = language
this.settings.language = language;
}

@@ -66,3 +66,3 @@

state,
countryCode,
countryCode
}: SetCurrentWeatherByCityName) {

@@ -73,8 +73,8 @@ this.location.city = {

state,
countryCode,
}
countryCode
};
}
public setCityId(cityId: number) {
this.location.cityId = cityId
this.location.cityId = cityId;
}

@@ -86,4 +86,4 @@

latitude,
longitude,
}
longitude
};
}

@@ -95,4 +95,4 @@

zipcode,
countryCode,
}
countryCode
};
}

@@ -104,4 +104,4 @@

units: 'imperial',
language: 'en',
}
language: 'en'
};
}

@@ -114,4 +114,4 @@

geoCoordinates: {},
zipcode: {},
}
zipcode: {}
};
}

@@ -126,7 +126,7 @@

public getAllSettings() {
return this.settings
return this.settings;
}
public getAllLocations() {
return this.location
return this.location;
}

@@ -141,5 +141,7 @@

private buildURL(queryType: QueryType, query: string) {
const { BASE_URL, settings } = this
const { BASE_URL, settings } = this;
return `${BASE_URL + queryType}?${query}&appid=${settings.apiKey}`
return `${BASE_URL + queryType}?${query}&appid=${settings.apiKey}&units=${
settings.units
}&lang=${settings.language}`;
}

@@ -159,23 +161,23 @@

`cityName missing, please pass it via argument or set it using setCityName method`
)
);
}
const cityName = location?.cityName || this.location.city.cityName
const state = location?.state || this.location.city.state
const cityName = location?.cityName || this.location.city.cityName;
const state = location?.state || this.location.city.state;
const countryCode =
location?.countryCode || this.location.city.countryCode
location?.countryCode || this.location.city.countryCode;
const query = `q=${cityName}${state ? ',' + state : ''}${
countryCode ? ',' + countryCode : ''
}`
const request = this.buildURL(queryType, query)
}`;
const request = this.buildURL(queryType, query);
const response = await fetch(request)
const currentWeather = await response.json()
const response = await fetch(request);
const currentWeather = await response.json();
resolve(currentWeather)
resolve(currentWeather);
} catch (error) {
reject(error)
reject(error);
}
})
});
}

@@ -186,3 +188,3 @@

try {
const { location } = this
const { location } = this;

@@ -192,18 +194,18 @@ if (!cityId && !location.cityId) {

`cityId missing, please pass it via argument or set it using setCityId method`
)
);
}
cityId = cityId || location.cityId
cityId = cityId || location.cityId;
const query = `id=${cityId}`
const request = this.buildURL(queryType, query)
const query = `id=${cityId}`;
const request = this.buildURL(queryType, query);
const response = await fetch(request)
const currentWeather = await response.json()
const response = await fetch(request);
const currentWeather = await response.json();
resolve(currentWeather)
resolve(currentWeather);
} catch (error) {
reject(error)
reject(error);
}
})
});
}

@@ -214,3 +216,3 @@

longitude,
queryType,
queryType
}: GetByGeoCoordinates) {

@@ -226,19 +228,19 @@ return new Promise(async (resolve, reject) => {

`latitude or longitude missing, please pass it via argument or set it using setGeoCoordinates method`
)
);
}
latitude = latitude || this.location.geoCoordinates.latitude
longitude = longitude || this.location.geoCoordinates.longitude
latitude = latitude || this.location.geoCoordinates.latitude;
longitude = longitude || this.location.geoCoordinates.longitude;
const query = `lat=${latitude}&lon=${longitude}`
const request = this.buildURL(queryType, query)
const query = `lat=${latitude}&lon=${longitude}`;
const request = this.buildURL(queryType, query);
const response = await fetch(request)
const currentWeather = await response.json()
const response = await fetch(request);
const currentWeather = await response.json();
resolve(currentWeather)
resolve(currentWeather);
} catch (error) {
reject(error)
reject(error);
}
})
});
}

@@ -253,3 +255,3 @@

try {
const { location } = this
const { location } = this;

@@ -259,21 +261,21 @@ if (!zipcode && !location.zipcode.zipcode) {

`zipcode missing, please pass it via argument or set it using setZipcode method`
)
);
}
zipcode = zipcode || location.zipcode.zipcode
zipcode = zipcode || location.zipcode.zipcode;
const query = `zip=${zipcode}${countryCode ? ',' + countryCode : ''}`
const request = this.buildURL(queryType, query)
const query = `zip=${zipcode}${countryCode ? ',' + countryCode : ''}`;
const request = this.buildURL(queryType, query);
const response = await fetch(request)
const currentWeather = await response.json()
const response = await fetch(request);
const currentWeather = await response.json();
resolve(currentWeather)
resolve(currentWeather);
} catch (error) {
reject(error)
reject(error);
}
})
});
}
}
export default OpenWeather
export default OpenWeather;