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
- Host: GitHub
- URL: https://github.com/jolucama/openweathermapapiconsumer
- Owner: jolucama
- License: mit
- Created: 2016-12-24T04:31:18.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-11-10T14:18:42.000Z (over 8 years ago)
- Last Synced: 2025-04-13T14:07:41.636Z (about 1 year ago)
- Topics: api-consumer, cocoapods, ios-lib, swift-3, weather
- Language: Swift
- Homepage: https://cocoapods.org/pods/OpenWeatherMapAPIConsumer
- Size: 256 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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
[](https://travis-ci.org/jolucama/OpenWeatherMapAPIConsumer)
[](http://cocoapods.org/pods/OpenWeatherMapAPIConsumer)
[](http://cocoapods.org/pods/OpenWeatherMapAPIConsumer)
[](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.