https://github.com/perseusrealdeal/openweatheragent
OpenWeatherMap 2.5 API Client
https://github.com/perseusrealdeal/openweatheragent
Last synced: 5 months ago
JSON representation
OpenWeatherMap 2.5 API Client
- Host: GitHub
- URL: https://github.com/perseusrealdeal/openweatheragent
- Owner: PerseusRealDeal
- License: other
- Created: 2023-02-23T14:30:41.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-07-02T09:56:01.000Z (about 1 year ago)
- Last Synced: 2025-08-10T03:14:00.278Z (11 months ago)
- Language: Swift
- Homepage:
- Size: 88.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# OpenWeatherAgent — Xcode 14.2+
> [`Weather-MenuBar-App for macOS`](https://github.com/perseusrealdeal/TheDarkMoon)
> `OpenWeatherAgent` is an OpenWeatherMap API Client for``.
> `Individual API key` is required.
> - To request current weather.
> - To request `5 Day / 3 Hour` forecast.
> `OpenWeatherAgent` is a single author and personale solution developed in `person-to-person` relationship paradigm.
[](https://github.com/perseusrealdeal/OpenWeatherAgent/actions/workflows/main.yml)
[](https://github.com/perseusrealdeal/OpenWeatherAgent/actions/workflows/swiftlint.yml)
[](/CHANGELOG.md)
[](https://en.wikipedia.org/wiki/List_of_Apple_products)
[](https://en.wikipedia.org/wiki/Xcode)
[](https://www.swift.org)
[](/LICENSE)
## Integration Capabilities
[](/OpenWeatherStar.swift)
[](/Package.swift)
> Use Stars to adopt [`OpenWeatherAgent`](/OpenWeatherStar.swift) for the specifics you need.
## Dependencies
[](https://github.com/perseusrealdeal/ConsolePerseusLogger.git)
# Approbation Matrix
> [`CHANGELOG`](/CHANGELOG.md) for details.
# In brief > Idea to use, the Why
> There're so many things happen unexpectedly... and weather is the most one.
# Build system requirements
- [macOS Monterey 12.7.6+](https://apps.apple.com/by/app/macos-monterey/id1576738294) / [Xcode 14.2+](https://developer.apple.com/services-account/download?path=/Developer_Tools/Xcode_14.2/Xcode_14.2.xip)
> But as the single source code file [OpenWeatherStar.swift](/OpenWeatherStar.swift) PDM can be used even in Xcode 10.1.
# First-party software
| Type | Name | License |
| ---- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
| Star | [ConsolePerseusLogger](https://github.com/perseusrealdeal/ConsolePerseusLogger) / [1.5.0](https://github.com/perseusrealdeal/ConsolePerseusLogger/releases/tag/1.5.0) | MIT |
# Third-party software
| Type | Name | License |
| ------ | --------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------- |
| Style | [SwiftLint](https://github.com/realm/SwiftLint) / [v0.57.0 for Monterey+](https://github.com/realm/SwiftLint/releases/tag/0.57.0) | MIT |
| Script | [SwiftLint Shell Script](/SucceedsPostAction.sh) to run SwiftLint | MIT |
| Action | [mxcl/xcodebuild@v3](https://github.com/mxcl/xcodebuild) | [Unlicense](https://unlicense.org) |
| Action | [cirruslabs/swiftlint-action@v1](https://github.com/cirruslabs/swiftlint-action/) | MIT |
# Installation
> Standalone: the single source code file [OpenWeatherStar.swift](/OpenWeatherStar.swift)
> Swift Package Manager: `https://github.com/perseusrealdeal/OpenWeatherAgent`
# Usage
## Request Current Weather
### `Case structured concurrency:` closure completion callbacks
```swift
let apikey = "The API key"
let client = OpenWeatherClient()
let respect = OpenWeatherRequestData(appid: apikey)
client.onDataGiven = { result in
switch result {
case .success(let weatherData):
// Source Code: prettyPrinted
// https://gist.github.com/perseusrealdeal/945c9050cb9f7a19e00853f064acacca
log.message(weatherData.prettyPrinted! as String)
case .failure(let error):
var errStr = ""
switch error {
case .failedRequest(let errText):
errStr = errText
case .failedResponse(let errText):
errStr = errText
case .invalidUrl:
errStr = "invalidUrl"
case .statusCode404:
errStr = "statusCode404"
}
log.message("[OpenWeatherAgent]\(#function): \(errStr)", .error)
}
}
try? client.call(with: respect)
```
### `Case async-await concurrency:` only from iOS 13, macOS 10.15
``` swift
let apikey = "The API key"
let respect = OpenWeatherRequestData(appid: apikey)
do {
let data = try await OpenWeatherAgent.shared.fetch(with: respect)
// Source Code: prettyPrinted
// https://gist.github.com/perseusrealdeal/945c9050cb9f7a19e00853f064acacca
log.message(data.prettyPrinted! as String)
} catch let error as OpenWeatherAPIClientError {
log.message("OpenWeatherAPIClientError: \(error)", .error)
} catch {
log.message(error.localizedDescription, .error)
}
```
## Request Forecast
### `Case structured concurrency:` closure completion callbacks
```swift
let apikey = "The API key"
let client = OpenWeatherClient()
let respect = OpenWeatherRequestData(appid: apikey, request: .forecast)
client.onDataGiven = { result in
switch result {
case .success(let weatherData):
// Source Code: prettyPrinted
// https://gist.github.com/perseusrealdeal/945c9050cb9f7a19e00853f064acacca
log.message(weatherData.prettyPrinted! as String)
case .failure(let error):
var errStr = ""
switch error {
case .failedRequest(let errText):
errStr = errText
case .failedResponse(let errText):
errStr = errText
case .invalidUrl:
errStr = "invalidUrl"
case .statusCode404:
errStr = "statusCode404"
}
log.message("[OpenWeatherAgent]\(#function): \(errStr)", .error)
}
}
try? client.call(with: respect)
```
### `Case async-await concurrency:` only from iOS 13, macOS 10.15
``` swift
let apikey = "The API key"
let respect = OpenWeatherRequestData(appid: apikey, request: .forecast)
do {
let data = try await OpenWeatherAgent.shared.fetch(with: respect)
// Source Code: prettyPrinted
// https://gist.github.com/perseusrealdeal/945c9050cb9f7a19e00853f064acacca
log.message(data.prettyPrinted! as String)
} catch let error as OpenWeatherAPIClientError {
log.message("OpenWeatherAPIClientError: \(error)", .error)
} catch {
log.message(error.localizedDescription, .error)
}
```
# Points taken into account
- Preconfigured Swift Package manifest [Package.swift](/Package.swift)
- Preconfigured SwiftLint config [.swiftlint.yml](/.swiftlint.yml)
- Preconfigured SwiftLint CI [swiftlint.yml](/.github/workflows/swiftlint.yml)
- Preconfigured GitHub config [.gitignore](/.gitignore)
- Preconfigured GitHub CI [main.yml](/.github/workflows/main.yml)
# License MIT
Copyright © 7530 - 7533 Mikhail A. Zhigulin of Novosibirsk
Copyright © 7533 PerseusRealDeal
- The year starts from the creation of the world according to a Slavic calendar.
- September, the 1st of Slavic year. It means that "Sep 01, 2024" is the beginning of 7533.
## Other Required License Notices
© 2025 The SwiftLint Contributors **for** SwiftLint
© GitHub **for** GitHub Action cirruslabs/swiftlint-action@v1
© 2021 Alexandre Colucci, geteimy.com **for** Shell Script SucceedsPostAction.sh
[LICENSE](/LICENSE) for details.
## Credits
Balance and Control
kept by
Mikhail A. Zhigulin
Source Code
written by
Mikhail A. Zhigulin
Documentation
prepared by
Mikhail A. Zhigulin
Product Approbation
tested by
Mikhail A. Zhigulin
- Language support: [Reverso](https://www.reverso.net/)
- Git clients: [SmartGit](https://syntevo.com/) and [GitHub Desktop](https://github.com/apps/desktop)
# Author
> © Mikhail A. Zhigulin of Novosibirsk.