novaposhta_api 0.1.4 → 0.1.5

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: 27b5e088bffd8d40473377c7f1a385845da0bd2e927e6dabccf1768bc8e082ac
4
- data.tar.gz: b372fdda387d3624bb89af76741fdd340901b33684b26c00a6ad3906c965eb3b
3
+ metadata.gz: 979e8503642e0311557adf2f503d6fea346d15bde8fc638f1fcdac4ab1b41b6a
4
+ data.tar.gz: 9f787311d1bac8896aa7db12033a6868797ee86455b49ae99895508fef586847
5
5
  SHA512:
6
- metadata.gz: 11af93b86668497b2984bc84ad23248800a8627fd6851e363a6a7c6587b96b73f92664063b90b06e1d257dda71c0fa5115eb6cc86bfeae3ced4cf24242e5cff4
7
- data.tar.gz: 55eaee4db23d4cf22d3d332aa0109e32c27eab888c9b0920422ff9ad4afb7c6a978a5ec1a4e34d31ae12195f17aca2b6b487b2530fd54cfcc5569fcef1817ca1
6
+ metadata.gz: 3c02d4ce41f85b731e55e1271653d4679c3a36a06a677221017a1c7d70d9ea025340c764c7c34f42a6395f1754b079e67c52caeed1ba39468f32f431b3f13b92
7
+ data.tar.gz: 9522235cb31bb5ff29ed162c5a0630dfa60fe64363efa49353172d909b6d8fec1963b0f16c48a3e1f76f56ed5633d55bb3b8db7255602b8348d531d4cf1dbe25
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).
@@ -52,7 +52,7 @@ module NovaposhtaApi
52
52
 
53
53
  # @example
54
54
  # NovaposhtaApi.setup do |config|
55
- # config.api_url = "https://api.novaposhta.ua/v2.0/json/"
55
+ # config.api_url = 'https://api.novaposhta.ua/v2.0/json/'
56
56
  # end
57
57
  #
58
58
  def self.setup
@@ -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
@@ -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
@@ -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.4'
4
+ VERSION = '0.1.5'
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.4
4
+ version: 0.1.5
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-27 00:00:00.000000000 Z
11
+ date: 2021-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -108,7 +108,7 @@ licenses:
108
108
  - MIT
109
109
  metadata:
110
110
  homepage_uri: https://github.com/venethub/novaposhta_api
111
- post_install_message:
111
+ post_install_message:
112
112
  rdoc_options: []
113
113
  require_paths:
114
114
  - lib
@@ -123,9 +123,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  requirements: []
126
- rubyforge_project:
127
- rubygems_version: 2.7.6.2
128
- signing_key:
126
+ rubygems_version: 3.0.9
127
+ signing_key:
129
128
  specification_version: 4
130
129
  summary: Novaposhta API 2.0 client
131
130
  test_files: []