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
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
- iOS 10.2
- Swift 3
- Xcode 8
OpenWeatherMapAPIConsumer is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "OpenWeatherMapAPIConsumer"
import OpenWeatherMapAPIConsumer
// Type by default OpenWeatherMapType.Current
let weatherAPI = OpenWeatherMapAPI(apiKey: "YOUR_API_KEY")
// Type forecast
let weatherAPI = OpenWeatherMapAPI(apiKey: "YOUR_API_KEY", forType: OpenWeatherMapType.Forecast)
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)
public func setSearchAccuracy(searchAccuracy : SearchAccuracyType)
public func setLimitationOfResult(in limitation : Int)
public func setTemperatureUnit(unit : TemperatureFormat)
public func setMultilingualSupport(language : Language)
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
}
}
})
The response classes are parsers, that give you a better use of the api response
- CurrentResponseOpenWeatherMap(data : Data)
- ForecastResponseOpenWeatherMap(data : Data)
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
Jose Luis Cardosa, [email protected]
OpenWeatherMapAPIConsumer is available under the MIT license. See the LICENSE file for more info.