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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: baf0a2127bb62c5a4479b4b3f73917aca8607eb3
4
- data.tar.gz: f74ec24bbb02caa93c0fbda878449506a0bac600
3
+ metadata.gz: 0829a4dcc8d7cff1fa73bdc3066bfde04ff1efae
4
+ data.tar.gz: b3a8ec438420c4bbe0eb808be32bb566912ce765
5
5
  SHA512:
6
- metadata.gz: db600f9067af16c9f3f1fb78119639fc187352937db4843f5d5265c6a451f0774ad0735a57441da8d483c588ab0454b6955e201deef3433e6a74678197f171a9
7
- data.tar.gz: b8b30f998e7e54c83a08b184a875724f9b7df5c80ae7f823dccf9a90cbe9b43ed86bde55d3eb68c3ab52ab3ecb1b165d509758ce03f5af585eec2e42f3415898
6
+ metadata.gz: f7a0b9db91fc55c075b34198b0ef0874dec4c6550399b27b131bc816311340dfd0c15a3f87263b54820882287f6779a86ef815fcafc951adfc9d164b1b6f3e82
7
+ data.tar.gz: 5082502f1ab10ac26bf738f856ac464291157256e9f8e76f1d3afa3e895714df9f7934a97a7ef372ca10dab40a3606901b950b3955917f4087cad2e66fd2da70
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # NovaPoshta
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/nova_poshta.svg)](https://badge.fury.io/rb/nova_poshta)
3
4
  [![Build Status](https://travis-ci.org/gigorok/nova_poshta.svg?branch=master)](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
@@ -10,6 +10,10 @@ Dir[File.dirname(__FILE__) + '/nova_poshta/model/*.rb'].each { |f| require f }
10
10
 
11
11
  module NovaPoshta
12
12
 
13
+ def self.api
14
+ @@api ||= NovaPoshta::Api.new
15
+ end
16
+
13
17
  def self.configuration
14
18
  @configuration ||= Configuration.new
15
19
  end
@@ -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, :model_name
9
+ attr_accessor :api_key
10
10
 
11
- def initialize(model_name)
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, self)
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
- api.request('getCities', params)
7
+ request('getCities', params)
8
8
  end
9
9
 
10
10
  def warehouses(city_ref, params={})
11
- api.request('getWarehouses', {city_ref: city_ref}.merge(params))
11
+ request('getWarehouses', {city_ref: city_ref}.merge(params))
12
12
  end
13
13
 
14
14
  def areas(params={})
15
- api.request('getAreas', params)
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
- attr_accessor :api
5
+ protected
6
6
 
7
- def api
8
- @api ||= Api.new(self.class.name.split('::').last)
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
- @api.request('getCities', params).select { |city| city.area_ref == self.ref }
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 :api, :result
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
- @api.request('getWarehouses', {city_ref: self.ref}.merge(params))
9
+ address.warehouses(self.ref, params)
10
10
  end
11
11
 
12
12
  def area(params={})
13
- @api.request('getAreas', params).select { |area| area.ref == self.area_ref }.first.result
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
- @api.request('getCities', params).select { |city| city.ref == self.city_ref }.first.result
12
+ address.cities(params).select { |city| city.ref == self.city_ref }.first.result
13
13
  end
14
14
 
15
15
  end
@@ -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, api)
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']
@@ -1,3 +1,3 @@
1
1
  module NovaPoshta
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
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.2.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-05-28 00:00:00.000000000 Z
11
+ date: 2016-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport