Class: Deposit

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

Class Method Summary collapse

Class Method Details

.apiKeyObject



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

def self.apiKey
  return Config.apiKey
end

.createDeposit(toAcc, deposit) ⇒ Object

Creates a new deposit. Parameters: toAccountId, DepositHash DepositHash is formatted as follows:

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

Returns http response code.



56
57
58
59
60
61
62
63
64
65
# File 'lib/capital_one/deposit.rb', line 56

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

.deleteDeposit(id) ⇒ Object

Deletes an existing deposit

Parameters: DepositId

Returns http response code



102
103
104
105
106
107
108
109
# File 'lib/capital_one/deposit.rb', line 102

def self.deleteDeposit(id)
  url = "#{self.url}/deposits/#{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 deposits for a specific account

Parameters: AccountID

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



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

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

.getOne(id) ⇒ Object

Returns a deposit for a given ID

Parameters: DepositId

Returns a hash with the deposit data



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

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

.updateDeposit(id, deposit) ⇒ Object

Updates an existing deposit

Parameters: DepositId, DepositHash

DepositHash is formatted as follows:

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

Returns http response code



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/capital_one/deposit.rb', line 83

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

.urlObject



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

def self.url
  return Config.baseUrl
end

.urlWithEntityObject



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

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