capital_one 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/capital_one.rb +57 -54
- data/lib/capital_one/account.rb +116 -107
- data/lib/capital_one/atm.rb +49 -43
- data/lib/capital_one/bill.rb +123 -124
- data/lib/capital_one/branch.rb +36 -34
- data/lib/capital_one/customer.rb +112 -79
- data/lib/capital_one/deposit.rb +109 -76
- data/lib/capital_one/merchant.rb +118 -0
- data/lib/capital_one/purchase.rb +107 -0
- data/lib/capital_one/transfer.rb +93 -0
- data/lib/capital_one/version.rb +3 -3
- data/lib/capital_one/withdrawal.rb +107 -76
- metadata +7 -5
- data/lib/capital_one/transaction.rb +0 -103
@@ -0,0 +1,118 @@
|
|
1
|
+
class Merchant
|
2
|
+
|
3
|
+
def self.urlWithEntity
|
4
|
+
return Config.baseUrl + "/merchants"
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.url
|
8
|
+
return Config.baseUrl
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.apiKey
|
12
|
+
return Config.apiKey
|
13
|
+
end
|
14
|
+
|
15
|
+
# *** GET ***
|
16
|
+
|
17
|
+
#==getAll
|
18
|
+
# Returns all Merchants as an array of hashes
|
19
|
+
def self.getAll
|
20
|
+
url = "#{self.urlWithEntity}?key=#{self.apiKey}"
|
21
|
+
resp = Net::HTTP.get_response(URI.parse(url))
|
22
|
+
data = JSON.parse(resp.body)
|
23
|
+
return data
|
24
|
+
end
|
25
|
+
|
26
|
+
#==getAllByLocation
|
27
|
+
# Returns all Merchants within a given location range
|
28
|
+
#= Parameters: Latitude, Longitude, Radius
|
29
|
+
# Accepts lat, lng, and rad as floats
|
30
|
+
# Returns an array of hashes
|
31
|
+
|
32
|
+
def self.getAllByLocation(lat, lng, rad)
|
33
|
+
url = "#{self.urlWithEntity}?lat=#{lat}&lng=#{lng}&rad=#{rad}&key=#{self.apiKey}"
|
34
|
+
resp = Net::HTTP.get_response(URI.parse(url))
|
35
|
+
data = JSON.parse(resp.body)
|
36
|
+
return data
|
37
|
+
end
|
38
|
+
|
39
|
+
#==getOne
|
40
|
+
# Returns a single merchant for a given ID
|
41
|
+
#= Parameters: MerchantId
|
42
|
+
# Returns a hash
|
43
|
+
|
44
|
+
def self.getOne(merchId)
|
45
|
+
url = "#{self.urlWithEntity}/#{merchId}?key=#{self.apiKey}"
|
46
|
+
resp = Net::HTTP.get_response(URI.parse(url))
|
47
|
+
data = JSON.parse(resp.body)
|
48
|
+
return data
|
49
|
+
end
|
50
|
+
|
51
|
+
# *** PUT ***
|
52
|
+
|
53
|
+
#==updateMerchant
|
54
|
+
# Updates an existing Merchant
|
55
|
+
#= Parameters: MerchantId, MerchantHash
|
56
|
+
# MerchantHash format is as follows:
|
57
|
+
# {
|
58
|
+
# "name": "string",
|
59
|
+
# "address": {
|
60
|
+
# "street_number": "string",
|
61
|
+
# "street_name": "string",
|
62
|
+
# "city": "string",
|
63
|
+
# "state": "string",
|
64
|
+
# "zip": "string",
|
65
|
+
# },
|
66
|
+
# "geocode": {
|
67
|
+
# "lat": 0,
|
68
|
+
# "lng": 0,
|
69
|
+
# }
|
70
|
+
# }
|
71
|
+
# Returns http response code
|
72
|
+
|
73
|
+
def self.updateMerchant(merchId, merchant)
|
74
|
+
merchantToUpdate = merchant.to_json
|
75
|
+
url = "#{self.urlWithEntity}/#{merchId}?key=#{self.apiKey}"
|
76
|
+
uri = URI.parse(url)
|
77
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
78
|
+
key = "?key=#{self.apiKey}"
|
79
|
+
request = Net::HTTP::Put.new(uri.path+key, initheader = {'Content-Type' =>'application/json'})
|
80
|
+
request.body = merchantToUpdate
|
81
|
+
response = http.request(request)
|
82
|
+
return JSON.parse(response.body)
|
83
|
+
end
|
84
|
+
|
85
|
+
# *** POST ***
|
86
|
+
|
87
|
+
#==createMerchant
|
88
|
+
# Creates a new Merchant
|
89
|
+
#= Parameters: MerchantHash
|
90
|
+
# MerchantHash format is as follows:
|
91
|
+
# {
|
92
|
+
# "name": "string",
|
93
|
+
# "address": {
|
94
|
+
# "street_number": "string",
|
95
|
+
# "street_name": "string",
|
96
|
+
# "city": "string",
|
97
|
+
# "state": "string",
|
98
|
+
# "zip": "string",
|
99
|
+
# },
|
100
|
+
# "geocode": {
|
101
|
+
# "lat": 0,
|
102
|
+
# "lng": 0,
|
103
|
+
# }
|
104
|
+
# }
|
105
|
+
# Returns http response code
|
106
|
+
|
107
|
+
def self.createMerchant(merchant)
|
108
|
+
merchantToCreate = merchant.to_json
|
109
|
+
url = "#{self.urlWithEntity}/?key=#{self.apiKey}"
|
110
|
+
uri = URI.parse(url)
|
111
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
112
|
+
request = Net::HTTP::Post.new(uri.request_uri, initheader = {'Content-Type' => 'application/json'})
|
113
|
+
request.body = merchantToCreate
|
114
|
+
resp = http.request(request)
|
115
|
+
data = JSON.parse(resp.body)
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
class Purchase
|
2
|
+
|
3
|
+
def self.urlWithEntity
|
4
|
+
return Config.baseUrl + "/accounts"
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.url
|
8
|
+
return Config.baseUrl
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.apiKey
|
12
|
+
return Config.apiKey
|
13
|
+
end
|
14
|
+
|
15
|
+
# *** GET ***
|
16
|
+
|
17
|
+
#==getAll
|
18
|
+
# Returns all purchases for a given account
|
19
|
+
#= Parameters: AccountId
|
20
|
+
# Returns an array of hashes
|
21
|
+
|
22
|
+
def self.getAllByAccountId(accId)
|
23
|
+
url = "#{self.urlWithEntity}/#{accId}/purchases?&key=#{self.apiKey}"
|
24
|
+
resp = Net::HTTP.get_response(URI.parse(url))
|
25
|
+
data = JSON.parse(resp.body)
|
26
|
+
end
|
27
|
+
|
28
|
+
#==getOne
|
29
|
+
# Returns a purchase for a given ID
|
30
|
+
#= Parameters: PurchaseId
|
31
|
+
# Returns a hash
|
32
|
+
|
33
|
+
def self.getOne(id)
|
34
|
+
url = "#{self.url}/purchases/#{id}?&key=#{self.apiKey}"
|
35
|
+
resp = Net::HTTP.get_response(URI.parse(url))
|
36
|
+
data = JSON.parse(resp.body)
|
37
|
+
end
|
38
|
+
|
39
|
+
# *** POST ***
|
40
|
+
#==createPurchase
|
41
|
+
# Creates a new purchase for a given account
|
42
|
+
#= Parameters: AccountId, PurchaseHash
|
43
|
+
# PurchaseHash is formatted as follows:
|
44
|
+
# {
|
45
|
+
# "merchant_id": "string",
|
46
|
+
# "medium": "balance",
|
47
|
+
# "purchase_date": "string",
|
48
|
+
# "amount": 0,
|
49
|
+
# "status": "pending",
|
50
|
+
# "description": "string"
|
51
|
+
# }
|
52
|
+
# Returns http response code
|
53
|
+
def self.createPurchase(accId, purchase)
|
54
|
+
purchaseToCreate = purchase.to_json
|
55
|
+
url = "#{self.urlWithEntity}/#{accId}/purchases?&key=#{self.apiKey}"
|
56
|
+
uri = URI.parse(url)
|
57
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
58
|
+
request = Net::HTTP::Post.new(uri.request_uri, initheader = {'Content-Type' =>'application/json'})
|
59
|
+
request.body = purchaseToCreate
|
60
|
+
response = http.request(request)
|
61
|
+
return JSON.parse(response.body)
|
62
|
+
end
|
63
|
+
|
64
|
+
# *** PUT ***
|
65
|
+
|
66
|
+
#==updatePurchase
|
67
|
+
# Updates an existing purchase
|
68
|
+
#= Parameters: PurchaseId, PurchaseHash
|
69
|
+
# PurchaseHash is formatted as follows:
|
70
|
+
# {
|
71
|
+
# "merchant_id": "string",
|
72
|
+
# "medium": "balance",
|
73
|
+
# "purchase_date": "string",
|
74
|
+
# "amount": 0,
|
75
|
+
# "status": "pending",
|
76
|
+
# "description": "string"
|
77
|
+
# }
|
78
|
+
# Returns http response code
|
79
|
+
|
80
|
+
def self.updatePurchase(id, purchase)
|
81
|
+
purchaseToUpdate = purchase.to_json
|
82
|
+
url = "#{self.url}/purchases/#{id}?key=#{self.apiKey}"
|
83
|
+
uri = URI.parse(url)
|
84
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
85
|
+
key = "?key=#{self.apiKey}"
|
86
|
+
request = Net::HTTP::Put.new(uri.path+key, initheader = {'Content-Type' =>'application/json'})
|
87
|
+
request.body = purchaseToUpdate
|
88
|
+
response = http.request(request)
|
89
|
+
return JSON.parse(response.body)
|
90
|
+
end
|
91
|
+
|
92
|
+
# *** DELETE ***
|
93
|
+
|
94
|
+
#==deletePurchase
|
95
|
+
# Deletes a purchase for a given ID
|
96
|
+
#= Parameters: PurchaseId
|
97
|
+
# Returns http response code
|
98
|
+
|
99
|
+
def self.deletePurchase(id)
|
100
|
+
url = "#{self.url}/purchases/#{id}?key=#{self.apiKey}"
|
101
|
+
uri = URI.parse(url)
|
102
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
103
|
+
key="?key=#{self.apiKey}"
|
104
|
+
request = Net::HTTP::Delete.new(uri.path+key)
|
105
|
+
response = http.request(request)
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
class Transfer
|
2
|
+
|
3
|
+
def self.urlWithEntity
|
4
|
+
return Config.baseUrl + "/accounts"
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.url
|
8
|
+
return Config.baseUrl
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.apiKey
|
12
|
+
return Config.apiKey
|
13
|
+
end
|
14
|
+
|
15
|
+
# *** GET ***
|
16
|
+
#= getAll
|
17
|
+
# Returns an array of hashes getting all the transfers for an account.
|
18
|
+
# Each index in the array is the hash of an individual transfer.
|
19
|
+
def self.getAll(accId)
|
20
|
+
url = "#{self.urlWithEntity}/#{accId}/transfers?&key=#{self.apiKey}"
|
21
|
+
resp = Net::HTTP.get_response(URI.parse(url))
|
22
|
+
data = JSON.parse(resp.body)
|
23
|
+
end
|
24
|
+
|
25
|
+
#== getAllByType
|
26
|
+
# Gets all transfers of a given type and account.
|
27
|
+
#= Parameters:
|
28
|
+
# Accepts a string of the transfer type. 2 possbilities: payer or payee
|
29
|
+
# Returns an array of hashes with the transfers.
|
30
|
+
def self.getAllByType(accId, type)
|
31
|
+
url = "#{self.urlWithEntity}/#{accId}/transfers?type=#{type}&key=#{self.apiKey}"
|
32
|
+
resp = Net::HTTP.get_response(URI.parse(url))
|
33
|
+
data = JSON.parse(resp.body)
|
34
|
+
end
|
35
|
+
|
36
|
+
#== getOne
|
37
|
+
# Returns the transfer specified by its transfer ID.
|
38
|
+
#= Parameters:
|
39
|
+
# Accepts a string of the transfer ID.
|
40
|
+
# Returns a hash with the transfer info.
|
41
|
+
def self.getOne(id)
|
42
|
+
url = "#{self.url}/transfers/#{id}?key=#{self.apiKey}"
|
43
|
+
resp = Net::HTTP.get_response(URI.parse(url))
|
44
|
+
data = JSON.parse(resp.body)
|
45
|
+
end
|
46
|
+
|
47
|
+
# *** POST ***
|
48
|
+
#== createAccount
|
49
|
+
# Creates a new transfer
|
50
|
+
# Parameters: AccountID, TransferHash
|
51
|
+
# Returns the http response code.
|
52
|
+
def self.createTransfer(accId, transfer)
|
53
|
+
transferToCreate = transfer.to_json
|
54
|
+
url = "#{self.urlWithEntity}/#{accId}/transfers?key=#{self.apiKey}"
|
55
|
+
uri = URI.parse(url)
|
56
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
57
|
+
request = Net::HTTP::Post.new(uri.request_uri, initheader = {'Content-Type' =>'application/json'})
|
58
|
+
request.body = transferToCreate
|
59
|
+
response = http.request(request)
|
60
|
+
return JSON.parse(response.body)
|
61
|
+
end
|
62
|
+
|
63
|
+
# *** PUT ***
|
64
|
+
#==updateAccount
|
65
|
+
# Updates a transfer's info.
|
66
|
+
# Parameters: TransferId, TransferHash
|
67
|
+
# Returns the http response code.
|
68
|
+
def self.updateTransfer(id, transfer)
|
69
|
+
transferToUpdate = transfer.to_json
|
70
|
+
url = "#{self.url}/transfers/#{id}?key=#{self.apiKey}"
|
71
|
+
uri = URI.parse(url)
|
72
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
73
|
+
key = "?key=#{self.apiKey}"
|
74
|
+
request = Net::HTTP::Put.new(uri.path+key, initheader = {'Content-Type' =>'application/json'})
|
75
|
+
request.body = transferToUpdate
|
76
|
+
response = http.request(request)
|
77
|
+
return JSON.parse(response.body)
|
78
|
+
end
|
79
|
+
|
80
|
+
# *** DELETE ***
|
81
|
+
#== deleteAccount
|
82
|
+
# delete a given transfer by TransferId.
|
83
|
+
# Parameters: TransferId.
|
84
|
+
# Returns the http response code.
|
85
|
+
def self.deleteTransfer(id)
|
86
|
+
url = "#{self.url}/transfers/#{id}?key=#{self.apiKey}"
|
87
|
+
uri = URI.parse(url)
|
88
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
89
|
+
key="?key=#{self.apiKey}"
|
90
|
+
request = Net::HTTP::Delete.new(uri.path+key)
|
91
|
+
response = http.request(request)
|
92
|
+
end
|
93
|
+
end
|
data/lib/capital_one/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module CapitalOne
|
2
|
-
VERSION = "0.1.0"
|
3
|
-
end
|
1
|
+
module CapitalOne
|
2
|
+
VERSION = "0.1.0"
|
3
|
+
end
|
@@ -1,77 +1,108 @@
|
|
1
|
-
class Withdrawal
|
2
|
-
|
3
|
-
def self.urlWithEntity
|
4
|
-
return Config.baseUrl + "/accounts"
|
5
|
-
end
|
6
|
-
|
7
|
-
def self.url
|
8
|
-
return Config.baseUrl
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.apiKey
|
12
|
-
return Config.apiKey
|
13
|
-
end
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
#==getAllByAccountId
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
def self.getAllByAccountId(accID)
|
23
|
-
url = "#{self.urlWithEntity}/#{accID}/withdrawals?key=#{self.apiKey}"
|
24
|
-
resp = Net::HTTP.get_response(URI.parse(url))
|
25
|
-
data = JSON.parse(resp.body)
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
http
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
#
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
1
|
+
class Withdrawal
|
2
|
+
|
3
|
+
def self.urlWithEntity
|
4
|
+
return Config.baseUrl + "/accounts"
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.url
|
8
|
+
return Config.baseUrl
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.apiKey
|
12
|
+
return Config.apiKey
|
13
|
+
end
|
14
|
+
|
15
|
+
# *** GET ***
|
16
|
+
|
17
|
+
#==getAllByAccountId
|
18
|
+
# Get all withdrawals for a specific account
|
19
|
+
#= Parameters: AccountID
|
20
|
+
# Returns an array of hashes containing the withdrawals for that account.
|
21
|
+
|
22
|
+
def self.getAllByAccountId(accID)
|
23
|
+
url = "#{self.urlWithEntity}/#{accID}/withdrawals?key=#{self.apiKey}"
|
24
|
+
resp = Net::HTTP.get_response(URI.parse(url))
|
25
|
+
data = JSON.parse(resp.body)
|
26
|
+
end
|
27
|
+
|
28
|
+
#==getOne
|
29
|
+
# Get a single withdrawal for a given ID
|
30
|
+
#= Parameters: WithdrawalId
|
31
|
+
# Returns a hash
|
32
|
+
|
33
|
+
def self.getOne(id)
|
34
|
+
url = "#{self.url}/withdrawals/#{id}?key=#{self.apiKey}"
|
35
|
+
resp = Net::HTTP.get_response(URI.parse(url))
|
36
|
+
data = JSON.parse(resp.body)
|
37
|
+
end
|
38
|
+
|
39
|
+
# *** POST ***
|
40
|
+
|
41
|
+
#==createWithdrawal
|
42
|
+
# Creates a new withdrawal
|
43
|
+
#= Parameters: toAccountId, WithdrawalHash
|
44
|
+
# WithdrawalHash formatted as follows:
|
45
|
+
# {
|
46
|
+
# "medium": "balance",
|
47
|
+
# "transaction_date": "string",
|
48
|
+
# "status": "pending",
|
49
|
+
# "amount": 0,
|
50
|
+
# "desciption": "string"
|
51
|
+
# }
|
52
|
+
# Returns http response code
|
53
|
+
|
54
|
+
def self.createWithdrawal(toAcc, withdrawal)
|
55
|
+
withdrawalToCreate = withdrawal.to_json
|
56
|
+
url = "#{self.urlWithEntity}/#{toAcc}/withdrawals?key=#{self.apiKey}"
|
57
|
+
uri = URI.parse(url)
|
58
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
59
|
+
request = Net::HTTP::Post.new(uri.request_uri, initheader = {'Content-Type' => 'application/json'})
|
60
|
+
request.body = withdrawalToCreate
|
61
|
+
resp = http.request(request)
|
62
|
+
data = JSON.parse(resp.body)
|
63
|
+
end
|
64
|
+
|
65
|
+
# *** PUT ***
|
66
|
+
|
67
|
+
#==updateWithdrawal
|
68
|
+
# Updates an existing withdrawal
|
69
|
+
#= Parameters: WithdrawalId, WithdrawalHash
|
70
|
+
# WithdrawalHash formatted as follows:
|
71
|
+
# {
|
72
|
+
# "medium": "balance",
|
73
|
+
# "transaction_date": "string",
|
74
|
+
# "status": "pending",
|
75
|
+
# "amount": 0,
|
76
|
+
# "desciption": "string"
|
77
|
+
# }
|
78
|
+
# Returns http response code
|
79
|
+
|
80
|
+
def self.updateWithdrawal(id, withdrawal)
|
81
|
+
url = "#{self.url}/withdrawals/#{id}?key=#{self.apiKey}"
|
82
|
+
uri = URI.parse(url)
|
83
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
84
|
+
key = "?key=#{self.apiKey}"
|
85
|
+
request = Net::HTTP::Put.new(uri.path+key, initheader = {'Content-Type' =>'application/json'})
|
86
|
+
request.body = withdrawal.to_json
|
87
|
+
response = http.request(request)
|
88
|
+
return JSON.parse(response.body)
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
# *** DELETE ***
|
93
|
+
|
94
|
+
#==deleteWithdrawal
|
95
|
+
# Deletes a specified withdrawal from a specified account.
|
96
|
+
# Parameters: WithdrawalID
|
97
|
+
# Returns http response code.
|
98
|
+
#= Note: This does not actually delete the withdrawal from the database, it only sets its status to 'cancelled'
|
99
|
+
|
100
|
+
def self.deleteWithdrawal(id)
|
101
|
+
url = "#{self.url}/withdrawals/#{id}?key=#{self.apiKey}"
|
102
|
+
uri = URI.parse(url)
|
103
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
104
|
+
key="?key=#{self.apiKey}"
|
105
|
+
request = Net::HTTP::Delete.new(uri.path+key)
|
106
|
+
resp = http.request(request)
|
107
|
+
end
|
77
108
|
end
|