Class: CheddarGetter::Request

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/cheddargetter-client.rb

Instance Method Summary collapse

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

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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