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



19
20
21
# File 'lib/capital_one/bill.rb', line 19

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(billId) ⇒ Object

delete a bill by its id Parameters: BillId Returns http response code



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

def self.deleteBill(billId)
  url = "#{self.urlWithEntity}/#{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

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



30
31
32
33
34
# File 'lib/capital_one/bill.rb', line 30

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

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



41
42
43
44
45
# File 'lib/capital_one/bill.rb', line 41

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

.getOne(id) ⇒ Object

Gets one bill for a specific billId Parameters: billId Returns a hash with the bill data



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

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

.updateBill(billId, bill) ⇒ Object

Returns http response code.



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

def self.updateBill(billId, bill)
  billToUpdate = bill.to_json
  url = "#{self.urlWithEntity}/#{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

.urlObject



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

def self.url
  return Config.baseUrl
end

.urlWithEntityObject



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

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