open-meteo 0.3.0 → 0.3.2
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/config.rb +3 -2
- data/lib/open_meteo/client/url_builder.rb +4 -4
- data/lib/open_meteo/client.rb +12 -13
- data/lib/open_meteo/configuration.rb +1 -0
- data/lib/open_meteo/faraday_connection.rb +27 -0
- data/lib/open_meteo/forecast.rb +5 -1
- 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 +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60140c0aa4f49166a8d9efef379ba7628fb663bd65c712018f7e2089f43677d5
|
4
|
+
data.tar.gz: bd54e00eabe5518725f32b790e8da3257fc985e0e678d0220343ac528858fbe5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17a87ed4b29b65f93ff21bfad1c2579f37faa5eb7677f7598da708438e1888d54729af4bd1946328a0b37dc14f8fef9711bab95ab3619ccc7e16b6e0c300302f
|
7
|
+
data.tar.gz: 205a30320db01bf6406e69c02633c1799d81f660962b05d13749cb9f92c630044224833cd88bd1b46bcfaf85656b5067958fe94d636d92b861b7aed9bb5e82ec
|
@@ -3,12 +3,13 @@ module OpenMeteo
|
|
3
3
|
##
|
4
4
|
# The configuration for the OpenMeteo::Client.
|
5
5
|
class Config
|
6
|
-
attr_reader :api_key, :host, :logger
|
6
|
+
attr_reader :api_key, :host, :logger, :timeouts
|
7
7
|
|
8
|
-
def initialize(api_key: nil, host: nil, logger: nil)
|
8
|
+
def initialize(api_key: nil, host: nil, logger: nil, timeouts: nil)
|
9
9
|
@api_key = api_key || OpenMeteo.configuration.api_key
|
10
10
|
@host = host || OpenMeteo.configuration.host
|
11
11
|
@logger = logger || OpenMeteo.configuration.logger
|
12
|
+
@timeouts = timeouts || OpenMeteo.configuration.timeouts
|
12
13
|
end
|
13
14
|
|
14
15
|
def url
|
@@ -5,15 +5,15 @@ 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
14
|
def build_url(endpoint, *args)
|
15
15
|
relative_path = API_PATHS.fetch(endpoint.to_sym)
|
16
|
-
full_path = [
|
16
|
+
full_path = [config.url, relative_path].join("/")
|
17
17
|
|
18
18
|
URI::DEFAULT_PARSER.escape(format(full_path, args))
|
19
19
|
end
|
data/lib/open_meteo/client.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
require "faraday/retry"
|
3
|
-
|
1
|
+
require_relative "faraday_connection"
|
4
2
|
require_relative "client/config"
|
5
3
|
require_relative "client/url_builder"
|
6
4
|
|
@@ -13,22 +11,23 @@ module OpenMeteo
|
|
13
11
|
class Timeout < StandardError
|
14
12
|
end
|
15
13
|
|
16
|
-
|
17
|
-
RETRY_OPTIONS = { max: 3, interval: 0.05, interval_randomness: 0.5, backoff_factor: 3 }.freeze
|
18
|
-
|
19
|
-
attr_reader :api_config, :agent
|
14
|
+
attr_reader :config, :agent
|
20
15
|
|
21
|
-
def initialize(
|
22
|
-
|
23
|
-
|
24
|
-
|
16
|
+
def initialize(
|
17
|
+
config: OpenMeteo::Client::Config.new,
|
18
|
+
url_builder: UrlBuilder.new(config:),
|
19
|
+
agent: FaradayConnection.new(config:)
|
20
|
+
)
|
21
|
+
@config = config
|
22
|
+
@url_builder = url_builder
|
23
|
+
@agent = agent
|
25
24
|
end
|
26
25
|
|
27
26
|
def get(endpoint_name, *endpoint_args, **get_params)
|
28
27
|
endpoint = url_builder.build_url(endpoint_name, *endpoint_args)
|
29
28
|
|
30
|
-
agent.get do |request|
|
31
|
-
request.params = get_params.merge({ apikey:
|
29
|
+
agent.connect.get do |request|
|
30
|
+
request.params = get_params.merge({ apikey: config.api_key }.compact)
|
32
31
|
request.url(endpoint)
|
33
32
|
end
|
34
33
|
rescue Faraday::ConnectionFailed => e
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "faraday"
|
2
|
+
require "faraday/retry"
|
3
|
+
|
4
|
+
module OpenMeteo
|
5
|
+
##
|
6
|
+
# The Faraday connection
|
7
|
+
class FaradayConnection
|
8
|
+
# See https://github.com/lostisland/faraday-retry/tree/main#usage
|
9
|
+
RETRY_OPTIONS = { max: 3, interval: 0.05, interval_randomness: 0.5, backoff_factor: 3 }.freeze
|
10
|
+
|
11
|
+
attr_reader :config
|
12
|
+
|
13
|
+
def initialize(config: OpenMeteo::Client::Config.new)
|
14
|
+
@config = config
|
15
|
+
end
|
16
|
+
|
17
|
+
def connect
|
18
|
+
Faraday.new do |conn|
|
19
|
+
conn.options[:timeout] = config.timeouts[:timeout]
|
20
|
+
conn.options[:open_timeout] = config.timeouts[:open_timeout]
|
21
|
+
|
22
|
+
conn.request :retry, RETRY_OPTIONS
|
23
|
+
conn.response :logger
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
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
|
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.2
|
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-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-struct
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- lib/open_meteo/entities/forecast/units.rb
|
114
114
|
- lib/open_meteo/entities/location.rb
|
115
115
|
- lib/open_meteo/errors.rb
|
116
|
+
- lib/open_meteo/faraday_connection.rb
|
116
117
|
- lib/open_meteo/forecast.rb
|
117
118
|
- lib/open_meteo/forecast/variables.rb
|
118
119
|
- lib/open_meteo/response_wrapper.rb
|