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

*** POST ***

createAccount

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


81
82
83
84
85
86
87
88
89
90
# File 'lib/capital_one/account.rb', line 81

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 ***

deleteAccount

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


98
99
100
101
102
103
104
105
# File 'lib/capital_one/account.rb', line 98

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

getAllByCustomerId

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


52
53
54
55
56
# File 'lib/capital_one/account.rb', line 52

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:

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

getOne

Returns the account specified by it's account ID.

Parameters:

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


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

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

*** PUT ***

updateAccount

Updates an account's nickname. Parameters: AccountID, AccountHash Returns the http response code.


64
65
66
67
68
69
70
71
72
73
# File 'lib/capital_one/account.rb', line 64

def self.updateAccount(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::Put.new(uri.path+key)
	request.set_form_data()
	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