tenkit 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/tenkit/client.rb +77 -0
- data/lib/tenkit/config.rb +7 -0
- data/lib/tenkit/current_weather.rb +45 -0
- data/lib/tenkit/daily_forecast.rb +14 -0
- data/lib/tenkit/day_weather_conditions.rb +57 -0
- data/lib/tenkit/hourly_forecast.rb +11 -0
- data/lib/tenkit/metadata.rb +25 -0
- data/lib/tenkit/next_hour_forecast.rb +7 -0
- data/lib/tenkit/response.rb +9 -0
- data/lib/tenkit/trend_comparison.rb +3 -0
- data/lib/tenkit/version.rb +5 -0
- data/lib/tenkit/weather.rb +31 -0
- data/lib/tenkit/weather_alert_collection.rb +14 -0
- data/lib/tenkit/weather_alert_summary.rb +39 -0
- data/lib/tenkit/weather_response.rb +12 -0
- data/lib/tenkit.rb +4 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92bb3db8677914662a80e8858cb8a895d9d0252e0619276013aac1a59eebdc7a
|
4
|
+
data.tar.gz: 3a11146700bada57d914a56c2c2a6453c7c03595ab11b39b14e92cc0e01ae858
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ed8e0d9267dc3a9a83eeb4045030f281e0ea0b721714bd4375cc717c73d5d93ffe4493157882f27dde02d1403b449dd58f2f3ea7fe27c0525cb0b0d52233622
|
7
|
+
data.tar.gz: dd8b0958afc4000ca20eeaa9d855186ec4754ba3f95922f6aa9d6af4bce4a1578fc16b3b1f122b2f1faca47eda7749f370f0fff1e5fb5dbf8eb96ace16d43e06
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'jwt'
|
4
|
+
require 'openssl'
|
5
|
+
require 'httparty'
|
6
|
+
require_relative './weather_response'
|
7
|
+
|
8
|
+
module Tenkit
|
9
|
+
class Client
|
10
|
+
include HTTParty
|
11
|
+
base_uri 'https://weatherkit.apple.com/api/v1'
|
12
|
+
|
13
|
+
DATA_SETS = {
|
14
|
+
current_weather: 'currentWeather',
|
15
|
+
forecast_daily: 'forecastDaily',
|
16
|
+
forecast_hourly: 'forecastHourly',
|
17
|
+
trend_comparison: 'trendComparison',
|
18
|
+
weather_alerts: 'weatherAlerts',
|
19
|
+
forecast_next_hour: 'forecastNextHour'
|
20
|
+
}.freeze
|
21
|
+
|
22
|
+
def availability(lat, lon, **options)
|
23
|
+
options[:country] ||= 'US'
|
24
|
+
get("/availability/#{lat}/#{lon}?country=#{options[:country]}")
|
25
|
+
end
|
26
|
+
|
27
|
+
def weather(lat, lon, **options)
|
28
|
+
options[:data_sets] ||= [:current_weather]
|
29
|
+
options[:language] ||= 'en'
|
30
|
+
|
31
|
+
path_root = "/weather/#{options[:language]}/#{lat}/#{lon}?dataSets="
|
32
|
+
path = path_root + options[:data_sets].map { |ds| DATA_SETS[ds] }.compact.join(',')
|
33
|
+
|
34
|
+
response = get(path)
|
35
|
+
WeatherResponse.new(response)
|
36
|
+
end
|
37
|
+
|
38
|
+
def weather_alert(id, **options)
|
39
|
+
options[:language] ||= 'en'
|
40
|
+
puts 'TODO: implement weather alert endpoint'
|
41
|
+
puts language
|
42
|
+
puts id
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def get(url)
|
48
|
+
headers = { Authorization: "Bearer #{token}" }
|
49
|
+
self.class.get(url, { headers: headers })
|
50
|
+
end
|
51
|
+
|
52
|
+
def header
|
53
|
+
{
|
54
|
+
alg: 'ES256',
|
55
|
+
kid: Tenkit.config.key_id,
|
56
|
+
id: "#{Tenkit.config.team_id}.#{Tenkit.config.service_id}"
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
def payload
|
61
|
+
{
|
62
|
+
iss: Tenkit.config.team_id,
|
63
|
+
iat: Time.new.to_i,
|
64
|
+
exp: Time.new.to_i + 600,
|
65
|
+
sub: Tenkit.config.service_id
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
def key
|
70
|
+
OpenSSL::PKey.read Tenkit.config.key
|
71
|
+
end
|
72
|
+
|
73
|
+
def token
|
74
|
+
JWT.encode payload, key, 'ES256', header
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require_relative './metadata'
|
2
|
+
|
3
|
+
module Tenkit
|
4
|
+
class CurrentWeather
|
5
|
+
attr_reader :as_of,
|
6
|
+
:cloud_cover,
|
7
|
+
:condition_code,
|
8
|
+
:daylight,
|
9
|
+
:humidity,
|
10
|
+
:metadata,
|
11
|
+
:precipitation_intensity,
|
12
|
+
:pressure,
|
13
|
+
:pressure_trend,
|
14
|
+
:temperature,
|
15
|
+
:temperature_apparent,
|
16
|
+
:temperature_dew_point,
|
17
|
+
:uv_index,
|
18
|
+
:visibility,
|
19
|
+
:wind_direction,
|
20
|
+
:wind_gust,
|
21
|
+
:wind_speed
|
22
|
+
|
23
|
+
def initialize(current_weather)
|
24
|
+
return if current_weather.nil?
|
25
|
+
|
26
|
+
@as_of = current_weather['asOf']
|
27
|
+
@cloud_cover = current_weather['cloudCover']
|
28
|
+
@condition_code = current_weather['conditionCode']
|
29
|
+
@daylight = current_weather['daylight']
|
30
|
+
@humidity = current_weather['humidity']
|
31
|
+
@metadata = Metadata.new(current_weather['metadata'])
|
32
|
+
@precipitation_intensity = current_weather['precipitationIntensity']
|
33
|
+
@pressure = current_weather['pressure']
|
34
|
+
@pressure_trend = current_weather['pressureTrend']
|
35
|
+
@temperature = current_weather['temperature']
|
36
|
+
@temperature_apparent = current_weather['temperatureApparent']
|
37
|
+
@temperature_dew_point = current_weather['temperatureDewPoint']
|
38
|
+
@uv_index = current_weather['uvIndex']
|
39
|
+
@visibility = current_weather['visibility']
|
40
|
+
@wind_direction = current_weather['windDirection']
|
41
|
+
@wind_gust = current_weather['windGust']
|
42
|
+
@wind_speed = current_weather['windSpeed']
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative './day_weather_conditions'
|
2
|
+
|
3
|
+
module Tenkit
|
4
|
+
class DailyForecast
|
5
|
+
attr_reader :days, :learn_more_url
|
6
|
+
|
7
|
+
def initialize(daily_forecast)
|
8
|
+
return if daily_forecast.nil?
|
9
|
+
|
10
|
+
@days = daily_forecast['days'].map { |day| DayWeatherConditions.new(day) }
|
11
|
+
@learn_more_url = daily_forecast['learnMoreURL']
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Tenkit
|
2
|
+
class DayWeatherConditions
|
3
|
+
attr_reader :condition_code,
|
4
|
+
:daytime_forecast,
|
5
|
+
:forecast_end,
|
6
|
+
:forecast_start,
|
7
|
+
:max_uv_index,
|
8
|
+
:moon_phase,
|
9
|
+
:moonrise,
|
10
|
+
:moonset,
|
11
|
+
:overnight_forecast,
|
12
|
+
:precipitation_amount,
|
13
|
+
:precipitation_chance,
|
14
|
+
:precipitation_type,
|
15
|
+
:snowfall_amount,
|
16
|
+
:solar_midnight,
|
17
|
+
:solar_noon,
|
18
|
+
:sunrise,
|
19
|
+
:sunrise_astronomical,
|
20
|
+
:sunrise_civil,
|
21
|
+
:sunrise_nautical,
|
22
|
+
:sunset,
|
23
|
+
:sunset_astronomical,
|
24
|
+
:sunset_civil,
|
25
|
+
:sunset_nautical,
|
26
|
+
:temperature_max,
|
27
|
+
:temperature_min
|
28
|
+
|
29
|
+
def initialize(day_weather_conditions)
|
30
|
+
@condition_code = day_weather_conditions['condition_code']
|
31
|
+
@daytime_forecast = day_weather_conditions['daytime_forecast']
|
32
|
+
@forecast_end = day_weather_conditions['forecast_end']
|
33
|
+
@forecast_start = day_weather_conditions['forecast_start']
|
34
|
+
@max_uv_index = day_weather_conditions['max_uv_index']
|
35
|
+
@moon_phase = day_weather_conditions['moon_phase']
|
36
|
+
@moonrise = day_weather_conditions['moonrise']
|
37
|
+
@moonset = day_weather_conditions['moonset']
|
38
|
+
@overnight_forecast = day_weather_conditions['overnight_forecast']
|
39
|
+
@precipitation_amount = day_weather_conditions['precipitation_amount']
|
40
|
+
@precipitation_chance = day_weather_conditions['precipitation_chance']
|
41
|
+
@precipitation_type = day_weather_conditions['precipitation_type']
|
42
|
+
@snowfall_amount = day_weather_conditions['snowfall_amount']
|
43
|
+
@solar_midnight = day_weather_conditions['solar_midnight']
|
44
|
+
@solar_noon = day_weather_conditions['solar_noon']
|
45
|
+
@sunrise = day_weather_conditions['sunrise']
|
46
|
+
@sunrise_astronomical = day_weather_conditions['sunrise_astronomical']
|
47
|
+
@sunrise_civil = day_weather_conditions['sunrise_civil']
|
48
|
+
@sunrise_nautical = day_weather_conditions['sunrise_nautical']
|
49
|
+
@sunset = day_weather_conditions['sunset']
|
50
|
+
@sunset_astronomical = day_weather_conditions['sunset_astronomical']
|
51
|
+
@sunset_civil = day_weather_conditions['sunset_civil']
|
52
|
+
@sunset_nautical = day_weather_conditions['sunset_nautical']
|
53
|
+
@temperature_max = day_weather_conditions['temperature_max']
|
54
|
+
@temperature_min = day_weather_conditions['temperature_min']
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Tenkit
|
2
|
+
class Metadata
|
3
|
+
attr_reader :attribution_url,
|
4
|
+
:expire_time,
|
5
|
+
:latitude,
|
6
|
+
:longitude,
|
7
|
+
:read_time,
|
8
|
+
:reported_time,
|
9
|
+
:units,
|
10
|
+
:version
|
11
|
+
|
12
|
+
def initialize(metadata)
|
13
|
+
return if metadata.nil?
|
14
|
+
|
15
|
+
@attribution_url = metadata['attributionURL']
|
16
|
+
@expire_time = metadata['expireTime']
|
17
|
+
@latitude = metadata['latitude']
|
18
|
+
@longitude = metadata['longitude']
|
19
|
+
@read_time = metadata['readTime']
|
20
|
+
@reported_time = metadata['reportedTime']
|
21
|
+
@units = metadata['units']
|
22
|
+
@version = metadata['version']
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative './current_weather'
|
2
|
+
require_relative './daily_forecast'
|
3
|
+
require_relative './hourly_forecast'
|
4
|
+
require_relative './next_hour_forecast'
|
5
|
+
require_relative './weather_alert_collection'
|
6
|
+
|
7
|
+
module Tenkit
|
8
|
+
class Weather
|
9
|
+
attr_reader :current_weather,
|
10
|
+
:forecast_daily,
|
11
|
+
:forecast_hourly,
|
12
|
+
:forecast_next_hour,
|
13
|
+
:weather_alerts
|
14
|
+
|
15
|
+
def initialize(response)
|
16
|
+
parsed_response = JSON.parse(response.body)
|
17
|
+
|
18
|
+
current_weather = parsed_response['currentWeather']
|
19
|
+
forecast_daily = parsed_response['forecastDaily']
|
20
|
+
forecast_hourly = parsed_response['forecastHourly']
|
21
|
+
forecast_next_hour = parsed_response['forecastNextHour']
|
22
|
+
weather_alerts = parsed_response['weatherAlerts']
|
23
|
+
|
24
|
+
@current_weather = CurrentWeather.new(current_weather)
|
25
|
+
@forecast_daily = DailyForecast.new(forecast_daily)
|
26
|
+
@forecast_hourly = HourlyForecast.new(forecast_hourly)
|
27
|
+
@forecast_next_hour = NextHourForecast.new(forecast_next_hour)
|
28
|
+
@weather_alerts = WeatherAlertCollection.new(weather_alerts)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative './weather_alert_summary'
|
2
|
+
|
3
|
+
module Tenkit
|
4
|
+
class WeatherAlertCollection
|
5
|
+
attr_reader :alerts, :details_url
|
6
|
+
|
7
|
+
def initialize(weather_alerts)
|
8
|
+
return if weather_alerts.nil?
|
9
|
+
|
10
|
+
@alerts = weather_alerts['alerts'].map { |alert| WeatherAlertSummary.new(alert) }
|
11
|
+
@details_url = weather_alerts['detailsUrl']
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Tenkit
|
2
|
+
class WeatherAlertSummary
|
3
|
+
attr_reader :area_id,
|
4
|
+
:area_name,
|
5
|
+
:certainty,
|
6
|
+
:country_code,
|
7
|
+
:description,
|
8
|
+
:details_url,
|
9
|
+
:effective_time,
|
10
|
+
:event_end_time,
|
11
|
+
:event_onset_time,
|
12
|
+
:expire_time,
|
13
|
+
:id,
|
14
|
+
:issued_time,
|
15
|
+
:responses,
|
16
|
+
:severity,
|
17
|
+
:source,
|
18
|
+
:urgency
|
19
|
+
|
20
|
+
def initialize(weather_alert)
|
21
|
+
@area_id = weather_alert['areaId']
|
22
|
+
@area_name = weather_alert['areaName']
|
23
|
+
@certainty = weather_alert['certainty']
|
24
|
+
@country_code = weather_alert['countryCode']
|
25
|
+
@description = weather_alert['description']
|
26
|
+
@details_url = weather_alert['detailsUrl']
|
27
|
+
@effective_time = weather_alert['effectiveTime']
|
28
|
+
@event_end_time = weather_alert['eventEndTime']
|
29
|
+
@event_onset_time = weather_alert['eventOnsetTime']
|
30
|
+
@expire_time = weather_alert['expireTime']
|
31
|
+
@id = weather_alert['id']
|
32
|
+
@issued_time = weather_alert['issued_time']
|
33
|
+
@responses = weather_alert['responses']
|
34
|
+
@severity = weather_alert['severity']
|
35
|
+
@source = weather_alert['source']
|
36
|
+
@urgency = weather_alert['urgency']
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/tenkit.rb
CHANGED
@@ -2,9 +2,12 @@
|
|
2
2
|
|
3
3
|
require_relative 'tenkit/client'
|
4
4
|
require_relative 'tenkit/config'
|
5
|
+
require_relative 'tenkit/version'
|
6
|
+
require_relative 'tenkit/weather'
|
5
7
|
|
6
8
|
module Tenkit
|
7
|
-
class Error < StandardError
|
9
|
+
class Error < StandardError
|
10
|
+
end
|
8
11
|
|
9
12
|
class << self
|
10
13
|
attr_accessor :config
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tenkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Pierce
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -101,6 +101,21 @@ extensions: []
|
|
101
101
|
extra_rdoc_files: []
|
102
102
|
files:
|
103
103
|
- lib/tenkit.rb
|
104
|
+
- lib/tenkit/client.rb
|
105
|
+
- lib/tenkit/config.rb
|
106
|
+
- lib/tenkit/current_weather.rb
|
107
|
+
- lib/tenkit/daily_forecast.rb
|
108
|
+
- lib/tenkit/day_weather_conditions.rb
|
109
|
+
- lib/tenkit/hourly_forecast.rb
|
110
|
+
- lib/tenkit/metadata.rb
|
111
|
+
- lib/tenkit/next_hour_forecast.rb
|
112
|
+
- lib/tenkit/response.rb
|
113
|
+
- lib/tenkit/trend_comparison.rb
|
114
|
+
- lib/tenkit/version.rb
|
115
|
+
- lib/tenkit/weather.rb
|
116
|
+
- lib/tenkit/weather_alert_collection.rb
|
117
|
+
- lib/tenkit/weather_alert_summary.rb
|
118
|
+
- lib/tenkit/weather_response.rb
|
104
119
|
homepage: https://github.com/superbasicxyz/tenkit
|
105
120
|
licenses:
|
106
121
|
- MIT
|