class Account

Public Class Methods

apiKey() click to toggle source
# File lib/capital_one/account.rb, line 11
def self.apiKey
        return Config.apiKey
end
createAccount(custID, account) click to toggle source

createAccount

Creates a new account
Parameters: CustomerID, accountHash
Returns the http response code.
# File lib/capital_one/account.rb, line 89
def self.createAccount(custID, account)
        accountToCreate = account.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) click to toggle source

deleteAccount

delete a given account by accountId.
Parameters: AccountId.
Returns the http response code.
# File lib/capital_one/account.rb, line 108
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
getAll() click to toggle source
*** GET ***

getAll

Returns an array of hashes getting all the customers.
Each index in the array is the hash of an individual customer.
# 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) click to toggle source

getAllByCustomerId

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

Parameters: CustomerId

Accepts a string of the customer ID
# File lib/capital_one/account.rb, line 55
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) click to toggle source

getAllByType

Gets all accounts of a given type.

Parameters: type

Accepts a string of the account type. 3 possbilities: Credit Card, Savings, Checking.
Returns an array of hashes with the accounts.
# 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) click to toggle source

getOne

Returns the account specified by its account ID.

Parameters: AccountId

Accepts a string of the account ID. 
Returns a hash with the account info.
# File lib/capital_one/account.rb, line 44
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) click to toggle source

updateAccount

Updates an account's nickname.

Parameters: AccountID, AccountHash

Returns the http response code.
# File lib/capital_one/account.rb, line 69
def self.updateAccount(accountId, account)
        accountToUpdate = account.to_json
        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, initheader = {'Content-Type' =>'application/json'})
        request.body = accountToUpdate
        response = http.request(request)
        return JSON.parse(response.body)
end
url() click to toggle source
# File lib/capital_one/account.rb, line 7
def self.url
        return Config.baseUrl
end
urlWithEntity() click to toggle source
# File lib/capital_one/account.rb, line 3
def self.urlWithEntity
        return Config.baseUrl + "/accounts"
end