Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular service to use weatherforecast api from http://openweathermap.org/api #2

Open
shafaiatul opened this issue Jun 4, 2015 · 2 comments

Comments

@shafaiatul
Copy link

// SERVICES
weatherApp.service('cityService', function() {

this.city = "New York, NY";

});

//taking the weather API info and make a service out of it and then I will have the flexibility to use the service somewhere else
weatherApp.service('weatherService', ['$resource', function ($resource) {

this.GetWeather = function (city, days) {
var apiKey = '75ab4a21554c3eea638f0493fc501db1';
var weatherAPI = 
    $resource("http://api.openweathermap.org/data/2.5/forecast/daily", { callback: "JSON_CALLBACK" }, { get: { method: "JSONP" }});

return weatherAPI.get({ q: city, cnt: days, APPID: apiKey });
};

}]);

_Hope this helps_***

@atufkas
Copy link
Owner

atufkas commented Jun 4, 2015

Hi @shafaiatul, thanks for that suggestion. Yeah, there's plenty of room to modularize the code for different situations. It's currently just serving the needs of the basic project motivation like stated in the README. I'm actually going to enhance this project soon and will take into account how and what kind .service() abstractions will make life easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@atufkas @shafaiatul and others