Class: Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/capital_one/transaction.rb

Class Method Summary collapse

Class Method Details

.apiKeyObject


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

def self.apiKey
	return Config.apiKey
end

.createTransaction(toAcc, json) ⇒ Object

Create a new transaction between 2 accounts

createTransaction

Creates a new transaction. Parameters: toAccountId, hashWithTransacionData Returns http response code.


48
49
50
51
52
53
54
55
56
# File 'lib/capital_one/transaction.rb', line 48

def self.createTransaction(toAcc, json)
	url = "#{self.urlWithEntity}/#{toAcc}/transactions?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 = json
	resp = http.request(request)
	data = JSON.parse(resp.body)
end

.deleteTransaction(accID, transID) ⇒ Object

deleteTransaction

Deletes a specified transaction from a specified account. Parameters: AccountID, TransactionID Returns http response code.

Note:

This does not actually delete the transaction from the database, it only sets it's status to 'cancelled'


68
69
70
71
72
73
74
75
76
# File 'lib/capital_one/transaction.rb', line 68

def self.deleteTransaction(accID, transID)
	url = "#{self.urlWithEntity}/#{accID}/transactions/#{transID}?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)
	resp = http.request(request)
	data = JSON.parse(resp.body)
end

.getAllByAccountId(accID) ⇒ Object

*** GET ***

getAllByAccountId

Get all transactions for a specific account Returns an array of hashes. Parameters: AccountID Returns an array of hashes containing the transactions for that account.


22
23
24
25
26
27
# File 'lib/capital_one/transaction.rb', line 22

def self.getAllByAccountId(accID)
	url = "#{self.urlWithEntity}/#{accID}/transactions?key=#{self.apiKey}"
	resp = Net::HTTP.get_response(URI.parse(url))
	data = JSON.parse(resp.body)
	return data
end

.getOneByAccountIdTransactionId(accID, tranID) ⇒ Object

getOneByAccountIdTransactionId

Get a specific transaction from a specific account. Parameters: AccountID, TransactionId Returns a hash with the specified transaction


34
35
36
37
38
# File 'lib/capital_one/transaction.rb', line 34

def self.getOneByAccountIdTransactionId(accID, tranID)
	url = "#{self.urlWithEntity}/#{accID}/transactions/#{tranID}?key=#{self.apiKey}"
	resp = Net::HTTP.get_response(URI.parse(url))
	data = JSON.parse(resp.body)
end

.urlObject


7
8
9
# File 'lib/capital_one/transaction.rb', line 7

def self.url
	return Config.baseUrl
end

.urlWithEntityObject


3
4
5
# File 'lib/capital_one/transaction.rb', line 3

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