Class: Account

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

Class Method Summary collapse

Class Method Details

.apiKeyObject



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

def self.apiKey
	return Config.apiKey
end

.createAccount(custID, account) ⇒ Object

createAccount

Creates a new account Parameters: CustomerID, accountHash Returns the http response code.



89
90
91
92
93
94
95
96
97
98
# File 'lib/capital_one/account.rb', line 89

def self.createAccount(custID, )
	accountToCreate = .to_json
	url = "#{self.url}/customers/#{custID}/accounts?key=#{self.apiKey}"
	uri = URI.parse(url)
	http = Net::HTTP.new(uri.host, uri.port)
	request = Net::HTTP::Post.new(uri.request_uri, initheader = {'Content-Type' =>'application/json'})
	request.body = accountToCreate
	response = http.request(request)
	return JSON.parse(response.body)
end

.deleteAccount(accountId) ⇒ Object

delete a given account by accountId. Parameters: AccountId. Returns the http response code.



108
109
110
111
112
113
114
115
# File 'lib/capital_one/account.rb', line 108

def self.deleteAccount(accountId)
	url = "#{self.urlWithEntity}/#{accountId}?key=#{self.apiKey}"
	uri = URI.parse(url)
	http = Net::HTTP.new(uri.host, uri.port)
	key="?key=#{self.apiKey}"
	request = Net::HTTP::Delete.new(uri.path+key)
	response = http.request(request)
end

.getAllObject

Returns an array of hashes getting all the customers. Each index in the array is the hash of an individual customer.



20
21
22
23
24
# File 'lib/capital_one/account.rb', line 20

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

.getAllByCustomerId(customerId) ⇒ Object

Returns all accounts associated with a given customer ID as an array of hashes.

Parameters: CustomerId

Accepts a string of the customer ID



55
56
57
58
59
# File 'lib/capital_one/account.rb', line 55

def self.getAllByCustomerId(customerId)
	url = "#{self.url}/customers/#{customerId}/accounts?key=#{self.apiKey}"
	resp = Net::HTTP.get_response(URI.parse(url))
	data = JSON.parse(resp.body)
end

.getAllByType(type) ⇒ Object

Gets all accounts of a given type.

Parameters: type

Accepts a string of the account type. 3 possbilities: Credit Card, Savings, Checking. Returns an array of hashes with the accounts.



32
33
34
35
36
# File 'lib/capital_one/account.rb', line 32

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

.getOne(id) ⇒ Object

Returns the account specified by its account ID.

Parameters: AccountId

Accepts a string of the account ID. Returns a hash with the account info.



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

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

.updateAccount(accountId, account) ⇒ Object

Updates an account’s nickname.

Parameters: AccountID, AccountHash

Returns the http response code.



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/capital_one/account.rb', line 69

def self.updateAccount(accountId, )
	accountToUpdate = .to_json
	url = "#{self.urlWithEntity}/#{accountId}?key=#{self.apiKey}"
	uri = URI.parse(url)
	http = Net::HTTP.new(uri.host, uri.port)
	key = "?key=#{self.apiKey}"
	request = Net::HTTP::Put.new(uri.path+key, initheader = {'Content-Type' =>'application/json'})
	request.body = accountToUpdate
	response = http.request(request)
	return JSON.parse(response.body)
end

.urlObject



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

def self.url
	return Config.baseUrl
end

.urlWithEntityObject



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

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