Class: Customer

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

Class Method Summary collapse

Class Method Details

.apiKeyObject


15
16
17
# File 'lib/capital_one/customer.rb', line 15

def self.apiKey
	return Config.apiKey
end

.getAllObject

*** GET ***

getAll

Gets all customers the API key has acccess to. Returns an array of hashes.


23
24
25
26
27
28
# File 'lib/capital_one/customer.rb', line 23

def self.getAll
	url = "#{self.urlWithEntity}?key=#{self.apiKey}"
	resp = Net::HTTP.get_response(URI.parse(url))
	data = JSON.parse(resp.body)
	return data
end

.getOne(custId) ⇒ Object

getOne

Gets the specified customer's information. Parameters tested - Returns a hash.


34
35
36
37
38
# File 'lib/capital_one/customer.rb', line 34

def self.getOne(custId)
	url = "#{self.urlWithEntity}/#{custId}?key=#{self.apiKey}"
	resp = Net::HTTP.get_response(URI.parse(url))
	data = JSON.parse(resp.body)
end

.getOneByAccountId(accID) ⇒ Object

getOneByAccountId

Get the customer for the given account. Parameters: AccountId Returns a hash with the specified customer data.


44
45
46
47
48
# File 'lib/capital_one/customer.rb', line 44

def self.getOneByAccountId(accID)
	url = "#{self.urlWithAcctEntity}/#{accID}/customer?key=#{self.apiKey}"
	resp = Net::HTTP.get_response(URI.parse(url))
	data = JSON.parse(resp.body)
end

.updateCustomer(custID, customer) ⇒ Object

Returns http response code.


66
67
68
69
70
71
72
73
74
75
76
# File 'lib/capital_one/customer.rb', line 66

def self.updateCustomer(custID, customer)
	url = "#{self.urlWithEntity}/#{custID}?key=#{self.apiKey}"
	uri = URI.parse(url)
	myHash = JSON.parse(customer)
	http = Net::HTTP.new(uri.host, uri.port)
	key = "?key=#{self.apiKey}"
	request = Net::HTTP::Put.new(uri.path+key)
	request.set_form_data(myHash)
	http.request(request)

end

.urlObject


11
12
13
# File 'lib/capital_one/customer.rb', line 11

def self.url
	return Config.baseUrl
end

.urlWithAcctEntityObject


7
8
9
# File 'lib/capital_one/customer.rb', line 7

def self.urlWithAcctEntity
	return Config.baseUrl + "/accounts"
end

.urlWithEntityObject


3
4
5
# File 'lib/capital_one/customer.rb', line 3

def self.urlWithEntity
	return Config.baseUrl + "/customers"
end