gman_client 0.2.1 → 0.3.0

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
  SHA1:
3
- metadata.gz: 0d92c041243c9292d3a28fb93757b7cc1fbc7b3c
4
- data.tar.gz: 5cd96aeae1636af33b2f3861973e22a7e831474a
3
+ metadata.gz: cea6b098f8e201f18a6621a1b3bee3ccb28296a4
4
+ data.tar.gz: 1236b436d46d5bdc9135a80337502c73acbd6cab
5
5
  SHA512:
6
- metadata.gz: 3385ae7287f790b40dca3c132c197b6e1aedcf919c8c13d85e3bfabf12bb8829c069ceaaf25d2fa644ece243d2b569b3b6dca7d62b6afebcc8249680cfa8880c
7
- data.tar.gz: ccc90ec73835c249501a98b4dc866f58be56302b22e69771875ca19f5cbd25bf65c5538686edb07681981c7ac523cfa478ef9fe6ac4c619da58418a86f19248c
6
+ metadata.gz: 2a6258aa3633d713e506d0b86cde2da540f4b669f2a2a52871a81ceceb911918dca6444069c2654c1ce0303295e081561b310cff52b2979f777ec8c04c34bcf3
7
+ data.tar.gz: bd883a95564481acd6de1ebf074596b161bb39a169fe0ce835144d1e1e5a2419f2deeac3c5a33791bc07e7505fe4c88ac47f1f74df6d94b179c369285f17fb95
data/lib/gman/client.rb CHANGED
@@ -2,6 +2,7 @@ module Gman
2
2
  class Client
3
3
  include GmanClient::Api::CustomerContracts
4
4
  include GmanClient::Api::Orders
5
+ include GmanClient::Api::PickUpOrders
5
6
  include GmanClient::Api::HealthCheck
6
7
  include GmanClient::CommodityMerchandising::Contracts
7
8
  include GmanClient::Utility
@@ -6,11 +6,7 @@ module GmanClient
6
6
  # @param [Hash] parameters to filter the orders
7
7
  def customer_contracts(filter_params)
8
8
  response = attempt(@retry_attempts) do
9
- request
10
- .api
11
- .v1
12
- .customer_contracts
13
- .get(params: { q: filter_params })
9
+ get(:customer_contracts, q: filter_params)
14
10
  end
15
11
 
16
12
  response.map(&:to_h)
@@ -0,0 +1,16 @@
1
+ module GmanClient
2
+ module Api
3
+ module PickUpOrders
4
+ # Retrieves pick up orders
5
+ #
6
+ # @param [Hash] parameters to filter the pick up orders
7
+ def pick_up_orders(filter_params)
8
+ response = attempt(@retry_attempts) do
9
+ get(:pick_up_orders, q: filter_params)
10
+ end
11
+
12
+ response.map(&:to_h)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,5 +1,13 @@
1
1
  module GmanClient
2
2
  module Utility
3
+ def get(resource, params)
4
+ request
5
+ .api
6
+ .v1
7
+ .send(resource)
8
+ .get(params: params)
9
+ end
10
+
3
11
  def request
4
12
  Blanket.wrap(
5
13
  @url,
@@ -1,3 +1,3 @@
1
1
  module GmanClient
2
- VERSION = '0.2.1'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
data/lib/gman_client.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'gman_client/api/customer_contracts'
2
+ require 'gman_client/api/pick_up_orders'
2
3
  require 'gman_client/api/orders'
3
4
  require 'gman_client/api/health_check'
4
5
  require 'gman_client/commodity_merchandising/contracts'
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
- require 'webmock'
3
2
 
4
3
  RSpec.describe Gman::Client do
5
- include WebMock::API
4
+ before(:all) { VCR.turn_off! }
5
+ after(:all) { VCR.turn_on! }
6
6
 
7
7
  let(:client) do
8
8
  Gman::Client.new(
@@ -0,0 +1,104 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Gman::Client do
4
+ before(:all) { VCR.turn_off! }
5
+ after(:all) { VCR.turn_on! }
6
+
7
+ let(:access_token) { SecureRandom.uuid }
8
+ let(:stubbed_url) { 'http://test.local' }
9
+
10
+ include_context 'new grossman client' do
11
+ let(:url) { stubbed_url }
12
+ let(:client_id) { SecureRandom.uuid }
13
+ let(:client_secret) { SecureRandom.uuid }
14
+ end
15
+
16
+ describe '#pick_up_orders' do
17
+ subject do
18
+ client.pick_up_orders(params)
19
+ end
20
+
21
+ before do
22
+ stub_request(:post, "#{stubbed_url}/oauth/token")
23
+ .to_return(
24
+ body: { access_token: access_token }.to_json, status: 200
25
+ )
26
+
27
+ stub_request(
28
+ :get, "#{stubbed_url}/api/v1/pick_up_orders.json?#{query_string}"
29
+ )
30
+ .to_return(body: pick_up_orders_hash.to_json, status: 200)
31
+ end
32
+
33
+ let(:query_string) do
34
+ params.map { |k, v| "q[#{k}]=#{v}" }.join('&')
35
+ end
36
+
37
+ context 'when there are results' do
38
+ let(:params) do
39
+ {
40
+ contract_commodity_id_eq: 1010
41
+ }
42
+ end
43
+ let(:pick_up_orders_hash) do
44
+ [
45
+ {
46
+ contract_id: '10000100',
47
+ contract_location_id: 1,
48
+ commodity_id: 1070,
49
+ item_id: '1234',
50
+ load_number: 1,
51
+ origin: 'HTV',
52
+ origin_state: 'CA',
53
+ origin_weight_certificate: 0,
54
+ origin_tare_weight: 0,
55
+ origin_gross_weight: 0,
56
+ origin_net_weight: 0,
57
+ pickup_type: 'Contract',
58
+ purchase_customer_id: '00000100',
59
+ release_prefix: 'TEST',
60
+ release_load_number: 1,
61
+ release_number: 'TEST 0001',
62
+ ship_date: '2016-12-28',
63
+ status: 'Used'
64
+ },
65
+ {
66
+ contract_id: '10000100',
67
+ contract_location_id: 1,
68
+ commodity_id: 1070,
69
+ item_id: '1234',
70
+ load_number: 2,
71
+ origin: 'HTV',
72
+ origin_state: 'CA',
73
+ origin_weight_certificate: 0,
74
+ origin_tare_weight: 0,
75
+ origin_gross_weight: 0,
76
+ origin_net_weight: 0,
77
+ pickup_type: 'Contract',
78
+ purchase_customer_id: '00000100',
79
+ release_prefix: 'TEST',
80
+ release_load_number: 2,
81
+ release_number: 'TEST 0002',
82
+ ship_date: '2016-12-28',
83
+ status: 'Open'
84
+ }
85
+ ]
86
+ end
87
+
88
+ it 'should respond with a collection of hashs' do
89
+ expect(subject).to all be_kind_of(Hash)
90
+ end
91
+
92
+ it 'should contain the pick up orders' do
93
+ expect(subject).to eq(pick_up_orders_hash)
94
+ end
95
+ end
96
+
97
+ context 'when there are no results' do
98
+ let(:params) { {} }
99
+ let(:pick_up_orders_hash) { [] }
100
+
101
+ it { is_expected.to be_empty }
102
+ end
103
+ end
104
+ end
data/spec/spec_helper.rb CHANGED
@@ -2,8 +2,8 @@ require 'rspec/its'
2
2
  require 'spec_helper'
3
3
  require 'gman_client'
4
4
  require 'httparty'
5
- require 'webmock'
6
5
  require 'securerandom'
6
+ require 'webmock/rspec'
7
7
 
8
8
  Dir[File.join(GmanClient.root, 'spec/support/**/*.rb')].each { |f| require f }
9
9
 
@@ -11,3 +11,13 @@ RSpec.shared_context 'grossman client' do
11
11
  )
12
12
  end
13
13
  end
14
+
15
+ RSpec.shared_context 'new grossman client' do
16
+ let(:client) do
17
+ Gman::Client.new(
18
+ url: url,
19
+ client_id: client_id,
20
+ client_secret: client_secret
21
+ )
22
+ end
23
+ end
data/spec/support/vcr.rb CHANGED
@@ -1,9 +1,6 @@
1
1
  require 'vcr'
2
2
 
3
- real_requests = ENV['VCR_ALLOW_ACTUAL_REQUESTS']
4
-
5
3
  VCR.configure do |c|
6
- c.allow_http_connections_when_no_cassette = true if real_requests
7
4
  c.cassette_library_dir = 'spec/vcr_cassettes'
8
5
  c.configure_rspec_metadata!
9
6
  c.default_cassette_options = { record: :new_episodes }
@@ -17,9 +14,3 @@ VCR.configure do |c|
17
14
  c.hook_into :webmock
18
15
  c.ignore_hosts 'codeclimate.com'
19
16
  end
20
-
21
- RSpec.configure do |config|
22
- config.before(:each) do
23
- VCR.eject_cassette
24
- end if real_requests
25
- end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gman_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - MichaelAChrisco
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-12-20 00:00:00.000000000 Z
12
+ date: 2017-01-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: vcr
@@ -175,6 +175,7 @@ files:
175
175
  - lib/gman_client/api/customer_contracts.rb
176
176
  - lib/gman_client/api/health_check.rb
177
177
  - lib/gman_client/api/orders.rb
178
+ - lib/gman_client/api/pick_up_orders.rb
178
179
  - lib/gman_client/commodity_merchandising/contracts.rb
179
180
  - lib/gman_client/inventory/items.rb
180
181
  - lib/gman_client/utility.rb
@@ -183,6 +184,7 @@ files:
183
184
  - spec/lib/client/health_check_spec.rb
184
185
  - spec/lib/client/order_spec.rb
185
186
  - spec/lib/client/orders_spec.rb
187
+ - spec/lib/client/pick_up_orders_spec.rb
186
188
  - spec/lib/client_contracts_spec.rb
187
189
  - spec/lib/driver_commission_history_response_spec.rb
188
190
  - spec/lib/driver_response_spec.rb
@@ -227,6 +229,7 @@ test_files:
227
229
  - spec/lib/client/health_check_spec.rb
228
230
  - spec/lib/client/order_spec.rb
229
231
  - spec/lib/client/orders_spec.rb
232
+ - spec/lib/client/pick_up_orders_spec.rb
230
233
  - spec/lib/client_contracts_spec.rb
231
234
  - spec/lib/driver_commission_history_response_spec.rb
232
235
  - spec/lib/driver_response_spec.rb