nova_poshta 0.2.0 → 0.3.0
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 +1 -2
- data/lib/nova_poshta.rb +4 -0
- data/lib/nova_poshta/api.rb +6 -7
- data/lib/nova_poshta/model/address.rb +3 -3
- data/lib/nova_poshta/model/base.rb +7 -3
- data/lib/nova_poshta/response/area.rb +31 -2
- data/lib/nova_poshta/response/base.rb +5 -1
- data/lib/nova_poshta/response/city.rb +2 -2
- data/lib/nova_poshta/response/warehouse.rb +1 -1
- data/lib/nova_poshta/result.rb +1 -3
- data/lib/nova_poshta/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0829a4dcc8d7cff1fa73bdc3066bfde04ff1efae
|
4
|
+
data.tar.gz: b3a8ec438420c4bbe0eb808be32bb566912ce765
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7a0b9db91fc55c075b34198b0ef0874dec4c6550399b27b131bc816311340dfd0c15a3f87263b54820882287f6779a86ef815fcafc951adfc9d164b1b6f3e82
|
7
|
+
data.tar.gz: 5082502f1ab10ac26bf738f856ac464291157256e9f8e76f1d3afa3e895714df9f7934a97a7ef372ca10dab40a3606901b950b3955917f4087cad2e66fd2da70
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# NovaPoshta
|
2
2
|
|
3
|
+
[](https://badge.fury.io/rb/nova_poshta)
|
3
4
|
[](https://travis-ci.org/gigorok/nova_poshta)
|
4
5
|
|
5
6
|
Ruby-client to novaposhta.ua API2.
|
@@ -48,8 +49,6 @@ a.areas
|
|
48
49
|
|
49
50
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
50
51
|
|
51
|
-
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).
|
52
|
-
|
53
52
|
## Contributing
|
54
53
|
|
55
54
|
Bug reports and pull requests are welcome on GitHub at https://github.com/gigorok/nova_poshta. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
data/lib/nova_poshta.rb
CHANGED
data/lib/nova_poshta/api.rb
CHANGED
@@ -6,19 +6,18 @@ module NovaPoshta
|
|
6
6
|
class Api
|
7
7
|
API_URL = 'https://api.novaposhta.ua/v2.0/json/'.freeze
|
8
8
|
|
9
|
-
attr_accessor :api_key
|
9
|
+
attr_accessor :api_key
|
10
10
|
|
11
|
-
def initialize
|
11
|
+
def initialize
|
12
12
|
self.api_key = NovaPoshta.configuration.api_key
|
13
|
-
self.model_name = model_name
|
14
13
|
end
|
15
14
|
|
16
|
-
def request(called_method, method_properties={})
|
17
|
-
response = post(request_body(called_method, method_properties))
|
18
|
-
::NovaPoshta::Result.new(response, called_method
|
15
|
+
def request(model_name, called_method, method_properties={})
|
16
|
+
response = post(request_body(model_name, called_method, method_properties))
|
17
|
+
::NovaPoshta::Result.new(response, called_method)
|
19
18
|
end
|
20
19
|
|
21
|
-
def request_body(called_method, method_props={})
|
20
|
+
def request_body(model_name, called_method, method_props={})
|
22
21
|
camelize_keys(
|
23
22
|
{
|
24
23
|
api_key: api_key,
|
@@ -4,15 +4,15 @@ module NovaPoshta
|
|
4
4
|
|
5
5
|
# you can use params as {find_by_string: 'Одесса'} to filter by city_name
|
6
6
|
def cities(params={})
|
7
|
-
|
7
|
+
request('getCities', params)
|
8
8
|
end
|
9
9
|
|
10
10
|
def warehouses(city_ref, params={})
|
11
|
-
|
11
|
+
request('getWarehouses', {city_ref: city_ref}.merge(params))
|
12
12
|
end
|
13
13
|
|
14
14
|
def areas(params={})
|
15
|
-
|
15
|
+
request('getAreas', params)
|
16
16
|
end
|
17
17
|
|
18
18
|
end
|
@@ -2,10 +2,14 @@ module NovaPoshta
|
|
2
2
|
module Model
|
3
3
|
class Base
|
4
4
|
|
5
|
-
|
5
|
+
protected
|
6
6
|
|
7
|
-
def
|
8
|
-
|
7
|
+
def request(called_method, method_properties={})
|
8
|
+
NovaPoshta.api.request(model_name, called_method, method_properties)
|
9
|
+
end
|
10
|
+
|
11
|
+
def model_name
|
12
|
+
self.class.name.demodulize
|
9
13
|
end
|
10
14
|
|
11
15
|
end
|
@@ -6,9 +6,38 @@ module NovaPoshta
|
|
6
6
|
|
7
7
|
# ugly API do not provide searching by area reference
|
8
8
|
def cities(params={})
|
9
|
-
|
9
|
+
|
10
|
+
# return NovaPoshta::Result
|
11
|
+
c = address.cities(params).select { |city| city.area_ref == self.ref }
|
12
|
+
data = c.map do |city|
|
13
|
+
{
|
14
|
+
:'Description' => city.description,
|
15
|
+
:'DescriptionRu' => city.description_ru,
|
16
|
+
:'Ref' => city.ref,
|
17
|
+
:'Delivery1' => city.delivery1,
|
18
|
+
:'Delivery2' => city.delivery2,
|
19
|
+
:'Delivery3' => city.delivery3,
|
20
|
+
:'Delivery4' => city.delivery4,
|
21
|
+
:'Delivery5' => city.delivery5,
|
22
|
+
:'Delivery6' => city.delivery6,
|
23
|
+
:'Delivery7' => city.delivery7,
|
24
|
+
:'Area' => city.area_ref,
|
25
|
+
:'Conglomerates' => city.conglomerates,
|
26
|
+
:'CityID' => city.city_id,
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
r = {
|
31
|
+
success: true,
|
32
|
+
data: data,
|
33
|
+
errors: [],
|
34
|
+
warnings: [],
|
35
|
+
info: []
|
36
|
+
}
|
37
|
+
|
38
|
+
::NovaPoshta::Result.new(r.to_json, 'getCities')
|
10
39
|
end
|
11
40
|
|
12
41
|
end
|
13
42
|
end
|
14
|
-
end
|
43
|
+
end
|
@@ -2,7 +2,7 @@ module NovaPoshta
|
|
2
2
|
module Response
|
3
3
|
class Base
|
4
4
|
|
5
|
-
attr_accessor :
|
5
|
+
attr_accessor :result
|
6
6
|
|
7
7
|
def initialize(attrs)
|
8
8
|
attrs.each do |k, v|
|
@@ -14,6 +14,10 @@ module NovaPoshta
|
|
14
14
|
yield self if block_given?
|
15
15
|
end
|
16
16
|
|
17
|
+
def address
|
18
|
+
@address ||= Model::Address.new
|
19
|
+
end
|
20
|
+
|
17
21
|
end
|
18
22
|
end
|
19
23
|
end
|
@@ -6,11 +6,11 @@ module NovaPoshta
|
|
6
6
|
:delivery5, :delivery6, :delivery7, :area_ref, :conglomerates, :city_id
|
7
7
|
|
8
8
|
def warehouses(params={})
|
9
|
-
|
9
|
+
address.warehouses(self.ref, params)
|
10
10
|
end
|
11
11
|
|
12
12
|
def area(params={})
|
13
|
-
|
13
|
+
address.areas(params).select { |area| area.ref == self.area_ref }.first.result
|
14
14
|
end
|
15
15
|
|
16
16
|
# city has area attribute, but it should be area_ref, so next writer will fix this situation
|
@@ -9,7 +9,7 @@ module NovaPoshta
|
|
9
9
|
|
10
10
|
# ugly API do not provide searching by city reference
|
11
11
|
def city(params={})
|
12
|
-
|
12
|
+
address.cities(params).select { |city| city.ref == self.city_ref }.first.result
|
13
13
|
end
|
14
14
|
|
15
15
|
end
|
data/lib/nova_poshta/result.rb
CHANGED
@@ -6,11 +6,10 @@ module NovaPoshta
|
|
6
6
|
attr_accessor :success, :data, :errors, :warnings, :info
|
7
7
|
attr_reader :body, :raw_body
|
8
8
|
|
9
|
-
def initialize(raw_body, called_method
|
9
|
+
def initialize(raw_body, called_method)
|
10
10
|
@raw_body = raw_body
|
11
11
|
@body = JSON.parse(raw_body)
|
12
12
|
@called_method = called_method
|
13
|
-
@api = api
|
14
13
|
end
|
15
14
|
|
16
15
|
def success?
|
@@ -20,7 +19,6 @@ module NovaPoshta
|
|
20
19
|
def data
|
21
20
|
body['data'].map do |attrs|
|
22
21
|
response_class.new(attrs) do |r|
|
23
|
-
r.api = @api
|
24
22
|
r.result = self
|
25
23
|
end
|
26
24
|
end if body['data']
|
data/lib/nova_poshta/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nova_poshta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Gonchar
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|