Giter Club home page Giter Club logo

kfopenweathermapapi's Introduction

#KFOpenWeatherMapAPI Client for iOS and OSX

A client connecting to the OpenWeatherMap API for fetching current weather data, interval/daily forecasts, and searching cities.

#Installation Add

pod 'KFOpenWeatherMapAPI'

to your podfile and run

pod install

Initialize the client with your API key obtained from http://openweathermap.org/login and an api version (currently 2.5):

self.apiClient = [[KFOpenWeatherMapAPIClient alloc] initWithAPIKey:@"1111111111" andAPIVersion:@"2.5"];

for a full documentation see http://docs.kf-interactive.com/KFOpenWeatherMapAPI

You can request weather data for a city by its name, its OpenWeatherMap city id, or by its geo location. For more acurate results you can #Usage ##Current Weather For requesting the current weather for Los Angeles use:

[self.apiClient weatherForCityName:@"Los Angeles" withResultBlock:^(BOOL success, id responseData, NSError *error)
{
    if (success)
    {
        KFOWMWeatherResponseModel *responseModel = (KFOWMWeatherResponseModel *)responseData;
        NSLog(@"received weather: %@, temperature: %@ K, %@%%rH, %@ mbar", responseModel.cityName, responseModel.mainWeather.temperature, responseModel.mainWeather.humidity, responseModel.mainWeather.pressure);
    }
    else
    {
        NSLog(@"could not get weather: %@", error);
    }
}];

This will return a KFOWMWeatherResponseModel including all data from the api parsed as native objects:
KFOpenWeatherMapAPI[6102:c07] received weather: Los Angeles, temperature: 292.65 K, 71%rH, 1011 mbar

##Forecast

To get the forecast for Los Angeles for the next hours call

[self.apiClient forecastForCityName:@"Los Angeles" withResultBlock:^(BOOL success, id responseData, NSError *error)
{
    if (success)
    {
        KFOWMForecastResponseModel *responseModel = (KFOWMForecastResponseModel *)responseData;
        
        NSString *humidity = [[responseModel.list valueForKeyPath:@"mainWeather.humidity"] componentsJoinedByString:@"%rH, "];
        NSLog(@"received forecast: %@, humidity: %@", responseModel.city.cityName, humidity);
    }
    else
    {
        NSLog(@"could not get forecast: %@", error);
    }
}];

and you get a KFOWMForecastResponseModel:
KFOpenWeatherMapAPI[6448:c07] received forecast: Los Angeles, humidity: 80%rH, 70%rH, 67%rH, 66%rH, โ€ฆ

##Daily Forecast

For getting a daily forecast for 4 days for Los Angeles use

[self.apiClient dailyForecastForCityName:@"Los Angeles" numberOfDays:4 withResultBlock:^(BOOL success, id responseData, NSError *error)
{
    if (success)
    {
        KFOWMDailyForecastResponseModel *responseModel = (KFOWMDailyForecastResponseModel *)responseData;
        NSLog(@"received daily forecast: %@, %@", responseModel.city.cityName, [[responseModel.list valueForKeyPath:@"temperature.day"] componentsJoinedByString:@" K, "]);
    }
    else
    {
        NSLog(@"could not get daily forecast: %@", error);
    }
}];

that returns a KFOWMDailyForecastResponseModel:
KFOpenWeatherMapAPI[6605:c07] received daily forecast: Los Angeles, 299.71 K, 299.93 K, 300.69 K, 301.13 K ##Search To search for a phrase you can call

[self.apiClient searchForPhrase:@"London" numberOfResults:10 withResultBlock:^(BOOL success, id responseData, NSError *error)
{
    if (success)
    {
        KFOWMSearchResponseModel *responseModel = (KFOWMSearchResponseModel *)responseData;
        NSMutableArray *foundCities = [NSMutableArray new];
        for (KFOWMWeatherResponseModel *listModel in responseModel.list)
        {
            NSString *city = [NSString stringWithFormat:@"%@, %@", listModel.cityName, listModel.systemInfo.country];
            [foundCities addObject:city];
        }
        NSLog(@"search results: %@", [foundCities componentsJoinedByString:@", "]);
    }
    else
    {
        NSLog(@"could not get search results: %@", error);
    }
}];

that will result in a KFOWMSearchResponseModel:
KFOpenWeatherMapAPI[6976:c07] search results: London, GB, London, CA, London, US, London, US

#License This code is distributed under the terms and conditions of the MIT license.

#Author Rico Becker
@ricobeck
https://twitter.com/ricobeck

kfopenweathermapapi's People

Contributors

ricobeck avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.