Class: Voicearchive::OrderClient

Inherits:
Client
  • Object
show all
Defined in:
lib/voicearchive/order_client.rb

Instance Attribute Summary

Attributes inherited from Client

#api_key, #version

Instance Method Summary collapse

Methods inherited from Client

#call, #initialize, #set_simple_endpoint_default_values

Constructor Details

This class inherits a constructor from Voicearchive::Client

Instance Method Details

#count_orders(options = {}) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/voicearchive/order_client.rb', line 48

def count_orders(options = {})
  options[:count] = true
  response = call('order', options, 'get')

  json = JSON.parse(response.body)
  return json unless json.key?('count')
  json['count'].to_i
end

#get_order(order_id, params = {}) ⇒ Object



11
12
13
14
# File 'lib/voicearchive/order_client.rb', line 11

def get_order(order_id, params = {})
  response = call("order/#{order_id}", params)
  JSON.parse(response.body)
end

#get_order_task(order_id, task_id, params = {}) ⇒ Object



26
27
28
29
# File 'lib/voicearchive/order_client.rb', line 26

def get_order_task(order_id, task_id, params = {})
  response = call("order/#{order_id}/tasks/#{task_id}", params)
  JSON.parse(response.body)
end

#get_order_tasks(order_id, params = {}) ⇒ Object



21
22
23
24
# File 'lib/voicearchive/order_client.rb', line 21

def get_order_tasks(order_id, params = {})
  response = call("order/#{order_id}/tasks", params)
  JSON.parse(response.body)
end

#get_orders(params = {}) ⇒ Object



6
7
8
9
# File 'lib/voicearchive/order_client.rb', line 6

def get_orders(params = {})
  response = call("order", params)
  JSON.parse(response.body)
end

#get_products(order_id) ⇒ Object



57
58
59
60
# File 'lib/voicearchive/order_client.rb', line 57

def get_products(order_id)
  response = call("order/#{order_id}/products")
  JSON.parse(response.body)
end

#get_services(order_id) ⇒ Object



62
63
64
65
# File 'lib/voicearchive/order_client.rb', line 62

def get_services(order_id)
  response = call("order/#{order_id}/services")
  JSON.parse(response.body)
end

#task_with_order(task_id, customer_id = false) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/voicearchive/order_client.rb', line 36

def task_with_order(task_id, customer_id=false)
  task = task_client.get_task(task_id)
  order = get_order(task['orderid'].to_i)
  if customer_id
    if order['customer'].to_i != customer_id.to_i
      raise 'Customer does not match'
    end
  end
  task['order'] = order
  task
end

#update_order(order_id, params = {}) ⇒ Object



16
17
18
19
# File 'lib/voicearchive/order_client.rb', line 16

def update_order(order_id, params = {})
  response = call("order/#{order_id}", params, 'put')
  JSON.parse(response.body)
end

#update_order_task(order_id, task_id, params = {}) ⇒ Object



31
32
33
34
# File 'lib/voicearchive/order_client.rb', line 31

def update_order_task(order_id, task_id, params = {})
  response = call("order/#{order_id}/tasks/#{task_id}", params, 'put')
  JSON.parse(response.body)
end