Skip to content

Commit

Permalink
Account number as input (#5)
Browse files Browse the repository at this point in the history
* Updating to make account number dynamic
  • Loading branch information
TruptiHosmani authored Apr 27, 2023
1 parent 88b91bc commit 4b71661
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 22 deletions.
10 changes: 5 additions & 5 deletions .rspec_status
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
example_id | status | run_time |
------------------------------- | ------- | --------------- |
./spec/oreilly_api_spec.rb[1:1] | passed | 0.00312 seconds |
./spec/oreilly_api_spec.rb[1:2] | passed | 0.03616 seconds |
./spec/oreilly_api_spec.rb[1:3] | passed | 0.01192 seconds |
./spec/oreilly_api_spec.rb[1:1] | passed | 0.00108 seconds |
./spec/oreilly_api_spec.rb[1:2] | passed | 0.0281 seconds |
./spec/oreilly_api_spec.rb[1:3] | passed | 0.00814 seconds |
./spec/oreilly_api_spec.rb[1:4] | pending | 0.00002 seconds |
./spec/oreilly_api_spec.rb[1:5] | passed | 0.01359 seconds |
./spec/oreilly_api_spec.rb[1:6] | passed | 0.01565 seconds |
./spec/oreilly_api_spec.rb[1:5] | passed | 0.01212 seconds |
./spec/oreilly_api_spec.rb[1:6] | passed | 0.01094 seconds |
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
oreilly_api (1.0.2)
oreilly_api (1.0.3)
byebug
redis
redis_utility
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ OreillyApi.config do |c|
c.client_secret = 'client_sercet'
c.identity = 'IDENTITY'
c.version = 'sms-external-partner/services'
c.account_number = '123456'
end
```

Expand Down
21 changes: 10 additions & 11 deletions lib/oreilly_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
module OreillyApi
TOKEN = 'oreilly_api_token'
class << self
attr_accessor :domain, :version, :client_id, :client_secret, :identity, :account_number, :device_id
attr_accessor :domain, :version, :client_id, :client_secret, :identity, :device_id

def config
yield self
Expand All @@ -24,22 +24,21 @@ def redis_utility=(redis_config)
RedisUtility.redis_config = redis_config
end

def payload_id
"YM#{OreillyApi.account_number}#{DateTime.now.strftime('%Y%m%d%l%S%M')}}"
def payload_id(account_number)
"YM#{account_number}#{DateTime.now.strftime('%Y%m%d%l%S%M')}"
end

def place_order(po_number, customer_location_id, vehicles_with_items, stop_order: false)
def place_order(po_number, account_number, vehicles_with_items, stop_order: false)
payload = {
'header' => {
'identity' => OreillyApi.identity,
'payloadId' => OreillyApi.payload_id,
'payloadId' => OreillyApi.payload_id(account_number),
'timestamp' => Time.now.strftime("%Y-%m-%d %H:%M:%S")
},
'orderHeader' => {
'poNumber' => po_number,
'customerLocationId': customer_location_id || '',
'accountNumber' => OreillyApi.account_number,
'comments' => "test"
'accountNumber' => account_number,
'comments' => "comments"
},
'vehicles' => vehicles_with_items
}.to_json
Expand All @@ -50,12 +49,12 @@ def place_order(po_number, customer_location_id, vehicles_with_items, stop_order
[res.code, place_order_response]
end

def fetch_quote(items)
def fetch_quote(items, account_number)
payload = {
'accountNumber' => OreillyApi.account_number,
'accountNumber' => account_number,
'header' => {
'identity' => OreillyApi.identity,
'payloadId' => OreillyApi.payload_id,
'payloadId' => OreillyApi.payload_id(account_number),
'timestamp' => Time.now.strftime("%Y-%m-%d %H:%M:%S")
},
'items' => items
Expand Down
2 changes: 1 addition & 1 deletion lib/oreilly_api/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module OreillyApi
VERSION = "1.0.2"
VERSION = "1.0.3"
end
6 changes: 3 additions & 3 deletions spec/oreilly_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
RSpec.describe OreillyApi do
let(:orielly_api) { OreillyApi }
let(:token) { '9df2c226-9353-41ed-927e-73dc2df11304' }
let(:account_number) { '123456' }
let(:token_response) do
{ "access_token" => token, "token_type" => "bearer", "expires_in" => 119, "scope" => "sms_external", "active" => true,
"authorities" => %w[ROLE_SMS_PLACE_ORDER ROLE_SMS_READ_QUOTE] }.to_json
Expand Down Expand Up @@ -38,7 +39,6 @@
c.client_secret = 'client_sercet'
c.identity = 'IDENTITY'
c.version = 'sms-external-partner/services'
c.account_number = '123456'
c.redis_utility = { host: "127.0.0.1", timeout: 60, db: 1, password: nil }
c.device_id = 'test'
end
Expand Down Expand Up @@ -89,7 +89,7 @@
'quantity' => 1,
'kitId' => 0
}]
res_code, response = orielly_api.fetch_quote(items)
res_code, response = orielly_api.fetch_quote(items, account_number)
expect(res_code).to eq(200)
expect(response.to_json).to eq(sample_quote)
end
Expand Down Expand Up @@ -117,7 +117,7 @@
]
}
]
res_code, response = orielly_api.place_order("po_number", "location_id", vehicles_with_items)
res_code, response = orielly_api.place_order("po_number", account_number, vehicles_with_items)
expect(res_code).to eq(200)
expect(response.to_json).to eq(sample_order)
end
Expand Down

0 comments on commit 4b71661

Please sign in to comment.