open-meteo 0.3.1 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/open_meteo/client/url_builder.rb +6 -6
- data/lib/open_meteo/client.rb +10 -10
- data/lib/open_meteo/entities/location.rb +1 -1
- data/lib/open_meteo/faraday_connection.rb +1 -0
- data/lib/open_meteo/forecast/variables.rb +7 -4
- data/lib/open_meteo/forecast.rb +7 -3
- data/lib/open_meteo/response_wrapper.rb +2 -0
- data/lib/open_meteo/version.rb +1 -1
- data/lib/open_meteo.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df57745eac4454ef8165b7e202ac8b794ffa21e4e91f3a2888245fae72c2247d
|
4
|
+
data.tar.gz: a94961154f9f325b5194956236fe2153071d91711a194eabcf9b8968766183ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3bc0b7c5530498b4a099503665e29c6f582aa4453a3bd564b612fa346ae56a18173f19e7a53677ba811015604a77eaaf408dbb52fde980afc6b887501843e22
|
7
|
+
data.tar.gz: f35900d202b03f878497d260ec54f6293f595a33848182b9ad106b587f60421124c9aa9b079605d4b62e4071743c883fa7dea3861354d98fe8502cb011700fb3
|
@@ -5,17 +5,17 @@ module OpenMeteo
|
|
5
5
|
class UrlBuilder
|
6
6
|
API_PATHS = { forecast: "v1/forecast", forecast_dwd_icon: "v1/dwd-icon" }.freeze
|
7
7
|
|
8
|
-
attr_reader :
|
8
|
+
attr_reader :config
|
9
9
|
|
10
|
-
def initialize(
|
11
|
-
@
|
10
|
+
def initialize(config: OpenMeteo::Client::Config.new)
|
11
|
+
@config = config
|
12
12
|
end
|
13
13
|
|
14
|
-
def build_url(endpoint,
|
14
|
+
def build_url(endpoint, path_params = {})
|
15
15
|
relative_path = API_PATHS.fetch(endpoint.to_sym)
|
16
|
-
full_path = [
|
16
|
+
full_path = [config.url, relative_path].join("/")
|
17
17
|
|
18
|
-
URI::DEFAULT_PARSER.escape(format(full_path,
|
18
|
+
URI::DEFAULT_PARSER.escape(format(full_path, path_params))
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
data/lib/open_meteo/client.rb
CHANGED
@@ -11,23 +11,23 @@ module OpenMeteo
|
|
11
11
|
class Timeout < StandardError
|
12
12
|
end
|
13
13
|
|
14
|
-
attr_reader :
|
14
|
+
attr_reader :config, :agent
|
15
15
|
|
16
16
|
def initialize(
|
17
|
-
|
18
|
-
url_builder:
|
19
|
-
agent: FaradayConnection.new
|
17
|
+
config: OpenMeteo::Client::Config.new,
|
18
|
+
url_builder: UrlBuilder.new(config:),
|
19
|
+
agent: FaradayConnection.new(config:)
|
20
20
|
)
|
21
|
-
@
|
22
|
-
@url_builder = url_builder
|
21
|
+
@config = config
|
22
|
+
@url_builder = url_builder
|
23
23
|
@agent = agent
|
24
24
|
end
|
25
25
|
|
26
|
-
def get(endpoint_name,
|
27
|
-
endpoint = url_builder.build_url(endpoint_name,
|
26
|
+
def get(endpoint_name, path_params: {}, query_params: {})
|
27
|
+
endpoint = url_builder.build_url(endpoint_name, path_params)
|
28
28
|
|
29
|
-
agent.get do |request|
|
30
|
-
request.params =
|
29
|
+
agent.connect.get do |request|
|
30
|
+
request.params = query_params.merge({ apikey: config.api_key }.compact)
|
31
31
|
request.url(endpoint)
|
32
32
|
end
|
33
33
|
rescue Faraday::ConnectionFailed => e
|
@@ -25,15 +25,18 @@ module OpenMeteo
|
|
25
25
|
:models,
|
26
26
|
OpenMeteo::Types::Strict::Array.of(OpenMeteo::Types::Strict::Symbol).default([].freeze),
|
27
27
|
)
|
28
|
+
attribute(:timezone, OpenMeteo::Types::Strict::String.optional.default(nil))
|
28
29
|
|
29
|
-
def
|
30
|
-
|
30
|
+
def to_query_params
|
31
|
+
query_params = {}
|
31
32
|
|
32
33
|
%i[current minutely_15 hourly daily models].each do |key|
|
33
|
-
|
34
|
+
query_params[key] = send(key).join(",") if send(key) != []
|
34
35
|
end
|
35
36
|
|
36
|
-
|
37
|
+
%i[timezone].each { |key| query_params[key] = send(key) if send(key) }
|
38
|
+
|
39
|
+
query_params
|
37
40
|
end
|
38
41
|
end
|
39
42
|
end
|
data/lib/open_meteo/forecast.rb
CHANGED
@@ -12,7 +12,11 @@ module OpenMeteo
|
|
12
12
|
class WrongLocationType < StandardError
|
13
13
|
end
|
14
14
|
|
15
|
-
def initialize(
|
15
|
+
def initialize(
|
16
|
+
config: OpenMeteo::Client::Config.new,
|
17
|
+
client: OpenMeteo::Client.new(config:),
|
18
|
+
response_wrapper: OpenMeteo::ResponseWrapper.new(config:)
|
19
|
+
)
|
16
20
|
@client = client
|
17
21
|
@response_wrapper = response_wrapper
|
18
22
|
end
|
@@ -53,8 +57,8 @@ module OpenMeteo
|
|
53
57
|
end
|
54
58
|
|
55
59
|
def get_forecast(endpoint, location, variables)
|
56
|
-
|
57
|
-
response = client.get(endpoint,
|
60
|
+
query_params = { **location.to_query_params, **variables.to_query_params }
|
61
|
+
response = client.get(endpoint, query_params:)
|
58
62
|
|
59
63
|
@response_wrapper.wrap(response, entity: OpenMeteo::Entities::Forecast)
|
60
64
|
end
|
data/lib/open_meteo/version.rb
CHANGED
data/lib/open_meteo.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: open-meteo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Morgenstern
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-struct
|