OpenWeatherFreeClient 0.1.1

OpenWeatherFreeClient 0.1.1

Maintained by perseusrealdeal.



  • By
  • perseusrealdeal

OpenWeatherFreeClient — Xcode 10.1+

OpenWeatherMap Free API Client released as the component for both macOS and iOS apps as well.

Actions Status Version Pod Platforms Xcode 10.1 Swift 4.2 License

Integration Capabilities

Standalone Carthage compatible CocoaPods manager Swift Package Manager compatible

In Brief

This library lets a developer perform the network calls requesting weather data available for free with OpenWeather API. It contains the implementation of Current Weather Data and 5 Day / 3 Hour Forecast of the API.

Individual API key is required.

Requirements

First-party software

Third-party software

Installation

Using "Exact" with the Version field is strongly recommended.

Standalone

Make a copy of the file OpenWeatherStar.swift then put it into a place required of a host project.

Carthage

Cartfile should contain:

github "perseusrealdeal/OpenWeatherFreeClient" == 0.1.1

Some Carthage usage tips placed here.

CocoaPods

Podfile should contain:

target "ProjectTarget" do
  use_frameworks!
  pod 'OpenWeatherFreeClient', '0.1.1'
end

Swift Package Manager

  • As a package dependency so Package.swift should contain the following statements:
dependencies: [
        .package(url: "https://github.com/perseusrealdeal/OpenWeatherFreeClient.git",
            .exact("0.1.1"))
    ],
  • As an Xcode project dependency:

Project in the Navigator > Package Dependencies > Add Package Dependency

Using "Exact" with the Version field is strongly recommended.

Usage

Call Current Weather

let apikey = "The API key"

let client = OpenWeatherFreeClient()
let callDetails = OpenWeatherDetails(appid: apikey)

client.onDataGiven = { result in

  switch result {
    case .success(let weatherData):
      print("""
        DATA: BEGIN
        \(String(decoding: weatherData, as: UTF8.self))
        DATA: END
      """)
    case .failure(let error):
      switch error {
       case .failedRequest(let message):
         print(message)
       default:
         break
      }
    }
}

try? client.call(with: callDetails)

Call 5 Day / 3 Hour Forecast

let apikey = "The API key"

let client = OpenWeatherFreeClient()
let callDetails = OpenWeatherDetails(appid: apikey, format: .forecast)

client.onDataGiven = { result in

  switch result {
    case .success(let weatherData):
      print("""
        DATA: BEGIN
        \(String(decoding: weatherData, as: UTF8.self))
        DATA: END
      """)
    case .failure(let error):
      switch error {
       case .failedRequest(let message):
         print(message)
       default:
         break
      }
    }
}

try? client.call(with: callDetails)

License MIT

All files from this repository is under license based on MIT.

Copyright © 7531 Mikhail Zhigulin of Novosibirsk.

  • The year starts from the creation of the world according to a Slavic calendar
  • September, the 1st of Slavic year

LICENSE for details.

Author

OpenWeatherFreeClient was written at Novosibirsk by Mikhail Zhigulin i.e. me, [email protected].