Module: OreillyApi
- Defined in:
- lib/oreilly_api.rb,
lib/oreilly_api/version.rb
Overview
OreillyApi
Constant Summary collapse
- TOKEN =
'oreilly_api_token'
- VERSION =
"1.0.3"
Class Attribute Summary collapse
-
.client_id ⇒ Object
Returns the value of attribute client_id.
-
.client_secret ⇒ Object
Returns the value of attribute client_secret.
-
.device_id ⇒ Object
Returns the value of attribute device_id.
-
.domain ⇒ Object
Returns the value of attribute domain.
-
.identity ⇒ Object
Returns the value of attribute identity.
-
.version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
- .config {|_self| ... } ⇒ Object
- .fetch_quote(items, account_number) ⇒ Object
- .invoice(order_number) ⇒ Object
- .payload_id(account_number) ⇒ Object
- .place_order(po_number, account_number, vehicles_with_items, stop_order: false) ⇒ Object
- .redis_utility=(redis_config) ⇒ Object
- .sample_request ⇒ Object
- .test_place_order ⇒ Object
Class Attribute Details
.client_id ⇒ Object
Returns the value of attribute client_id.
17 18 19 |
# File 'lib/oreilly_api.rb', line 17 def client_id @client_id end |
.client_secret ⇒ Object
Returns the value of attribute client_secret.
17 18 19 |
# File 'lib/oreilly_api.rb', line 17 def client_secret @client_secret end |
.device_id ⇒ Object
Returns the value of attribute device_id.
17 18 19 |
# File 'lib/oreilly_api.rb', line 17 def device_id @device_id end |
.domain ⇒ Object
Returns the value of attribute domain.
17 18 19 |
# File 'lib/oreilly_api.rb', line 17 def domain @domain end |
.identity ⇒ Object
Returns the value of attribute identity.
17 18 19 |
# File 'lib/oreilly_api.rb', line 17 def identity @identity end |
.version ⇒ Object
Returns the value of attribute version.
17 18 19 |
# File 'lib/oreilly_api.rb', line 17 def version @version end |
Class Method Details
.config {|_self| ... } ⇒ Object
19 20 21 |
# File 'lib/oreilly_api.rb', line 19 def config yield self end |
.fetch_quote(items, account_number) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/oreilly_api.rb', line 52 def fetch_quote(items, account_number) payload = { 'accountNumber' => account_number, 'header' => { 'identity' => OreillyApi.identity, 'payloadId' => OreillyApi.payload_id(account_number), 'timestamp' => Time.now.strftime("%Y-%m-%d %H:%M:%S") }, 'items' => items }.to_json url = "#{base_url}/quote/fetchQuote" token = fetch_token res = RestClient.post(url, payload, get_header(token)) sample_request = JSON.parse(res) [res.code, sample_request] end |
.invoice(order_number) ⇒ Object
85 86 87 88 89 90 91 92 93 |
# File 'lib/oreilly_api.rb', line 85 def invoice(order_number) token = fetch_token params = "identity=#{OreillyApi.identity}&orderDetails=true&orderNumber=#{order_number}" url = "#{base_url}/order/invoice?#{params}" res = RestClient.get(url, get_header(token)) invoice_info = JSON.parse(res) [res.code, invoice_info] end |
.payload_id(account_number) ⇒ Object
27 28 29 |
# File 'lib/oreilly_api.rb', line 27 def payload_id(account_number) "YM#{account_number}#{DateTime.now.strftime('%Y%m%d%l%S%M')}" end |
.place_order(po_number, account_number, vehicles_with_items, stop_order: false) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/oreilly_api.rb', line 31 def place_order(po_number, account_number, vehicles_with_items, stop_order: false) payload = { 'header' => { 'identity' => OreillyApi.identity, 'payloadId' => OreillyApi.payload_id(account_number), 'timestamp' => Time.now.strftime("%Y-%m-%d %H:%M:%S") }, 'orderHeader' => { 'poNumber' => po_number, 'accountNumber' => account_number, 'comments' => "comments" }, 'vehicles' => vehicles_with_items }.to_json url = "#{base_url}/order/placeOrder?stopOrder=#{stop_order}" token = fetch_token res = RestClient.post(url, payload, get_header(token)) place_order_response = JSON.parse(res) [res.code, place_order_response] end |
.redis_utility=(redis_config) ⇒ Object
23 24 25 |
# File 'lib/oreilly_api.rb', line 23 def redis_utility=(redis_config) RedisUtility.redis_config = redis_config end |
.sample_request ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/oreilly_api.rb', line 69 def sample_request token = fetch_token url = "#{base_url}/quote/sampleRequest?detailsRequired=false" res = RestClient.get(url, get_header(token)) sample_request = JSON.parse(res) [res.code, sample_request] end |
.test_place_order ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/oreilly_api.rb', line 77 def test_place_order token = fetch_token url = "#{base_url}/order/testPlaceOrder?detailsRequired=false" res = RestClient.get(url, get_header(token)) place_order_response = JSON.parse(res) [res.code, place_order_response] end |