novaposhta_api 0.1.0 → 0.1.1
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/config/locales/novaposhta.en.yml +674 -0
- data/config/locales/novaposhta.ru.yml +674 -0
- data/config/locales/novaposhta.uk.yml +674 -0
- data/lib/novaposhta_api/client.rb +12 -11
- data/lib/novaposhta_api/http_client.rb +2 -4
- data/lib/novaposhta_api/middlewares/error_handling.rb +1 -1
- data/lib/novaposhta_api/version.rb +1 -1
- metadata +5 -2
@@ -2,11 +2,12 @@
|
|
2
2
|
|
3
3
|
module NovaposhtaApi
|
4
4
|
class Client
|
5
|
-
|
5
|
+
API_URL = 'https://api.novaposhta.ua/v2.0/json/'
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
attr_reader :api_key
|
8
|
+
|
9
|
+
def initialize(api_key: nil)
|
10
|
+
@api_key = api_key
|
10
11
|
end
|
11
12
|
|
12
13
|
def self.resources
|
@@ -20,7 +21,7 @@ module NovaposhtaApi
|
|
20
21
|
end
|
21
22
|
|
22
23
|
def method_missing(name, *args, &block)
|
23
|
-
if
|
24
|
+
if with_resource?(name)
|
24
25
|
resources[name] ||= self.class.resources[name].new(connection: connection)
|
25
26
|
resources[name]
|
26
27
|
else
|
@@ -29,7 +30,11 @@ module NovaposhtaApi
|
|
29
30
|
end
|
30
31
|
|
31
32
|
def respond_to_missing?(method_name, include_private = false)
|
32
|
-
|
33
|
+
with_resource?(method_name) || super
|
34
|
+
end
|
35
|
+
|
36
|
+
def with_resource?(resource_name)
|
37
|
+
self.class.resources.keys.include?(resource_name)
|
33
38
|
end
|
34
39
|
|
35
40
|
def resources
|
@@ -38,13 +43,9 @@ module NovaposhtaApi
|
|
38
43
|
|
39
44
|
def connection
|
40
45
|
@connection ||= NovaposhtaApi::HttpClient.new(
|
41
|
-
uri:
|
46
|
+
uri: API_URL,
|
42
47
|
api_key: api_key
|
43
48
|
)
|
44
49
|
end
|
45
|
-
|
46
|
-
def delivery_member_api_key
|
47
|
-
@delivery_member_api_key ||= Delivery::Member.select(:api_key).primary&.api_key
|
48
|
-
end
|
49
50
|
end
|
50
51
|
end
|
@@ -22,8 +22,7 @@ module NovaposhtaApi
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def request(http_method, path, params = {})
|
25
|
-
options = build_options(path).merge
|
26
|
-
|
25
|
+
options = build_options(path).merge(methodProperties: transform_keys(params))
|
27
26
|
response = connection.public_send(http_method, '', options.to_json)
|
28
27
|
response.body
|
29
28
|
end
|
@@ -55,9 +54,8 @@ module NovaposhtaApi
|
|
55
54
|
def connection
|
56
55
|
@connection ||= Faraday.new(connection_options) do |client|
|
57
56
|
client.adapter Faraday.default_adapter
|
58
|
-
client.
|
57
|
+
client.response :error_handling
|
59
58
|
client.response :json
|
60
|
-
client.response :logger if Rails.env.development?
|
61
59
|
end
|
62
60
|
end
|
63
61
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: novaposhta_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- venet
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-06-
|
11
|
+
date: 2020-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -75,6 +75,9 @@ files:
|
|
75
75
|
- Rakefile
|
76
76
|
- bin/console
|
77
77
|
- bin/setup
|
78
|
+
- config/locales/novaposhta.en.yml
|
79
|
+
- config/locales/novaposhta.ru.yml
|
80
|
+
- config/locales/novaposhta.uk.yml
|
78
81
|
- lib/novaposhta_api.rb
|
79
82
|
- lib/novaposhta_api/client.rb
|
80
83
|
- lib/novaposhta_api/collection.rb
|