Class: Jet::Client::Orders

Inherits:
Object
  • Object
show all
Defined in:
lib/jet/client/orders.rb

Constant Summary collapse

STATUSES =
{
  created: 'created',
  ready: 'ready',
  acknowledged: 'acknowledged',
  inprogress: 'inprogress',
  complete: 'complete',
}

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Orders

Returns a new instance of Orders.



14
15
16
# File 'lib/jet/client/orders.rb', line 14

def initialize(client)
  @client = client
end

Instance Method Details

#acknowledge_order(order_id, body = {}) ⇒ Object



37
38
39
40
41
# File 'lib/jet/client/orders.rb', line 37

def acknowledge_order(order_id, body = {})
  headers = @client.token
  response = RestClient.put("#{Jet::Client::API_URL}/orders/#{order_id}/acknowledge", body.to_json, headers)
  JSON.parse(response.body) if response.code == 200
end

#get_directed_cancelObject



49
50
51
52
53
# File 'lib/jet/client/orders.rb', line 49

def get_directed_cancel
  headers = @client.token
  response = RestClient.get("#{Jet::Client::API_URL}/orders/directedCancel", headers)
  JSON.parse(response.body) if response.code == 200
end

#get_order(order_url) ⇒ Object



25
26
27
28
29
# File 'lib/jet/client/orders.rb', line 25

def get_order(order_url)
  headers = @client.token
  response = RestClient.get("#{Jet::Client::API_URL}#{order_url}", headers)
  JSON.parse(response.body) if response.code == 200
end

#get_order_by_id(order_id) ⇒ Object



31
32
33
34
35
# File 'lib/jet/client/orders.rb', line 31

def get_order_by_id(order_id)
  headers = @client.token
  response = RestClient.get("#{Jet::Client::API_URL}/orders/withoutShipmentDetail/#{order_id}", headers)
  JSON.parse(response.body) if response.code == 200
end

#get_orders(status = :ready) ⇒ Object



18
19
20
21
22
23
# File 'lib/jet/client/orders.rb', line 18

def get_orders(status = :ready)
  headers = @client.token
  query_status = STATUSES[status]
  response = RestClient.get("#{Jet::Client::API_URL}/orders/#{query_status}", headers)
  JSON.parse(response.body) if response.code == 200
end

#ship_order(order_id, body = {}) ⇒ Object



43
44
45
46
47
# File 'lib/jet/client/orders.rb', line 43

def ship_order(order_id, body = {})
  headers = @client.token
  response = RestClient.put("#{Jet::Client::API_URL}/orders/#{order_id}/shipped", body.to_json, headers)
  JSON.parse(response.body) if response.code == 200
end