pec_calc_client 1.0.1 → 1.1.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: f1649565b1eb9a909a3317eefd280cc6b77c436c
4
- data.tar.gz: 9aafc336b1a3c22e01278971e3c50a28dd8c75d2
3
+ metadata.gz: ac26ccc8942f900194dd2382978196f9dea74bf7
4
+ data.tar.gz: 6d27386f092e3518130b29d71718e3854396ea07
5
5
  SHA512:
6
- metadata.gz: b5a19004f6e6267cc2f96f096c5b8fc16199fe27df1d82a600ffa7ff3c036071ac2708e590d2e854218c431e66d5e5de1132cec25b5d82bf7ebc691c0441fc1b
7
- data.tar.gz: 910a1abf359bdc9b343c9c9981204f70f4d8f0c6b8175fac3cae28679fa29ee996f7f965d27f756e2e377cd141a3dbe8b7e18d68ef75a12542ec1ff3d6dc224a
6
+ metadata.gz: 186f65e3ff0ebc6602fd7d076a41dcb624a08061b4ca230c6e4211c7dc8c339bbd59407d4419830818a5676021afa2c948730ff30b6aa26bf69421af87cc2242
7
+ data.tar.gz: 3440513627f187a9a3817729f656b6cd0892861848e47ec2ac6f55eabf81519a523f58faf4a50334d2541f07a144722e3429b8eada157702ef1956539c8d3a2a
data/Gemfile.lock CHANGED
@@ -1,32 +1,31 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pec_calc_client (1.0.0)
4
+ pec_calc_client (0.1.2)
5
5
  json (~> 1.8)
6
- rack (~> 1.6)
7
6
 
8
7
  GEM
9
8
  remote: https://rubygems.org/
10
9
  specs:
11
10
  diff-lcs (1.2.5)
12
- faker (1.5.0)
11
+ faker (1.6.1)
13
12
  i18n (~> 0.5)
14
13
  i18n (0.7.0)
15
14
  json (1.8.3)
16
15
  rack (1.6.4)
17
- rspec (3.3.0)
18
- rspec-core (~> 3.3.0)
19
- rspec-expectations (~> 3.3.0)
20
- rspec-mocks (~> 3.3.0)
21
- rspec-core (3.3.2)
22
- rspec-support (~> 3.3.0)
23
- rspec-expectations (3.3.1)
16
+ rspec (3.4.0)
17
+ rspec-core (~> 3.4.0)
18
+ rspec-expectations (~> 3.4.0)
19
+ rspec-mocks (~> 3.4.0)
20
+ rspec-core (3.4.1)
21
+ rspec-support (~> 3.4.0)
22
+ rspec-expectations (3.4.0)
24
23
  diff-lcs (>= 1.2.0, < 2.0)
25
- rspec-support (~> 3.3.0)
26
- rspec-mocks (3.3.2)
24
+ rspec-support (~> 3.4.0)
25
+ rspec-mocks (3.4.0)
27
26
  diff-lcs (>= 1.2.0, < 2.0)
28
- rspec-support (~> 3.3.0)
29
- rspec-support (3.3.0)
27
+ rspec-support (~> 3.4.0)
28
+ rspec-support (3.4.1)
30
29
 
31
30
  PLATFORMS
32
31
  ruby
@@ -39,4 +38,4 @@ DEPENDENCIES
39
38
  rspec
40
39
 
41
40
  BUNDLED WITH
42
- 1.10.6
41
+ 1.11.2
data/README.md CHANGED
@@ -23,14 +23,14 @@ Or install it yourself as:
23
23
 
24
24
  ## Usage
25
25
 
26
- Get Delivery Regions:
26
+ Get Delivery Regions:
27
27
 
28
28
  ```ruby
29
29
  require 'pec_calc_client'
30
30
 
31
31
  PecCalcClient::Region.all
32
32
  ```
33
- Extract Delivery Cities by region:
33
+ Extract Delivery Cities by region:
34
34
 
35
35
  ```ruby
36
36
  require 'pec_calc_client'
data/bin/console CHANGED
@@ -7,7 +7,7 @@ require 'pec/calc/client'
7
7
  # with your gem easier. You can also use a different console, if you like.
8
8
 
9
9
  # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require 'pry'
10
+ # require "pry"
11
11
  # Pry.start
12
12
 
13
13
  require 'irb'
@@ -1,5 +1,4 @@
1
1
  module PecCalcClient
2
- # Calculator container
3
2
  class Calc
4
3
  extend RequestClass
5
4
  include RequestObject
@@ -25,9 +24,7 @@ module PecCalcClient
25
24
  out = to_h
26
25
  out[:deliver] = @delivery.to_h
27
26
  out[:take] = @take.to_h
28
- out[:places] = @places.each_with_index.map do |place, i|
29
- [i, place.to_a]
30
- end.to_h
27
+ out[:places] = @places.each_with_index.map { |place, i| [i, place.to_a] }.to_h
31
28
  out
32
29
  end
33
30
 
@@ -2,7 +2,6 @@ require 'net/http'
2
2
  require 'rack/utils'
3
3
 
4
4
  module PecCalcClient
5
- # HTTP Connector
6
5
  class Connector
7
6
  def initialize(url)
8
7
  @url = url.to_s
@@ -21,10 +20,7 @@ module PecCalcClient
21
20
  private
22
21
 
23
22
  def prepare_params(params)
24
- @params_string = Rack::Utils.build_nested_query(params).gsub(
25
- /[\[\]\.\-]/,
26
- '[' => '%5B', ']' => '%5D', '.' => '%2E', '-' => '%2D'
27
- )
23
+ @params_string = Rack::Utils.build_nested_query(params).gsub(/[\[\]\.\-]/, '[' => '%5B', ']' => '%5D', '.' => '%2E', '-' => '%2D')
28
24
  end
29
25
 
30
26
  def url_with_params
@@ -1,22 +1,11 @@
1
1
  module PecCalcClient
2
- # Delivery Place
3
2
  class Place
4
- PLACE_PARAMS = %w(
5
- width
6
- length
7
- height
8
- volume
9
- weight
10
- oversized
11
- sturdy_packaging
12
- )
3
+ PLACE_PARAMS = %w( width length height volume weight oversized sturdy_packaging )
13
4
 
14
5
  PLACE_PARAMS.each { |param_name| attr_reader param_name }
15
6
 
16
7
  def initialize(params)
17
- params.each do |k, v|
18
- instance_variable_set("@#{k}", v) if PLACE_PARAMS.include? k.to_s
19
- end
8
+ params.each { |k, v| instance_variable_set("@#{k}", v) if PLACE_PARAMS.include? k.to_s }
20
9
  end
21
10
 
22
11
  def to_a
@@ -1,5 +1,4 @@
1
1
  module PecCalcClient
2
- # Delivery region
3
2
  class Region
4
3
  URL = 'http://pecom.ru/ru/calc/towns.php'
5
4
 
@@ -7,13 +6,12 @@ module PecCalcClient
7
6
 
8
7
  def initialize(name, towns)
9
8
  @name = name
10
- @towns = towns.collect { |id, town_name| Town.new id, town_name }
9
+ @towns = towns.collect { |id, name| Town.new id, name }
11
10
  end
12
11
 
13
12
  def self.all
14
- Connector.new(self::URL).request.to_hash.collect do |name, towns|
15
- new name, towns
16
- end
13
+ @all = Connector.new(self::URL).request.to_hash.collect { |name, towns| new name, towns } if @all.nil?
14
+ @all
17
15
  end
18
16
  end
19
17
  end
@@ -1,5 +1,4 @@
1
1
  module PecCalcClient
2
- # Delivery town
3
2
  class Town
4
3
  attr_reader :id, :name
5
4
 
@@ -9,9 +8,8 @@ module PecCalcClient
9
8
  end
10
9
 
11
10
  def self.all
12
- Connector.new(URL).request.to_json.collect do |town|
13
- new town
14
- end
11
+ @all = Connector.new(URL).request.to_json.map{ |town| new town } if @all.nil?
12
+ @all
15
13
  end
16
14
  end
17
15
  end
@@ -1,37 +1,8 @@
1
1
  describe 'Calc' do
2
- calc_params = {
3
- plombir: 12,
4
- strah: 33,
5
- ashan: 1,
6
- night: 1,
7
- pal: 3,
8
- pallets: 4
9
- }
10
- place_params = {
11
- width: 0.5,
12
- length: 0.3,
13
- height: 0.5,
14
- volume: 0.2,
15
- weight: 0.03,
16
- oversized: true,
17
- sturdy_packaging: true
18
- }
19
- delivery_params = {
20
- town: 134_104,
21
- tent: 1,
22
- gidro: 1,
23
- manip: 1,
24
- speed: 0,
25
- moscow: 0
26
- }
27
- take_params = {
28
- town: 175_004,
29
- tent: 1,
30
- gidro: 1,
31
- manip: 1,
32
- speed: 1,
33
- moscow: 1
34
- }
2
+ calc_params = { plombir: 12, strah: 33, ashan: 1, night: 1, pal: 3, pallets: 4 }
3
+ place_params = { width: 0.5, length: 0.3, height: 0.5, volume: 0.2, weight: 0.03, oversized: true, sturdy_packaging: true }
4
+ delivery_params = { town: 134_104, tent: 1, gidro: 1, manip: 1, speed: 0, moscow: 0 }
5
+ take_params = { town: 175_004, tent: 1, gidro: 1, manip: 1, speed: 1, moscow: 1 }
35
6
 
36
7
  let! :calc do
37
8
  calc = PecCalcClient::Calc.new calc_params
@@ -44,9 +15,7 @@ describe 'Calc' do
44
15
  describe '#initialize' do
45
16
  it 'Should be initialized' do
46
17
  calc = PecCalcClient::Calc.new(calc_params)
47
- hash_of_params = PecCalcClient::Calc::PARAMS.map do |k|
48
- [k.to_sym, calc.send(k)]
49
- end.to_h
18
+ hash_of_params = PecCalcClient::Calc::PARAMS.map { |k| [k.to_sym, calc.send(k)] }.to_h
50
19
  expect(hash_of_params).to eq calc_params
51
20
  end
52
21
  end
@@ -18,8 +18,7 @@ describe 'Connector' do
18
18
  end
19
19
 
20
20
  it 'Raise Exception' do
21
- expect(-> { bad_connector.request })
22
- .to raise_error(PecCalcClient::ConnectionError)
21
+ expect(-> { bad_connector.request }).to raise_error(PecCalcClient::ConnectionError)
23
22
  end
24
23
  end
25
24
  end
@@ -1,19 +1,10 @@
1
1
  describe 'Delivery' do
2
- delivery_params = {
3
- town: 64_883,
4
- tent: 1,
5
- gidro: 1,
6
- manip: 1,
7
- speed: 0,
8
- moscow: 0
9
- }
2
+ delivery_params = { town: 64_883, tent: 1, gidro: 1, manip: 1, speed: 0, moscow: 0 }
10
3
 
11
4
  describe '#initialize' do
12
5
  it 'Should be initialized' do
13
6
  delivery = PecCalcClient::Delivery.new(delivery_params)
14
- hash_of_params = PecCalcClient::Delivery::PARAMS.map do |k|
15
- [k.to_sym, delivery.send(k)]
16
- end.to_h
7
+ hash_of_params = PecCalcClient::Delivery::PARAMS.map { |k| [k.to_sym, delivery.send(k)] }.to_h
17
8
  expect(hash_of_params).to eq delivery_params
18
9
  end
19
10
  end
@@ -1,27 +1,12 @@
1
- describe 'Place' do
2
- place_params = {
3
- width: 0.5,
4
- length: 0.3,
5
- height: 0.5,
6
- volume: 0.2,
7
- weight: 0.03,
8
- oversized: 1,
9
- sturdy_packaging: 1
10
- }
1
+ describe do
2
+ 'Place'
3
+ place_params = { width: 0.5, length: 0.3, height: 0.5, volume: 0.2, weight: 0.03, oversized: 1, sturdy_packaging: 1 }
11
4
  let!(:place) { PecCalcClient::Place.new place_params }
12
5
 
13
6
  describe '#initialize' do
14
7
  it 'Should be initialized' do
15
8
  place = PecCalcClient::Place.new(place_params)
16
- expect([
17
- place.width,
18
- place.length,
19
- place.height,
20
- place.volume,
21
- place.weight,
22
- place.oversized,
23
- place.sturdy_packaging
24
- ]).to eq place_params.values
9
+ expect([place.width, place.length, place.height, place.volume, place.weight, place.oversized, place.sturdy_packaging]).to eq place_params.values
25
10
  end
26
11
  end
27
12
 
@@ -1,10 +1,8 @@
1
+
1
2
  describe 'Region' do
2
3
  describe '#initialize' do
3
4
  it 'Should initialize' do
4
- region = PecCalcClient::Region.new(
5
- 'RegionName',
6
- [{ id: 14, name: 'Name1' }, { id: 11, name: 'Name' }]
7
- )
5
+ region = PecCalcClient::Region.new('RegionName', [{ id: 14, name: 'Name1' }, { id: 11, name: 'Name' }])
8
6
  expect(region.name).to eq 'RegionName'
9
7
  expect(region.towns.first.class.to_s).to eq 'PecCalcClient::Town'
10
8
  end
@@ -12,8 +12,7 @@ describe 'Response' do
12
12
  end
13
13
 
14
14
  it 'Raise Exception BadResponse' do
15
- expect(-> { not_found_connector.request })
16
- .to raise_error(PecCalcClient::BadResponse)
15
+ expect(-> { not_found_connector.request }).to raise_error(PecCalcClient::BadResponse)
17
16
  end
18
17
  end
19
18
 
@@ -4,9 +4,7 @@ describe 'Take' do
4
4
  describe '#initialize' do
5
5
  it 'Should be initialized' do
6
6
  take = PecCalcClient::Take.new(take_params)
7
- hash_of_params = PecCalcClient::Take::PARAMS.map do |k|
8
- [k.to_sym, take.send(k)]
9
- end.to_h
7
+ hash_of_params = PecCalcClient::Take::PARAMS.map { |k| [k.to_sym, take.send(k)] }.to_h
10
8
  expect(hash_of_params).to eq take_params
11
9
  end
12
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pec_calc_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - MAXOPKA
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-14 00:00:00.000000000 Z
11
+ date: 2016-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -24,23 +24,7 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.8'
27
- - !ruby/object:Gem::Dependency
28
- name: rack
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '1.6'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '1.6'
41
- description: |-
42
- Gem for working with public API http://pecom.ru/business/dev
43
- elopers/api_public/
27
+ description: Gem for working with public API http://pecom.ru/business/developers/api_public/
44
28
  email: d.n.krivenko@gmail.com
45
29
  executables: []
46
30
  extensions: []
@@ -62,7 +46,6 @@ files:
62
46
  - lib/pec_calc_client/response.rb
63
47
  - lib/pec_calc_client/take.rb
64
48
  - lib/pec_calc_client/town.rb
65
- - lib/pec_calc_client/version.rb
66
49
  - spec/pec_calc_client/calc_result_spec.rb
67
50
  - spec/pec_calc_client/calc_spec.rb
68
51
  - spec/pec_calc_client/connector_spec.rb
@@ -94,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
77
  version: '0'
95
78
  requirements: []
96
79
  rubyforge_project:
97
- rubygems_version: 2.4.6
80
+ rubygems_version: 2.4.8
98
81
  signing_key:
99
82
  specification_version: 4
100
83
  summary: Gem for PEC transport Company API
@@ -1,9 +0,0 @@
1
- module PecCalcClient #:nodoc:
2
- module VERSION #:nodoc:
3
- MAJOR = 1
4
- MINOR = 0
5
- TINY = 0
6
-
7
- STRING = [MAJOR, MINOR, TINY].join('.')
8
- end
9
- end