Class: Purchase
- Inherits:
-
Object
- Object
- Purchase
- Defined in:
- lib/capital_one/purchase.rb
Class Method Summary collapse
- .apiKey ⇒ Object
-
.createPurchase(accId, purchase) ⇒ Object
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.
-
.deletePurchase(id) ⇒ Object
Deletes a purchase for a given ID = Parameters: PurchaseId Returns http response code.
-
.getAllByAccountId(accId) ⇒ Object
Returns all purchases for a given account = Parameters: AccountId Returns an array of hashes.
-
.getOne(id) ⇒ Object
Returns a purchase for a given ID = Parameters: PurchaseId Returns a hash.
-
.updatePurchase(id, purchase) ⇒ Object
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.
- .url ⇒ Object
- .urlWithEntity ⇒ Object
Class Method Details
.apiKey ⇒ Object
11 12 13 |
# File 'lib/capital_one/purchase.rb', line 11 def self.apiKey return Config.apiKey end |
.createPurchase(accId, purchase) ⇒ Object
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
53 54 55 56 57 58 59 60 61 62 |
# 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) ⇒ Object
Deletes a purchase for a given ID
Parameters: PurchaseId
Returns http response code
99 100 101 102 103 104 105 106 |
# 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) ⇒ Object
Returns all purchases for a given account
Parameters: AccountId
Returns an array of hashes
22 23 24 25 26 |
# 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) ⇒ Object
Returns a purchase for a given ID
Parameters: PurchaseId
Returns a hash
33 34 35 36 37 |
# File 'lib/capital_one/purchase.rb', line 33 def self.getOne(id) url = "#{self.url}/purchases/#{id}?&key=#{self.apiKey}" resp = Net::HTTP.get_response(URI.parse(url)) data = JSON.parse(resp.body) end |
.updatePurchase(id, purchase) ⇒ Object
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
80 81 82 83 84 85 86 87 88 89 90 |
# 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 |