gman_client 0.0.8 → 0.0.9
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 +3 -1
- data/lib/gman/client.rb +3 -1
- data/lib/gman_client/api/orders.rb +21 -0
- data/lib/gman_client/version.rb +1 -1
- data/lib/gman_client.rb +1 -0
- data/pkg/gman_client-0.0.8.gem +0 -0
- data/spec/lib/client_orders_spec.rb +96 -0
- data/spec/lib/inventory_item_response_spec.rb +3 -3
- data/spec/spec_helper.rb +2 -0
- data/spec/support/gman_adapter.rb +3 -7
- data/spec/vcr_cassettes/inventory_items_by_id.yml +15 -15
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0b2012b4f4a924167b18271efdb13e092788ce7
|
4
|
+
data.tar.gz: 1a3f2f3281bb916cfd1b0a17f96362f197ee1c0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45e41fc768e6a7af96b33839ad40a736395ffeea7197eb1312ccc0a891b72a831cedba12ce20e0eac73600ad796115f51beaf856a6f26def7b6fc94ae6ef1e9c
|
7
|
+
data.tar.gz: 4ec31c7001b660759fd40faeee19346fa46475f987f9da1343d459c8c1ab548259a4413199d4775c0aa824a67cf0780ec0ab2485dd5fbd08db24d64edfe1117f
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
[](https://travis-ci.org/westernmilling/gman_client)
|
1
|
+
[](https://travis-ci.org/westernmilling/gman_client)
|
2
|
+
[](https://codeclimate.com/github/westernmilling/gman_client)
|
2
3
|
[](https://codeclimate.com/github/westernmilling/gman_client/coverage)
|
4
|
+
[](https://gemnasium.com/westernmilling/gman_client)
|
3
5
|
[](https://badge.fury.io/rb/gman_client)
|
4
6
|
|
5
7
|
# GmanClient
|
data/lib/gman/client.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
module Gman
|
2
2
|
class Client
|
3
|
+
include GmanClient::Api::Orders
|
3
4
|
include GmanClient::CommodityMerchandising::Contracts
|
4
5
|
include GmanClient::Utility
|
5
6
|
|
6
7
|
attr_accessor :url, :client_id, :client_secret
|
8
|
+
|
7
9
|
def initialize(options)
|
8
10
|
@url = options[:url]
|
9
11
|
@token_url = "#{url}/oauth/token"
|
@@ -66,7 +68,7 @@ module Gman
|
|
66
68
|
.items_by_id
|
67
69
|
.get(params: { item_id: item_id })
|
68
70
|
end
|
69
|
-
convert_payload(response)
|
71
|
+
convert_payload([response].flatten)
|
70
72
|
end
|
71
73
|
end
|
72
74
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module GmanClient
|
2
|
+
module Api
|
3
|
+
# Orders API
|
4
|
+
module Orders
|
5
|
+
# Retrieve a single order
|
6
|
+
#
|
7
|
+
# @param [String] uuid identifies the order
|
8
|
+
def order(uuid)
|
9
|
+
response = attempt(@retry_attempts) do
|
10
|
+
request
|
11
|
+
.api
|
12
|
+
.v1
|
13
|
+
.orders(uuid)
|
14
|
+
.get
|
15
|
+
end
|
16
|
+
|
17
|
+
response.to_h
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/gman_client/version.rb
CHANGED
data/lib/gman_client.rb
CHANGED
Binary file
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'webmock'
|
3
|
+
|
4
|
+
RSpec.describe Gman::Client do
|
5
|
+
include WebMock::API
|
6
|
+
|
7
|
+
let(:client) do
|
8
|
+
Gman::Client.new(
|
9
|
+
url: stubbed_url,
|
10
|
+
client_id: 'client_id',
|
11
|
+
client_secret: 'client_secret'
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:orders_hash) do
|
16
|
+
[
|
17
|
+
{
|
18
|
+
order_number: 000001,
|
19
|
+
order_key: 001,
|
20
|
+
quantity_shipped: 5.0,
|
21
|
+
ship_date: '2000-01-01',
|
22
|
+
warehouse_id: 1,
|
23
|
+
uuid: '949085E3-6FC3-4240-BC86-2940D543DB35'
|
24
|
+
},
|
25
|
+
{
|
26
|
+
order_number: 000002,
|
27
|
+
order_key: 002,
|
28
|
+
quantity_shipped: 5.0,
|
29
|
+
ship_date: '2000-01-01',
|
30
|
+
warehouse_id: 1,
|
31
|
+
uuid: '1AE4C0FD-B1B3-4381-ACF2-62025A6F0D8C'
|
32
|
+
}
|
33
|
+
]
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#order' do
|
37
|
+
let(:described) { client.order(order_hash[:uuid]) }
|
38
|
+
let(:access_token) { SecureRandom.uuid }
|
39
|
+
let(:order_hash) { orders_hash.sample }
|
40
|
+
let(:stubbed_url) { 'http://test.local' }
|
41
|
+
|
42
|
+
subject do
|
43
|
+
described
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'when the authorization fails' do
|
47
|
+
before do
|
48
|
+
stub_request(:post, "#{stubbed_url}/oauth/token")
|
49
|
+
.to_return(response)
|
50
|
+
end
|
51
|
+
|
52
|
+
let(:response) do
|
53
|
+
{
|
54
|
+
body: {
|
55
|
+
error: 'invalid_client',
|
56
|
+
error_description: '...'
|
57
|
+
}.to_json,
|
58
|
+
status: 401
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should raise RestClient::Unauthorized' do
|
63
|
+
expect { subject }.to raise_error(RestClient::Unauthorized)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'when the order is found' do
|
68
|
+
before do
|
69
|
+
stub_request(:post, "#{stubbed_url}/oauth/token")
|
70
|
+
.to_return(
|
71
|
+
body: { access_token: access_token }.to_json, status: 200
|
72
|
+
)
|
73
|
+
stub_request(
|
74
|
+
:get, "#{stubbed_url}/api/v1/orders/#{order_hash[:uuid]}.json"
|
75
|
+
)
|
76
|
+
.to_return(body: order_hash.to_json, status: 200)
|
77
|
+
end
|
78
|
+
let(:access_token) { SecureRandom.uuid }
|
79
|
+
|
80
|
+
it 'should respond with a Hash' do
|
81
|
+
expect(subject).to be_kind_of(Hash)
|
82
|
+
end
|
83
|
+
|
84
|
+
describe 'response' do
|
85
|
+
its([:order_number]) { is_expected.to eq order_hash[:order_number] }
|
86
|
+
its([:order_key]) { is_expected.to eq order_hash[:order_key] }
|
87
|
+
its([:quantity_shipped]) do
|
88
|
+
is_expected.to eq order_hash[:quantity_shipped]
|
89
|
+
end
|
90
|
+
its([:ship_date]) { is_expected.to eq order_hash[:ship_date] }
|
91
|
+
its([:warehouse_id]) { is_expected.to eq order_hash[:warehouse_id] }
|
92
|
+
its([:uuid]) { is_expected.to eq order_hash[:uuid] }
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -60,7 +60,7 @@ RSpec.describe GmanClient do
|
|
60
60
|
describe '.inventory_items_by_id' do
|
61
61
|
let(:response) do
|
62
62
|
VCR.use_cassette('inventory_items_by_id') do
|
63
|
-
gman_adapter.inventory_items_by_id(
|
63
|
+
gman_adapter.inventory_items_by_id('80')
|
64
64
|
end
|
65
65
|
end
|
66
66
|
subject(:client_response) { response }
|
@@ -80,8 +80,8 @@ RSpec.describe GmanClient do
|
|
80
80
|
|
81
81
|
it { is_expected.to have_key(:item_id) }
|
82
82
|
it { is_expected.to have_key(:in_item_description) }
|
83
|
-
it { is_expected.to have_value(
|
84
|
-
it { is_expected.to have_value('
|
83
|
+
it { is_expected.to have_value('80') }
|
84
|
+
it { is_expected.to have_value('Corn Gluten Feed') }
|
85
85
|
end
|
86
86
|
end
|
87
87
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,13 +1,9 @@
|
|
1
1
|
def gman_adapter
|
2
|
-
url = '
|
3
|
-
|
4
|
-
|
5
|
-
client_id = 'd137a94543da86e52214d3ed86b015f9299ad2fc66681637600afad814cd7d2b'
|
6
|
-
client_secret = 'f444a467ddbbaed52297d61a3edc5efd93e9292fc542058786aa13fa366865a3'
|
7
|
-
# rubocop:enable Metrics/LineLength
|
2
|
+
url = ENV['GMAN_SERVICES_URL']
|
3
|
+
client_id = ENV['GMAN_SERVICES_CLIENT_ID']
|
4
|
+
client_secret = ENV['GMAN_SERVICES_CLIENT_SECRET']
|
8
5
|
|
9
6
|
Gman::Client.new(url: url,
|
10
|
-
token_url: token_url,
|
11
7
|
client_id: client_id,
|
12
8
|
client_secret: client_secret
|
13
9
|
)
|
@@ -2,10 +2,10 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: post
|
5
|
-
uri:
|
5
|
+
uri: "<GMAN_SERVICES_URL>/oauth/token"
|
6
6
|
body:
|
7
7
|
encoding: US-ASCII
|
8
|
-
string: grant_type=client_credentials&client_id
|
8
|
+
string: grant_type=client_credentials&client_id=<GMAN_SERVICES_CLIENT_ID>&client_secret=<GMAN_SERVICES_CLIENT_SECRET>
|
9
9
|
headers:
|
10
10
|
Accept:
|
11
11
|
- "*/*; q=0.5, application/xml"
|
@@ -35,27 +35,27 @@ http_interactions:
|
|
35
35
|
Content-Type:
|
36
36
|
- application/json; charset=utf-8
|
37
37
|
Etag:
|
38
|
-
- '"
|
38
|
+
- '"062d093ffd884c929884c8bec05d8b69"'
|
39
39
|
X-Request-Id:
|
40
|
-
-
|
40
|
+
- 2683b8b9-00a4-4708-99d7-ab8cd8630160
|
41
41
|
X-Runtime:
|
42
|
-
- '0.
|
42
|
+
- '0.046000'
|
43
43
|
Transfer-Encoding:
|
44
44
|
- chunked
|
45
45
|
body:
|
46
46
|
encoding: UTF-8
|
47
|
-
string: '{"access_token":"
|
47
|
+
string: '{"access_token":"29a72bedd04f3f98a24b9e6de74a680b649d21f2c746c5277f0c546c49f92caf","token_type":"bearer","created_at":1471454476}'
|
48
48
|
http_version:
|
49
|
-
recorded_at:
|
49
|
+
recorded_at: Wed, 17 Aug 2016 17:21:16 GMT
|
50
50
|
- request:
|
51
51
|
method: get
|
52
|
-
uri:
|
52
|
+
uri: "<GMAN_SERVICES_URL>/api/v1/inventory/items_by_id.json?item_id=80"
|
53
53
|
body:
|
54
54
|
encoding: US-ASCII
|
55
55
|
string: ''
|
56
56
|
headers:
|
57
57
|
Authorization:
|
58
|
-
- Bearer
|
58
|
+
- Bearer 29a72bedd04f3f98a24b9e6de74a680b649d21f2c746c5277f0c546c49f92caf
|
59
59
|
response:
|
60
60
|
status:
|
61
61
|
code: 200
|
@@ -70,18 +70,18 @@ http_interactions:
|
|
70
70
|
Content-Type:
|
71
71
|
- application/json; charset=utf-8
|
72
72
|
Etag:
|
73
|
-
- '"
|
73
|
+
- '"7c5fe23f612a40f341c1836661852316"'
|
74
74
|
Cache-Control:
|
75
75
|
- max-age=0, private, must-revalidate
|
76
76
|
X-Request-Id:
|
77
|
-
-
|
77
|
+
- 918da3e4-68ea-480f-8c2a-70db832bfd06
|
78
78
|
X-Runtime:
|
79
|
-
- '0.
|
79
|
+
- '0.382000'
|
80
80
|
Transfer-Encoding:
|
81
81
|
- chunked
|
82
82
|
body:
|
83
83
|
encoding: UTF-8
|
84
|
-
string: '
|
84
|
+
string: '{"item_id":"80","in_item_description":"Corn Gluten Feed"}'
|
85
85
|
http_version:
|
86
|
-
recorded_at:
|
87
|
-
recorded_with: VCR
|
86
|
+
recorded_at: Wed, 17 Aug 2016 17:21:16 GMT
|
87
|
+
recorded_with: VCR 3.0.1
|
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.0.
|
4
|
+
version: 0.0.9
|
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
|
+
date: 2016-08-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: vcr
|
@@ -171,6 +171,7 @@ files:
|
|
171
171
|
- gman_client.gemspec
|
172
172
|
- lib/gman/client.rb
|
173
173
|
- lib/gman_client.rb
|
174
|
+
- lib/gman_client/api/orders.rb
|
174
175
|
- lib/gman_client/commodity_merchandising/contracts.rb
|
175
176
|
- lib/gman_client/inventory/items.rb
|
176
177
|
- lib/gman_client/utility.rb
|
@@ -181,7 +182,9 @@ files:
|
|
181
182
|
- pkg/gman_client-0.0.4.gem
|
182
183
|
- pkg/gman_client-0.0.5.gem
|
183
184
|
- pkg/gman_client-0.0.7.gem
|
185
|
+
- pkg/gman_client-0.0.8.gem
|
184
186
|
- spec/lib/client_contracts_spec.rb
|
187
|
+
- spec/lib/client_orders_spec.rb
|
185
188
|
- spec/lib/driver_commission_history_response_spec.rb
|
186
189
|
- spec/lib/driver_response_spec.rb
|
187
190
|
- spec/lib/inventory_item_response_spec.rb
|
@@ -222,6 +225,7 @@ specification_version: 4
|
|
222
225
|
summary: Grossman API Client for Ruby
|
223
226
|
test_files:
|
224
227
|
- spec/lib/client_contracts_spec.rb
|
228
|
+
- spec/lib/client_orders_spec.rb
|
225
229
|
- spec/lib/driver_commission_history_response_spec.rb
|
226
230
|
- spec/lib/driver_response_spec.rb
|
227
231
|
- spec/lib/inventory_item_response_spec.rb
|