Class: Withdrawal

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

Class Method Summary collapse

Class Method Details

.apiKeyObject



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

def self.apiKey
  return Config.apiKey
end

.createWithdrawal(toAcc, withdrawal) ⇒ Object

Creates a new withdrawal

Parameters: toAccountId, WithdrawalHash

WithdrawalHash formatted as follows:

"medium": "balance",
"transaction_date": "string",
"status": "pending",
"amount": 0,
"desciption": "string"

Returns http response code



54
55
56
57
58
59
60
61
62
63
# File 'lib/capital_one/withdrawal.rb', line 54

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

.deleteWithdrawal(id) ⇒ Object

Deletes a specified withdrawal from a specified account. Parameters: WithdrawalID Returns http response code.

Note: This does not actually delete the withdrawal from the database, it only sets its status to ‘cancelled’



100
101
102
103
104
105
106
107
# File 'lib/capital_one/withdrawal.rb', line 100

def self.deleteWithdrawal(id)
  url = "#{self.url}/withdrawals/#{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)
  resp = http.request(request)
end

.getAllByAccountId(accID) ⇒ Object

Get all withdrawals for a specific account

Parameters: AccountID

Returns an array of hashes containing the withdrawals for that account.



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

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

.getOne(id) ⇒ Object

Get a single withdrawal for a given ID

Parameters: WithdrawalId

Returns a hash



33
34
35
36
37
# File 'lib/capital_one/withdrawal.rb', line 33

def self.getOne(id)
  url = "#{self.url}/withdrawals/#{id}?key=#{self.apiKey}"
  resp = Net::HTTP.get_response(URI.parse(url))
  data = JSON.parse(resp.body)
end

.updateWithdrawal(id, withdrawal) ⇒ Object

Updates an existing withdrawal

Parameters: WithdrawalId, WithdrawalHash

WithdrawalHash formatted as follows:

"medium": "balance",
"transaction_date": "string",
"status": "pending",
"amount": 0,
"desciption": "string"

Returns http response code



80
81
82
83
84
85
86
87
88
89
# File 'lib/capital_one/withdrawal.rb', line 80

def self.updateWithdrawal(id, withdrawal)
  url = "#{self.url}/withdrawals/#{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 = withdrawal.to_json
  response = http.request(request)
  return JSON.parse(response.body)
end

.urlObject



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

def self.url
  return Config.baseUrl
end

.urlWithEntityObject



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

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