Class: Customers

Inherits:
Object
  • Object
show all
Defined in:
lib/Customers.rb

Defined Under Namespace

Classes: Customer

Class Method Summary collapse

Class Method Details

.create(options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/Customers.rb', line 25

def Customers.create(options={})
  if (options.length == 0)
    raise InvalidArguementError.new()
  end
  method = 'POST'
  url = '/customers'
  response = request(method,url,options)
  customers = Customer.new(response.body)
  return customers
end

.delete(options = {}) ⇒ Object



88
89
90
# File 'lib/Customers.rb', line 88

def Customers.delete(options={})
  raise "ERROR: Not Implemented"
end

.get(options = {}) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/Customers.rb', line 62

def Customers.get(options={})
  customer_id = get_arg(options,:customer_id)
  if customer_id == NIL
    raise InvalidArguementError.new("ERROR: `customer_id` is a required parameter for Customers.get().")
  end

  method = 'GET'
  url = "/customers/#{customer_id}"
  response = request(method,url,options)
  customers = Customer.new(response.body)
  return customers
end

.list(options = {}) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/Customers.rb', line 36

def Customers.list(options={})
  method = 'GET'
  url = '/customers'
  offset = get_arg(options,:offset)
  count = get_arg(options,:count)

  if count == NIL and offset == NIL
        puts "count & offset can be passed if required.\n"
  end

  response = request(method,url,options).body
  customer_list = Array(response['list'])
  customers = []
  customer_list.each  do |customerData|
    customer = Customer.new(customerData)
    customers.push(customer)
  end
  customer_response = {
      'count' => response['count'],
      'offset' => response['offset'],
      'total' => response['total'],
      'list' => customers
  }
  return customer_response
end

.update(options = {}) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/Customers.rb', line 75

def Customers.update(options={})
  customer_id = get_arg(options,:customer_id)
  if customer_id == NIL
    raise InvalidArguementError.new("ERROR: `customer_id` is a required parameter for Customers.update().")
  end

  method = 'POST'
  url = "/customers/#{customer_id}"
  response = request(method,url,options)
  customers = Customer.new(response.body)
  return customers
end