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

Class Method Summary collapse

Class Attribute Details

.client_idObject

Returns the value of attribute client_id.



17
18
19
# File 'lib/oreilly_api.rb', line 17

def client_id
  @client_id
end

.client_secretObject

Returns the value of attribute client_secret.



17
18
19
# File 'lib/oreilly_api.rb', line 17

def client_secret
  @client_secret
end

.device_idObject

Returns the value of attribute device_id.



17
18
19
# File 'lib/oreilly_api.rb', line 17

def device_id
  @device_id
end

.domainObject

Returns the value of attribute domain.



17
18
19
# File 'lib/oreilly_api.rb', line 17

def domain
  @domain
end

.identityObject

Returns the value of attribute identity.



17
18
19
# File 'lib/oreilly_api.rb', line 17

def identity
  @identity
end

.versionObject

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

Yields:

  • (_self)

Yield Parameters:

  • _self (OreillyApi)

    the object that the method was called on



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, )
  payload = {
    'accountNumber' => ,
    'header' => {
      'identity' => OreillyApi.identity,
      'payloadId' => OreillyApi.payload_id(),
      '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()
  "YM#{}#{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, , vehicles_with_items, stop_order: false)
  payload = {
    'header' => {
      'identity' => OreillyApi.identity,
      'payloadId' => OreillyApi.payload_id(),
      'timestamp' => Time.now.strftime("%Y-%m-%d %H:%M:%S")
    },
    'orderHeader' => {
      'poNumber' => po_number,
      'accountNumber' => ,
      '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_requestObject



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_orderObject



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