Skip to content
This repository has been archived by the owner on Jul 19, 2023. It is now read-only.

Commit

Permalink
Updated project to use the simplified API
Browse files Browse the repository at this point in the history
  • Loading branch information
devmaximilian committed Dec 24, 2019
1 parent 9b541ae commit 8b186b7
Show file tree
Hide file tree
Showing 25 changed files with 64 additions and 729 deletions.
22 changes: 17 additions & 5 deletions Sources/MetobsKit/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,23 @@

import Foundation

internal struct MetobsKit {
public static var endpoint: URL = URL(string: "https://opendata-download-metobs.smhi.se")!
public static var directoryPath: URL {
return endpoint.appendingPathComponent("api.json")
extension Double {
func rounded(toPrecision precision: Int) -> Double {
let multiplier: Double = pow(10, Double(precision))
return (self * multiplier).rounded() / multiplier
}
}

internal func buildURL(latitude: Double, longitude: Double) -> Promise<URL> {
// Remove decimals exceeding six positions as it will cause a 404 response
let values: (lat: Double, lon: Double) = (
lat: latitude.rounded(toPrecision: 6),
lon: longitude.rounded(toPrecision: 6)
)

guard let url = URL(string: "https://opendata-download-metfcst.smhi.se/api/category/pmp3g/version/2/geotype/point/lon/\(values.lon)/lat/\(values.lat)/data.json") else {
return Promise<URL>(value: nil, error: URLError(.badURL))
}

public static var preferredType: String = "application/json"
return Promise<URL>(value: url)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Codes.swift
// Exports.swift
//
// Copyright (c) 2019 Maximilian Wendel
//
Expand All @@ -22,8 +22,4 @@
// SOFTWARE.
//

import Foundation

public struct Codes: Codable {
public let entry: [Code]
}
@_exported import Foundation
55 changes: 0 additions & 55 deletions Sources/MetobsKit/Models/Directory.swift

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Code.swift
// Forecast.swift
//
// Copyright (c) 2019 Maximilian Wendel
//
Expand All @@ -24,7 +24,7 @@

import Foundation

public struct Code: Codable {
public let key: Int
public let value: String
public struct Forecast: Codable {
public let validTime: String
public let parameters: [Parameter]
}
32 changes: 0 additions & 32 deletions Sources/MetobsKit/Models/GeoBox.swift

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Link.swift
// Geometry.swift
//
// Copyright (c) 2019 Maximilian Wendel
//
Expand All @@ -24,9 +24,9 @@

import Foundation

/// An object representation of a link
public struct Link: Codable {
public let rel: String
public typealias GeometryCoordinate = [Double]

public struct Geometry: Codable {
public let type: String
public let href: String
public let coordinates: [GeometryCoordinate]
}
32 changes: 0 additions & 32 deletions Sources/MetobsKit/Models/Observation+Directory.swift

This file was deleted.

11 changes: 4 additions & 7 deletions Sources/MetobsKit/Models/Observation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@

import Foundation

/// An object representation of a data-set
public struct Observation: Codable {
public let value: [Value]?
public let parameter: ObservedParameter
public let station: ObservedStation
public let period: ObservedPeriod
public let position: [Position]
public let link: [Link]
public let approvedTime: String
public let referenceTime: String
public let geometry: Geometry
public let timeSeries: [Forecast]
}
32 changes: 0 additions & 32 deletions Sources/MetobsKit/Models/ObservedParameter.swift

This file was deleted.

32 changes: 0 additions & 32 deletions Sources/MetobsKit/Models/ObservedPeriod.swift

This file was deleted.

32 changes: 0 additions & 32 deletions Sources/MetobsKit/Models/ObservedStation.swift

This file was deleted.

10 changes: 5 additions & 5 deletions Sources/MetobsKit/Models/Parameter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import Foundation

public struct Parameter: Codable {
public let key: String
public let title: String
public let summary: String
public let link: [Link]
public let station: [Station]
public let name: String
public let levelType: String
public let level: Int
public let unit: String
public let values: [Double]
}
35 changes: 0 additions & 35 deletions Sources/MetobsKit/Models/Period+Directory.swift

This file was deleted.

Loading

0 comments on commit 8b186b7

Please sign in to comment.