An open API service indexing awesome lists of open source software.

https://github.com/jolucama/openweathermapapiconsumer

Free version API Consumer to get the current and forecast weather of Open Weather Map
https://github.com/jolucama/openweathermapapiconsumer

api-consumer cocoapods ios-lib swift-3 weather

Last synced: about 1 year ago
JSON representation

Free version API Consumer to get the current and forecast weather of Open Weather Map

Awesome Lists containing this project

README

          

# OpenWeatherMapAPIConsumer

Open Weather Map API Consumer fully Unit Tested, being able to get current weather and 3-hourly forecast 5 days for your city. Helpful stats, temperature, clouds, pressure, wind around your location... This API is a consumer of Open Weather Map and the description of the api may be found here

Note: In the consumer has been implemented just the free version of the API. In order to start using it, please register and get the API Key Sign up

[![Build Status](https://travis-ci.org/jolucama/OpenWeatherMapAPIConsumer.svg?branch=master)](https://travis-ci.org/jolucama/OpenWeatherMapAPIConsumer)
[![Version](https://img.shields.io/cocoapods/v/OpenWeatherMapAPIConsumer.svg?style=flat)](http://cocoapods.org/pods/OpenWeatherMapAPIConsumer)
[![License](https://img.shields.io/cocoapods/l/OpenWeatherMapAPIConsumer.svg?style=flat)](http://cocoapods.org/pods/OpenWeatherMapAPIConsumer)
[![Platform](https://img.shields.io/cocoapods/p/OpenWeatherMapAPIConsumer.svg?style=flat)](http://cocoapods.org/pods/OpenWeatherMapAPIConsumer)

## Example

To run the example project, clone the repo, and run `pod install` from the Example directory first.




Basically, the example makes use of the CLLocationManager to obtain the current coordenates, and then make a request to our API to get all the displayed information. All the code is located in View Controller

## Requirements

- iOS 10.2
- Swift 3
- Xcode 8

## Installation

OpenWeatherMapAPIConsumer is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:

```ruby
pod "OpenWeatherMapAPIConsumer"
```
## Usage

### Import the pod in your file

```swift
import OpenWeatherMapAPIConsumer
```

### Setup the api key

```swift

// Type by default OpenWeatherMapType.Current
let weatherAPI = OpenWeatherMapAPI(apiKey: "YOUR_API_KEY")

// Type forecast
let weatherAPI = OpenWeatherMapAPI(apiKey: "YOUR_API_KEY", forType: OpenWeatherMapType.Forecast)

```

### Set the location using

```swift

public func weather(byLatitude latitude : Double, andLongitude longitude : Double)

public func weather(byCityName cityName : String)

public func weather(byCityName cityName : String, andCountryCode countryCode: String)

// List of city ids may be found here: http://bulk.openweathermap.org/sample/
public func weather(byCityId cityId : Int)

```

### API Options

```swift
public func setSearchAccuracy(searchAccuracy : SearchAccuracyType)

public func setLimitationOfResult(in limitation : Int)

public func setTemperatureUnit(unit : TemperatureFormat)

public func setMultilingualSupport(language : Language)
```

### Perform request

```swift
public func performWeatherRequest(completionHandler: @escaping (Data?, URLResponse?, Error?) -> Swift.Void)

//Example
weatherAPI.performWeatherRequest(completionHandler:{(data: Data?, urlResponse: URLResponse?, error: Error?) in
if (error != nil) {
//Handling error
} else {
do {
let responseWeatherApi = try CurrentResponseOpenWeatherMap(data: data!)
} catch let error as Error {
//Handling error
}
}
})

```

### Response classes

The response classes are parsers, that give you a better use of the api response

- CurrentResponseOpenWeatherMap(data : Data)
- ForecastResponseOpenWeatherMap(data : Data)

```swift

func getCoord() -> CLLocationCoordinate2D

func getTemperature() -> Float

func getPressure() -> Float

func getHumidity() -> Float

func getTempMax() -> Float

func getTempMin() -> Float

func getCityName() -> String

func getIconList() -> IconList

func getDescription() -> String

func getWindSpeed() -> Float

func getDate() -> Date

```

## Author

Jose Luis Cardosa, jlcardosa@gmail.com

## License

OpenWeatherMapAPIConsumer is available under the MIT license. See the LICENSE file for more info.