Class: Bill
- Inherits:
-
Object
- Object
- Bill
- Defined in:
- lib/capital_one/bill.rb
Class Method Summary collapse
- .accountBaseUrl ⇒ Object
- .apiKey ⇒ Object
-
.createBill(accountId, bill) ⇒ Object
Returns http response code.
- .customerBaseUrl ⇒ Object
-
.deleteBill(accountId, billId) ⇒ Object
*** DELETE *** ==deleteBill delete a bill by id from a given account.
-
.getAllByAccountId(accountId) ⇒ Object
getAllByAccountId Get all bills for a specific account Parameters: accountId Returns an array of hashes containing the bills.
-
.getAllByCustomerId(customerId) ⇒ Object
getAllByCustomerId Get all bills for a specific customer Parameters: customerId Returns the customer as a hash array.
-
.getOneByAccountIdBillId(accountId, billId) ⇒ Object
Returns a hash array with the bill.
-
.getOneByCustomerIdBillId(customerId, billId) ⇒ Object
getOneByCustomerIdBillId Get a specific bill from a specific customer.
-
.updateBill(accountId, billId, bill) ⇒ Object
Returns http response code.
- .url ⇒ Object
Class Method Details
.accountBaseUrl ⇒ Object
3 4 5 |
# File 'lib/capital_one/bill.rb', line 3 def self.accountBaseUrl return Config.baseUrl + "/accounts" end |
.apiKey ⇒ Object
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.
101 102 103 104 105 106 107 108 109 |
# File 'lib/capital_one/bill.rb', line 101 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 |
.customerBaseUrl ⇒ Object
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.
117 118 119 120 121 122 123 124 |
# File 'lib/capital_one/bill.rb', line 117 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
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 85 |
# File 'lib/capital_one/bill.rb', line 75 def self.updateBill(accountId, billId, bill) billToUpdate = bill.to_json 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, initheader = {'Content-Type' =>'application/json'}) request.body = billToUpdate response = http.request(request) return JSON.parse(response.body) end |
.url ⇒ Object
11 12 13 |
# File 'lib/capital_one/bill.rb', line 11 def self.url return Config.baseUrl end |