novaposhta_api 0.1.3 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db0a59d6e83adee1e273164e0a7c3dc33828e2e0167451a4da1047dc88eaaf9e
4
- data.tar.gz: 465497a98ad80b79aa90ee2722bfce629db455a7467f9e4f13a03bedef4ed79d
3
+ metadata.gz: '092ea7dd2a237106569b0c9d36739f1892f40d628b2599ab5dd0004f5c9f83af'
4
+ data.tar.gz: 38ef279dcdc0c6df731343772662824be10f3b6605368972037d818c004e3403
5
5
  SHA512:
6
- metadata.gz: cf3b30451c7c21da4d71b7439f725c00b136c6240816501cb808b83ce738548a315509cc478473ca344ac9e2975521230e9654b78bc35db4e489dc47ed2c711d
7
- data.tar.gz: c18707a6fc4f48be132091376dc6ec39322868aabd1fdcb5201ae53421947abfff3bcbc790cc6068345fe979f3cfb9b47db6fe3a3263fb0c7f7e225033ed9a9f
6
+ metadata.gz: b47c5ea02935ff7082779b07dfe2275af3e8d5851b63772364665d5425380ea7e6cd6b98adfe1bc7502af1f0e924b343f56d3a2e303afdfdc2118f133ec8c043
7
+ data.tar.gz: ee6f09275d11db038970e79661669e06013011a9100fbd449cd59e1a7f8a33818502074e7c564b14cbbf3cc10f660fac8827b0a6fb90d4e20fcc6cdd62eec2ae
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # NovaposhtaApi
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/novaposhta_api`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Simple Novaposhta API 2.0 Ruby client. API documentation by link https://devcenter.novaposhta.ua/docs/services/
6
4
 
7
5
  ## Installation
8
6
 
@@ -20,19 +18,47 @@ Or install it yourself as:
20
18
 
21
19
  $ gem install novaposhta_api
22
20
 
21
+ ## Setup
22
+
23
+ ```
24
+ NovaposhtaApi.setup do |config|
25
+ config.api_url = 'https://api.novaposhta.ua/v2.0/json/'
26
+ config.api_key = 'KEY'
27
+ end
28
+ ```
29
+
23
30
  ## Usage
24
31
 
25
- TODO: Write usage instructions here
32
+ Define API client:
33
+ ```
34
+ client = NovaposhtaApi::Client.new
35
+ ```
26
36
 
27
- ## Development
37
+ Cities:
38
+ ```
39
+ client.cities.all
40
+ ```
28
41
 
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
42
+ Settlements:
43
+ ```
44
+ client.settlements.all
45
+ ```
46
+
47
+ Warehouses:
48
+ ```
49
+ client.warehouses.all
50
+ ```
51
+
52
+ Create internet document:
53
+ ```
54
+ client.internet_documents.create(params)
55
+ ```
30
56
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
57
+ TODO
32
58
 
33
59
  ## Contributing
34
60
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/novaposhta_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/novaposhta_api/blob/master/CODE_OF_CONDUCT.md).
61
+ Bug reports and pull requests are welcome on GitHub at https://github.com/venethub/novaposhta_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/venethub/novaposhta_api/blob/master/CODE_OF_CONDUCT.md).
36
62
 
37
63
 
38
64
  ## License
@@ -41,4 +67,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
41
67
 
42
68
  ## Code of Conduct
43
69
 
44
- Everyone interacting in the NovaposhtaApi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/novaposhta_api/blob/master/CODE_OF_CONDUCT.md).
70
+ Everyone interacting in the NovaposhtaApi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/venethub/novaposhta_api/blob/master/CODE_OF_CONDUCT.md).
@@ -6,6 +6,8 @@ module NovaposhtaApi
6
6
 
7
7
  def initialize(api_key: nil)
8
8
  @api_key = api_key
9
+
10
+ yield(http.connection) if block_given?
9
11
  end
10
12
 
11
13
  def self.resources
@@ -21,7 +23,7 @@ module NovaposhtaApi
21
23
 
22
24
  def method_missing(name, *args, &block)
23
25
  if with_resource?(name)
24
- resources[name] ||= self.class.resources[name].new(connection: connection)
26
+ resources[name] ||= self.class.resources[name].new(http: http)
25
27
  resources[name]
26
28
  else
27
29
  super
@@ -40,8 +42,8 @@ module NovaposhtaApi
40
42
  @resources ||= {}
41
43
  end
42
44
 
43
- def connection
44
- @connection ||= NovaposhtaApi::HttpClient.new(
45
+ def http
46
+ @http ||= NovaposhtaApi::HttpClient.new(
45
47
  uri: NovaposhtaApi.configuration.api_url,
46
48
  api_key: api_key || NovaposhtaApi.configuration.api_key
47
49
  )
@@ -11,6 +11,8 @@ module NovaposhtaApi
11
11
 
12
12
  def initialize(config)
13
13
  @config = config.with_indifferent_access
14
+
15
+ yield(connection) if block_given?
14
16
  end
15
17
 
16
18
  def uri
@@ -27,20 +29,16 @@ module NovaposhtaApi
27
29
  response.body
28
30
  end
29
31
 
30
- private
31
-
32
- def transform_keys(params)
33
- convert_params_to_hash(params).deep_transform_keys { |key| key.to_s.camelcase }
34
- end
35
-
36
- def convert_params_to_hash(params)
37
- if params.respond_to?(:to_unsafe_h)
38
- params.to_unsafe_h
39
- else
40
- params
32
+ def connection
33
+ @connection ||= Faraday.new(connection_options) do |client|
34
+ client.adapter Faraday.default_adapter
35
+ client.response :error_handling
36
+ client.response :json
41
37
  end
42
38
  end
43
39
 
40
+ private
41
+
44
42
  def build_options(path)
45
43
  paths = path.split('/')
46
44
 
@@ -51,19 +49,23 @@ module NovaposhtaApi
51
49
  }
52
50
  end
53
51
 
54
- def connection
55
- @connection ||= Faraday.new(connection_options) do |client|
56
- client.adapter Faraday.default_adapter
57
- client.response :error_handling
58
- client.response :json
59
- end
60
- end
61
-
62
52
  def connection_options
63
53
  {
64
54
  url: uri,
65
55
  headers: DEFAULT_HEADERS
66
56
  }
67
57
  end
58
+
59
+ def transform_keys(params)
60
+ convert_params_to_hash(params).deep_transform_keys { |key| key.to_s.camelcase }
61
+ end
62
+
63
+ def convert_params_to_hash(params)
64
+ if params.respond_to?(:to_unsafe_h)
65
+ params.to_unsafe_h
66
+ else
67
+ params
68
+ end
69
+ end
68
70
  end
69
71
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module NovaposhtaApi
4
4
  module Middlewares
5
- class ErrorHandling < Faraday::Response::Middleware
5
+ class ErrorHandling < Faraday::Middleware
6
6
  SEPARATOR = ', '
7
7
 
8
8
  def on_complete(env)
@@ -7,6 +7,9 @@ module NovaposhtaApi
7
7
  property :city_id, from: :CityID
8
8
  property :area, from: :Area
9
9
  property :description, from: :Description
10
+ property :description_ru, from: :DescriptionRu
11
+ property :settlement_type_description, from: :SettlementTypeDescription
12
+ property :settlement_type_description_ru, from: :SettlementTypeDescriptionRu
10
13
  end
11
14
  end
12
15
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NovaposhtaApi
4
+ module Models
5
+ class ContactPerson < Model
6
+ property :ref, from: :Ref
7
+ property :first_name, from: :FirstName
8
+ property :middle_name, from: :MiddleName
9
+ property :last_name, from: :LastName
10
+ property :phones, from: :Phones
11
+ property :description, from: :Description
12
+ property :email, from: :Email
13
+ end
14
+ end
15
+ end
@@ -6,7 +6,9 @@ module NovaposhtaApi
6
6
  property :ref, from: :Ref
7
7
  property :city_ref, from: :CityRef
8
8
  property :city_description, from: :CityDescription
9
+ property :city_description_ru, from: :CityDescriptionRu
9
10
  property :description, from: :Description
11
+ property :description_ru, from: :DescriptionRu
10
12
  property :short_address, from: :ShortAddress
11
13
  property :longitude, from: :Longitude
12
14
  property :latitude, from: :Latitude
@@ -2,18 +2,17 @@
2
2
 
3
3
  module NovaposhtaApi
4
4
  class Resource
5
- attr_reader :connection
5
+ attr_reader :http
6
6
 
7
7
  HTTP_METHODS = %i[get post patch put delete].freeze
8
- CACHE_OPTIONS = {expires_in: 1.day}.freeze
9
8
 
10
- def initialize(connection: nil)
11
- @connection = connection
9
+ def initialize(http: nil)
10
+ @http = http
12
11
  end
13
12
 
14
13
  HTTP_METHODS.each do |http_method|
15
14
  define_method http_method do |*args|
16
- response = connection.request(http_method, *args)
15
+ response = http.request(http_method, *args)
17
16
  response['data']
18
17
  end
19
18
  end
@@ -4,9 +4,7 @@ module NovaposhtaApi
4
4
  module Resources
5
5
  class CityResource < Resource
6
6
  def all(params = {})
7
- response = Rails.cache.fetch("cities/#{params}", CACHE_OPTIONS) do
8
- post('Address/getCities', params)
9
- end
7
+ response = post('Address/getCities', params)
10
8
 
11
9
  NovaposhtaApi::Models::City.extract_collection(response)
12
10
  end
@@ -4,9 +4,7 @@ module NovaposhtaApi
4
4
  module Resources
5
5
  class SettlementResource < Resource
6
6
  def all(params = {})
7
- response = Rails.cache.fetch("settlements/#{params}", CACHE_OPTIONS) do
8
- post('Address/searchSettlements', params)
9
- end
7
+ response = post('Address/searchSettlements', params)
10
8
 
11
9
  NovaposhtaApi::Models::Settlement.extract_collection(response[0]['Addresses'])
12
10
  end
@@ -4,9 +4,7 @@ module NovaposhtaApi
4
4
  module Resources
5
5
  class WarehouseResource < Resource
6
6
  def all(params = {})
7
- response = Rails.cache.fetch("warehouses/#{params}", CACHE_OPTIONS) do
8
- post('Address/getWarehouses', params)
9
- end
7
+ response = post('Address/getWarehouses', params)
10
8
 
11
9
  NovaposhtaApi::Models::Warehouse.extract_collection(response)
12
10
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NovaposhtaApi
4
- VERSION = '0.1.3'
4
+ VERSION = '0.1.7'
5
5
  end
@@ -12,7 +12,6 @@ module NovaposhtaApi
12
12
 
13
13
  module Middlewares
14
14
  autoload :ErrorHandling, 'novaposhta_api/middlewares/error_handling'
15
- autoload :ParseJson, 'novaposhta_api/middlewares/parse_json'
16
15
  end
17
16
 
18
17
  module Resources
@@ -31,6 +30,7 @@ module NovaposhtaApi
31
30
  autoload :TrackingDocument, 'novaposhta_api/models/tracking_document'
32
31
  autoload :Settlement, 'novaposhta_api/models/settlement'
33
32
  autoload :Warehouse, 'novaposhta_api/models/warehouse'
33
+ autoload :ContactPerson, 'novaposhta_api/models/contact_person'
34
34
  end
35
35
 
36
36
  Error = Class.new(StandardError)
@@ -51,7 +51,7 @@ module NovaposhtaApi
51
51
 
52
52
  # @example
53
53
  # NovaposhtaApi.setup do |config|
54
- # config.api_url = "https://api.novaposhta.ua/v2.0/json/"
54
+ # config.api_url = 'https://api.novaposhta.ua/v2.0/json/'
55
55
  # end
56
56
  #
57
57
  def self.setup
@@ -59,7 +59,6 @@ module NovaposhtaApi
59
59
  end
60
60
 
61
61
  if Faraday::Middleware.respond_to? :register_middleware
62
- Faraday::Response.register_middleware json: NovaposhtaApi::Middlewares::ParseJson
63
62
  Faraday::Response.register_middleware error_handling: NovaposhtaApi::Middlewares::ErrorHandling
64
63
  end
65
64
  end
@@ -25,8 +25,8 @@ Gem::Specification.new do |spec|
25
25
  spec.executables = spec.files.grep(%r(^exe/)) { |f| File.basename(f) }
26
26
  spec.require_paths = ['lib']
27
27
 
28
- spec.add_dependency 'faraday', '~> 1.0', '>= 1.0.1'
28
+ spec.add_dependency 'faraday', '~> 2.2'
29
29
  spec.add_dependency 'hashie', '~> 4.1'
30
30
 
31
- spec.add_development_dependency 'rubocop', '~> 0.86.0'
31
+ spec.add_development_dependency 'rubocop', '~> 1.25'
32
32
  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.3
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - venet
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-06 00:00:00.000000000 Z
11
+ date: 2022-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -16,20 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.0'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 1.0.1
19
+ version: '2.2'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '1.0'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 1.0.1
26
+ version: '2.2'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: hashie
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -50,14 +44,14 @@ dependencies:
50
44
  requirements:
51
45
  - - "~>"
52
46
  - !ruby/object:Gem::Version
53
- version: 0.86.0
47
+ version: '1.25'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
51
  requirements:
58
52
  - - "~>"
59
53
  - !ruby/object:Gem::Version
60
- version: 0.86.0
54
+ version: '1.25'
61
55
  description: Ruby wrapper for NovaPoshta API 2.0.
62
56
  email:
63
57
  - venet.dev@gmail.com
@@ -84,9 +78,9 @@ files:
84
78
  - lib/novaposhta_api/configuration.rb
85
79
  - lib/novaposhta_api/http_client.rb
86
80
  - lib/novaposhta_api/middlewares/error_handling.rb
87
- - lib/novaposhta_api/middlewares/parse_json.rb
88
81
  - lib/novaposhta_api/model.rb
89
82
  - lib/novaposhta_api/models/city.rb
83
+ - lib/novaposhta_api/models/contact_person.rb
90
84
  - lib/novaposhta_api/models/counterparty.rb
91
85
  - lib/novaposhta_api/models/internet_document.rb
92
86
  - lib/novaposhta_api/models/settlement.rb
@@ -107,7 +101,7 @@ licenses:
107
101
  - MIT
108
102
  metadata:
109
103
  homepage_uri: https://github.com/venethub/novaposhta_api
110
- post_install_message:
104
+ post_install_message:
111
105
  rdoc_options: []
112
106
  require_paths:
113
107
  - lib
@@ -122,9 +116,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
116
  - !ruby/object:Gem::Version
123
117
  version: '0'
124
118
  requirements: []
125
- rubyforge_project:
126
- rubygems_version: 2.7.6.2
127
- signing_key:
119
+ rubygems_version: 3.2.32
120
+ signing_key:
128
121
  specification_version: 4
129
122
  summary: Novaposhta API 2.0 client
130
123
  test_files: []
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module NovaposhtaApi
4
- module Middlewares
5
- class ParseJson < Faraday::Response::Middleware
6
- def on_complete(env)
7
- process_response(env)
8
- end
9
-
10
- def process_response(env)
11
- env[:body] = JSON.parse(env[:body])
12
- rescue Faraday::ParsingError => e
13
- raise Faraday::ParsingError.new(e.wrapped_exception, env[:response])
14
- end
15
- end
16
- end
17
- end