novaposhta_api 0.1.4 → 0.1.5
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/README.md +35 -9
- data/lib/novaposhta_api.rb +1 -1
- data/lib/novaposhta_api/client.rb +5 -3
- data/lib/novaposhta_api/http_client.rb +21 -19
- data/lib/novaposhta_api/models/city.rb +3 -0
- data/lib/novaposhta_api/models/warehouse.rb +2 -0
- data/lib/novaposhta_api/resource.rb +4 -5
- data/lib/novaposhta_api/resources/city_resource.rb +1 -3
- data/lib/novaposhta_api/resources/settlement_resource.rb +1 -3
- data/lib/novaposhta_api/resources/warehouse_resource.rb +1 -3
- data/lib/novaposhta_api/version.rb +1 -1
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 979e8503642e0311557adf2f503d6fea346d15bde8fc638f1fcdac4ab1b41b6a
|
4
|
+
data.tar.gz: 9f787311d1bac8896aa7db12033a6868797ee86455b49ae99895508fef586847
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c02d4ce41f85b731e55e1271653d4679c3a36a06a677221017a1c7d70d9ea025340c764c7c34f42a6395f1754b079e67c52caeed1ba39468f32f431b3f13b92
|
7
|
+
data.tar.gz: 9522235cb31bb5ff29ed162c5a0630dfa60fe64363efa49353172d909b6d8fec1963b0f16c48a3e1f76f56ed5633d55bb3b8db7255602b8348d531d4cf1dbe25
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# NovaposhtaApi
|
2
2
|
|
3
|
-
|
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
|
-
|
32
|
+
Define API client:
|
33
|
+
```
|
34
|
+
client = NovaposhtaApi::Client.new
|
35
|
+
```
|
26
36
|
|
27
|
-
|
37
|
+
Cities:
|
38
|
+
```
|
39
|
+
client.cities.all
|
40
|
+
```
|
28
41
|
|
29
|
-
|
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
|
-
|
57
|
+
TODO
|
32
58
|
|
33
59
|
## Contributing
|
34
60
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
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/
|
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).
|
data/lib/novaposhta_api.rb
CHANGED
@@ -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(
|
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
|
44
|
-
@
|
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
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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 :
|
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(
|
11
|
-
@
|
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 =
|
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 =
|
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 =
|
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 =
|
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
|
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.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:
|
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
|
-
|
127
|
-
|
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: []
|