capital_one 0.4.1 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,107 +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
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
107
  end
@@ -1,93 +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
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
93
  end
@@ -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,108 +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
- # *** 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
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
108
108
  end