Class: Bill

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

Class Method Summary collapse

Class Method Details

.accountBaseUrlObject


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

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

.apiKeyObject


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

def self.apiKey
	return Config.apiKey
end

.createBill(accountId, bill) ⇒ Object

Returns http response code.


100
101
102
103
104
105
106
107
108
# File 'lib/capital_one/bill.rb', line 100

def self.createBill(accountId, bill)
	url = "#{self.accountBaseUrl}/#{accountId}/bills?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 = bill.to_json
	response = http.request(request)
	return JSON.parse(response.body)
end

.customerBaseUrlObject


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

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

.deleteBill(accountId, billId) ⇒ Object

*** DELETE ***

deleteBill

delete a bill by id from a given account. Parameters: Accountid, billid. Returns http response code.


116
117
118
119
120
121
122
123
# File 'lib/capital_one/bill.rb', line 116

def self.deleteBill(accountId, billId)
	url = "#{self.accountBaseUrl}/#{accountId}/bills/#{billId}?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

.getAllByAccountId(accountId) ⇒ Object

getAllByAccountId

Get all bills for a specific account Parameters: accountId Returns an array of hashes containing the bills.


45
46
47
48
49
# File 'lib/capital_one/bill.rb', line 45

def self.getAllByAccountId(accountId)
	url = "#{self.accountBaseUrl}/#{accountId}/bills?key=#{self.apiKey}"
	response = Net::HTTP.get_response(URI.parse(url))
	return JSON.parse(response.body)
end

.getAllByCustomerId(customerId) ⇒ Object

getAllByCustomerId

Get all bills for a specific customer Parameters: customerId Returns the customer as a hash array.


25
26
27
28
29
# File 'lib/capital_one/bill.rb', line 25

def self.getAllByCustomerId(customerId)
	url = "#{self.customerBaseUrl}/#{customerId}/bills?key=#{self.apiKey}"
	response = Net::HTTP.get_response(URI.parse(url))
	return JSON.parse(response.body)
end

.getOneByAccountIdBillId(accountId, billId) ⇒ Object

getOneByAccountIdBillId

Get a specific bill from a specific account Parameters: AccountId, BillId Returns a hash array with the bill.


54
55
56
57
58
# File 'lib/capital_one/bill.rb', line 54

def self.getOneByAccountIdBillId(accountId, billId)
	url ="#{self.accountBaseUrl}/#{accountId}/bills/#{billId}?key=#{self.apiKey}"
	response = Net::HTTP.get_response(URI.parse(url))
	return JSON.parse(response.body)
end

.getOneByCustomerIdBillId(customerId, billId) ⇒ Object

getOneByCustomerIdBillId

Get a specific bill from a specific customer. Parameters: customerId, BillId Returns the specified bill as a hash array


35
36
37
38
39
# File 'lib/capital_one/bill.rb', line 35

def self.getOneByCustomerIdBillId(customerId, billId)
	url = "#{self.customerBaseUrl}/#{customerId}/bills/#{billId}?key=#{self.apiKey}"
	resp = Net::HTTP.get_response(URI.parse(url))
	data = JSON.parse(resp.body)
end

.updateBill(accountId, billId, bill) ⇒ Object

Returns http response code.


75
76
77
78
79
80
81
82
83
84
# File 'lib/capital_one/bill.rb', line 75

def self.updateBill(accountId, billId, bill)
	url = "#{self.accountBaseUrl}/#{accountId}/bills/#{billId}?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(bill)
	response = http.request(request)
	return JSON.parse(response.body)
end

.urlObject


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

def self.url
	return Config.baseUrl
end