Class: Customer
- Inherits:
-
Object
- Object
- Customer
- Defined in:
- lib/capital_one/customer.rb
Class Method Summary collapse
- .apiKey ⇒ Object
-
.createCustomer(customer) ⇒ Object
Returns http response code.
-
.getAll ⇒ Object
Gets all customers the API key has acccess to.
-
.getOne(custId) ⇒ Object
Gets the specified customer’s information.
-
.getOneByAccountId(accID) ⇒ Object
Get the customer for the given account.
-
.updateCustomer(custID, customer) ⇒ Object
Returns http response code.
- .url ⇒ Object
- .urlWithAcctEntity ⇒ Object
- .urlWithEntity ⇒ Object
Class Method Details
.apiKey ⇒ Object
15 16 17 |
# File 'lib/capital_one/customer.rb', line 15 def self.apiKey return Config.apiKey end |
.createCustomer(customer) ⇒ Object
Returns http response code
73 74 75 76 77 78 79 80 81 |
# File 'lib/capital_one/customer.rb', line 73 def self.createCustomer(customer) url = "#{self.urlWithEntity}?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 = customer.to_json response = http.request(request) return JSON.parse(response.body) end |
.getAll ⇒ Object
Gets all customers the API key has acccess to. Returns an array of hashes.
25 26 27 28 29 30 |
# File 'lib/capital_one/customer.rb', line 25 def self.getAll url = "#{self.urlWithEntity}?key=#{self.apiKey}" resp = Net::HTTP.get_response(URI.parse(url)) data = JSON.parse(resp.body) return data end |
.getOne(custId) ⇒ Object
Gets the specified customer’s information.
Parameters: CustomerId
Returns a Hash with the customer data
37 38 39 40 41 |
# File 'lib/capital_one/customer.rb', line 37 def self.getOne(custId) url = "#{self.urlWithEntity}/#{custId}?key=#{self.apiKey}" resp = Net::HTTP.get_response(URI.parse(url)) data = JSON.parse(resp.body) end |
.getOneByAccountId(accID) ⇒ Object
Get the customer for the given account.
Parameters: AccountId
Returns a hash with the specified customer data.
48 49 50 51 52 |
# File 'lib/capital_one/customer.rb', line 48 def self.getOneByAccountId(accID) url = "#{self.urlWithAcctEntity}/#{accID}/customer?key=#{self.apiKey}" resp = Net::HTTP.get_response(URI.parse(url)) data = JSON.parse(resp.body) end |
.updateCustomer(custID, customer) ⇒ Object
Returns http response code.
101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/capital_one/customer.rb', line 101 def self.updateCustomer(custID, customer) customerToUpdate = customer.to_json url = "#{self.urlWithEntity}/#{custID}?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 = customerToUpdate response = http.request(request) return JSON.parse(response.body) end |
.url ⇒ Object
11 12 13 |
# File 'lib/capital_one/customer.rb', line 11 def self.url return Config.baseUrl end |
.urlWithAcctEntity ⇒ Object
7 8 9 |
# File 'lib/capital_one/customer.rb', line 7 def self.urlWithAcctEntity return Config.baseUrl + "/accounts" end |
.urlWithEntity ⇒ Object
3 4 5 |
# File 'lib/capital_one/customer.rb', line 3 def self.urlWithEntity return Config.baseUrl + "/customers" end |