novaposhta_api 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,11 +2,12 @@
2
2
 
3
3
  module NovaposhtaApi
4
4
  class Client
5
- attr_reader :api_url, :api_key
5
+ API_URL = 'https://api.novaposhta.ua/v2.0/json/'
6
6
 
7
- def initialize(api_url: nil, api_key:)
8
- @api_url = api_url || ENV['NOVAPOSHTA_URL']
9
- @api_key = api_key || delivery_member_api_key || ENV['NOVAPOSHTA_KEY']
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 self.class.resources.keys.include?(name)
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
- self.class.resources.keys.include?(method_name) || super
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: api_url,
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!(methodProperties: transform_keys(params))
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.use NovaposhtaApi::Middlewares::ErrorHandling
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
 
@@ -18,7 +18,7 @@ module NovaposhtaApi
18
18
  def from_codes(codes = [])
19
19
  return nil if codes.blank?
20
20
 
21
- codes.map { |code| I18n.t(code, scope: %i[NovaposhtaApi errors]) }
21
+ codes.map { |code| I18n.t(code, scope: %i[novaposhta errors]) }
22
22
  end
23
23
  end
24
24
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NovaposhtaApi
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
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.0
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-22 00:00:00.000000000 Z
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