Class: CheddarGetter::Request
- Inherits:
-
Object
- Object
- CheddarGetter::Request
- Includes:
- HTTParty
- Defined in:
- lib/cheddargetter-client.rb
Instance Method Summary collapse
- #addItemQuantity(code, id = nil, data) ⇒ Object
- #cancelSubscription(code, id = nil) ⇒ Object
- #customer(code, id = nil) ⇒ Object
- #customers(filters = nil) ⇒ Object
- #deleteCustomer(code, id = nil) ⇒ Object
- #deletePlan(code, id) ⇒ Object
- #editCustomer(code, id = nil, data) ⇒ Object
- #editPlan(code, id = nil, data) ⇒ Object
- #editSubscription(code, id = nil, data) ⇒ Object
-
#initialize(url, username, password, productCode = nil) ⇒ Request
constructor
A new instance of Request.
- #newCustomer(data) ⇒ Object
- #newPlan(data) ⇒ Object
- #plan(code, id = nil) ⇒ Object
- #plans(filters = nil) ⇒ Object
- #productCode=(productCode) ⇒ Object
- #removeItemQuantity(code, id = nil, data) ⇒ Object
- #request(path, args = nil) ⇒ Object
- #setItemQuantity(code, id = nil, data) ⇒ Object
Constructor Details
#initialize(url, username, password, productCode = nil) ⇒ Request
Returns a new instance of Request.
12 13 14 15 16 |
# File 'lib/cheddargetter-client.rb', line 12 def initialize(url, username, password, productCode = nil) self.class.base_uri url self.class.basic_auth username, password @productCode = productCode end |
Instance Method Details
#addItemQuantity(code, id = nil, data) ⇒ Object
78 79 80 81 |
# File 'lib/cheddargetter-client.rb', line 78 def addItemQuantity(code, id = nil, data) raise ArgumentError, 'code|id is required' if code.blank? || id.blank? return Response.new(request('/customers/add-item-quantity/' + (id!=nil ? id : code), data)) end |
#cancelSubscription(code, id = nil) ⇒ Object
73 74 75 76 |
# File 'lib/cheddargetter-client.rb', line 73 def cancelSubscription(code, id = nil) raise ArgumentError, 'code|id is required' if code.blank? || id.blank? return Response.new(request('/customers/cancel/' + (id!=nil ? id : code))) end |
#customer(code, id = nil) ⇒ Object
49 50 51 52 |
# File 'lib/cheddargetter-client.rb', line 49 def customer(code, id = nil) raise ArgumentError, 'code|id is required' if code.blank? || id.blank? return Response.new(request('/customers/get/' + (id!=nil ? id : code))) end |
#customers(filters = nil) ⇒ Object
45 46 47 |
# File 'lib/cheddargetter-client.rb', line 45 def customers(filters = nil) return Response.new(request('/customers/get', filters)) end |
#deleteCustomer(code, id = nil) ⇒ Object
63 64 65 66 |
# File 'lib/cheddargetter-client.rb', line 63 def deleteCustomer(code, id = nil) raise ArgumentError, 'code|id is required' if code.blank? || id.blank? return Response.new(request('/customers/delete/' + (id!=nil ? id : code), data)) end |
#deletePlan(code, id) ⇒ Object
40 41 42 43 |
# File 'lib/cheddargetter-client.rb', line 40 def deletePlan(code, id) raise ArgumentError, 'code|id is required' if code.blank? || id.blank? return Response.new(request('/plans/delete/' + (id ? 'id/' + id : 'code/' + code))) end |
#editCustomer(code, id = nil, data) ⇒ Object
58 59 60 61 |
# File 'lib/cheddargetter-client.rb', line 58 def editCustomer(code, id = nil, data) raise ArgumentError, 'code|id is required' if code.blank? || id.blank? return Response.new(request('/customers/edit/' + (id!=nil ? id : code), data)) end |
#editPlan(code, id = nil, data) ⇒ Object
35 36 37 38 |
# File 'lib/cheddargetter-client.rb', line 35 def editPlan(code, id = nil, data) raise ArgumentError, 'code|id is required' if code.blank? || id.blank? return Response.new(request('/plans/edit/' + (id ? 'id/' + id : 'code/' + code), data)) end |
#editSubscription(code, id = nil, data) ⇒ Object
68 69 70 71 |
# File 'lib/cheddargetter-client.rb', line 68 def editSubscription(code, id = nil, data) raise ArgumentError, 'code|id is required' if code.blank? || id.blank? return Response.new(request('/customers/edit-subscription/' + (id!=nil ? id : code), data)) end |
#newCustomer(data) ⇒ Object
54 55 56 |
# File 'lib/cheddargetter-client.rb', line 54 def newCustomer(data) return Response.new(request('/customers/new', data)) end |
#newPlan(data) ⇒ Object
31 32 33 |
# File 'lib/cheddargetter-client.rb', line 31 def newPlan(data) return Response.new(request('/plans/new', data)) end |
#plan(code, id = nil) ⇒ Object
26 27 28 29 |
# File 'lib/cheddargetter-client.rb', line 26 def plan(code, id = nil) raise ArgumentError, 'code|id is required' if code.blank? || id.blank? return Response.new(request('/plans/get/' + (id!=nil ? id : code))) end |
#plans(filters = nil) ⇒ Object
22 23 24 |
# File 'lib/cheddargetter-client.rb', line 22 def plans(filters = nil) return Response.new(request('/plans/get', filters)) end |
#productCode=(productCode) ⇒ Object
18 19 20 |
# File 'lib/cheddargetter-client.rb', line 18 def productCode=(productCode) @productCode = productCode end |
#removeItemQuantity(code, id = nil, data) ⇒ Object
83 84 85 86 |
# File 'lib/cheddargetter-client.rb', line 83 def removeItemQuantity(code, id = nil, data) raise ArgumentError, 'code|id is required' if code.blank? || id.blank? return Response.new(request('/customers/remove-item-quantity/' + (id!=nil ? id : code), data)) end |
#request(path, args = nil) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/cheddargetter-client.rb', line 93 def request(path, args = nil) path = '/xml/' + path + (@productCode!=nil ? '/productCode/' + @productCode : '') # convert multiple adjacent slashes to single slashes path = path.gsub(/(\w)\/+/, '\1/') if (args != nil) return Request.post(path, :body => args).to_s else return Request.get(path).to_s end end |
#setItemQuantity(code, id = nil, data) ⇒ Object
88 89 90 91 |
# File 'lib/cheddargetter-client.rb', line 88 def setItemQuantity(code, id = nil, data) raise ArgumentError, 'code|id is required' if code.blank? || id.blank? return Response.new(request('/customers/set-item-quantity/' + (id!=nil ? id : code), data)) end |