class Purchase
Public Class Methods
apiKey()
click to toggle source
# File lib/capital_one/purchase.rb, line 11 def self.apiKey return Config.apiKey end
createPurchase(accId, purchase)
click to toggle source
*** POST ***
createPurchase¶ ↑
Creates a new purchase for a given account
Parameters: AccountId, PurchaseHash¶ ↑
PurchaseHash is formatted as follows: { "merchant_id": "string", "medium": "balance", "purchase_date": "string", "amount": 0, "status": "pending", "description": "string" } Returns http response code
# File lib/capital_one/purchase.rb, line 53 def self.createPurchase(accId, purchase) purchaseToCreate = purchase.to_json url = "#{self.urlWithEntity}/#{accId}/purchases?&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 = purchaseToCreate response = http.request(request) return JSON.parse(response.body) end
deletePurchase(id)
click to toggle source
deletePurchase¶ ↑
Deletes a purchase for a given ID
Parameters: PurchaseId¶ ↑
Returns http response code
# File lib/capital_one/purchase.rb, line 99 def self.deletePurchase(id) url = "#{self.url}/purchases/#{id}?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(accId)
click to toggle source
getAll¶ ↑
Returns all purchases for a given account
Parameters: AccountId¶ ↑
Returns an array of hashes
# File lib/capital_one/purchase.rb, line 22 def self.getAllByAccountId(accId) url = "#{self.urlWithEntity}/#{accId}/purchases?&key=#{self.apiKey}" resp = Net::HTTP.get_response(URI.parse(url)) data = JSON.parse(resp.body) end
getOne(id)
click to toggle source
updatePurchase(id, purchase)
click to toggle source
updatePurchase¶ ↑
Updates an existing purchase
Parameters: PurchaseId, PurchaseHash¶ ↑
PurchaseHash is formatted as follows: { "merchant_id": "string", "medium": "balance", "purchase_date": "string", "amount": 0, "status": "pending", "description": "string" } Returns http response code
# File lib/capital_one/purchase.rb, line 80 def self.updatePurchase(id, purchase) purchaseToUpdate = purchase.to_json url = "#{self.url}/purchases/#{id}?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 = purchaseToUpdate response = http.request(request) return JSON.parse(response.body) end
url()
click to toggle source
# File lib/capital_one/purchase.rb, line 7 def self.url return Config.baseUrl end
urlWithEntity()
click to toggle source
# File lib/capital_one/purchase.rb, line 3 def self.urlWithEntity return Config.baseUrl + "/accounts" end