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.
@@ -1,35 +1,37 @@
1
- class Branch
2
-
3
- def self.url
4
- return Config.baseUrl
5
- end
6
-
7
- def self.urlWithEntity
8
- return Config.baseUrl + "/branches"
9
- end
10
-
11
- def self.apiKey
12
- return Config.apiKey
13
- end
14
-
15
- # *** GET ***
16
- #==getAll
17
- # Get all the branches
18
- #Returns an array of hashes. Each hash is a branch.
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
- end
24
-
25
- #==getOne
26
- #Get a branch by it's id
27
- #Parameters: BranchId
28
- #Returns a hash with the specified branch.
29
- def self.getOne(id)
30
- url = "#{self.urlWithEntity}/#{id}?key=#{self.apiKey}"
31
- resp = Net::HTTP.get_response(URI.parse(url))
32
- data = JSON.parse(resp.body)
33
-
34
- end
1
+ class Branch
2
+
3
+ def self.url
4
+ return Config.baseUrl
5
+ end
6
+
7
+ def self.urlWithEntity
8
+ return Config.baseUrl + "/branches"
9
+ end
10
+
11
+ def self.apiKey
12
+ return Config.apiKey
13
+ end
14
+
15
+ # *** GET ***
16
+
17
+ #==getAll
18
+ # Gets all branches
19
+ # Returns an array of Hashes with the branch data
20
+
21
+ def self.getAll
22
+ url = "#{self.urlWithEntity}?key=#{self.apiKey}"
23
+ resp = Net::HTTP.get_response(URI.parse(url))
24
+ data = JSON.parse(resp.body)
25
+ end
26
+
27
+ #==getOne
28
+ # Gets one branch for a given ID
29
+ #= Parameters: AtmId
30
+ # Returns a hash with the ATM data
31
+
32
+ def self.getOne(id)
33
+ url = "#{self.urlWithEntity}/#{id}?key=#{self.apiKey}"
34
+ resp = Net::HTTP.get_response(URI.parse(url))
35
+ data = JSON.parse(resp.body)
36
+ end
35
37
  end
@@ -1,80 +1,113 @@
1
- class Customer
2
-
3
- def self.urlWithEntity
4
- return Config.baseUrl + "/customers"
5
- end
6
-
7
- def self.urlWithAcctEntity
8
- return Config.baseUrl + "/accounts"
9
- end
10
-
11
- def self.url
12
- return Config.baseUrl
13
- end
14
-
15
- def self.apiKey
16
- return Config.apiKey
17
- end
18
-
19
- # *** GET ***
20
- #==getAll
21
- #Gets all customers the API key has acccess to.
22
- #Returns an array of hashes.
23
- def self.getAll
24
- url = "#{self.urlWithEntity}?key=#{self.apiKey}"
25
- resp = Net::HTTP.get_response(URI.parse(url))
26
- data = JSON.parse(resp.body)
27
- return data
28
- end
29
-
30
- #==getOne
31
- #Gets the specified customer's information.
32
- #Parameters
33
- #tested - Returns a hash.
34
- def self.getOne(custId)
35
- url = "#{self.urlWithEntity}/#{custId}?key=#{self.apiKey}"
36
- resp = Net::HTTP.get_response(URI.parse(url))
37
- data = JSON.parse(resp.body)
38
- end
39
-
40
- #==getOneByAccountId
41
- #Get the customer for the given account.
42
- #Parameters: AccountId
43
- #Returns a hash with the specified customer data.
44
- def self.getOneByAccountId(accID)
45
- url = "#{self.urlWithAcctEntity}/#{accID}/customer?key=#{self.apiKey}"
46
- resp = Net::HTTP.get_response(URI.parse(url))
47
- data = JSON.parse(resp.body)
48
- end
49
-
50
-
51
- # *** PUT ***
52
- #==updateCustomer
53
- #Updates a customer by id with given json data.
54
- #Parameters: CustomerId, CustomerJson.
55
- #Json is as follows:
56
- # {
57
- # "address": {
58
- # "street_number": "",
59
- # "street_name": "",
60
- # "city": "",
61
- # "state": "",
62
- # "zip": ""
63
- # }
64
- # }
65
- #Returns http response code.
66
- def self.updateCustomer(custID, customer)
67
- customerToUpdate = customer.to_json
68
- url = "#{self.urlWithEntity}/#{custID}?key=#{self.apiKey}"
69
- uri = URI.parse(url)
70
- http = Net::HTTP.new(uri.host, uri.port)
71
- key = "?key=#{self.apiKey}"
72
- request = Net::HTTP::Put.new(uri.path+key, initheader = {'Content-Type' =>'application/json'})
73
- request.body = customerToUpdate
74
- response = http.request(request)
75
- return JSON.parse(response.body)
76
- end
77
-
78
- #
79
-
1
+ class Customer
2
+
3
+ def self.urlWithEntity
4
+ return Config.baseUrl + "/customers"
5
+ end
6
+
7
+ def self.urlWithAcctEntity
8
+ return Config.baseUrl + "/accounts"
9
+ end
10
+
11
+ def self.url
12
+ return Config.baseUrl
13
+ end
14
+
15
+ def self.apiKey
16
+ return Config.apiKey
17
+ end
18
+
19
+ # *** GET ***
20
+
21
+ #== getAll
22
+ # Gets all customers the API key has acccess to.
23
+ # Returns an array of hashes.
24
+
25
+ def self.getAll
26
+ url = "#{self.urlWithEntity}?key=#{self.apiKey}"
27
+ resp = Net::HTTP.get_response(URI.parse(url))
28
+ data = JSON.parse(resp.body)
29
+ return data
30
+ end
31
+
32
+ #== getOne
33
+ # Gets the specified customer's information.
34
+ #= Parameters: CustomerId
35
+ # Returns a Hash with the customer data
36
+
37
+ def self.getOne(custId)
38
+ url = "#{self.urlWithEntity}/#{custId}?key=#{self.apiKey}"
39
+ resp = Net::HTTP.get_response(URI.parse(url))
40
+ data = JSON.parse(resp.body)
41
+ end
42
+
43
+ #== getOneByAccountId
44
+ # Get the customer for the given account.
45
+ #= Parameters: AccountId
46
+ # Returns a hash with the specified customer data.
47
+
48
+ def self.getOneByAccountId(accID)
49
+ url = "#{self.urlWithAcctEntity}/#{accID}/customer?key=#{self.apiKey}"
50
+ resp = Net::HTTP.get_response(URI.parse(url))
51
+ data = JSON.parse(resp.body)
52
+ end
53
+
54
+ # *** POST ***
55
+
56
+ #==createCustomer
57
+ # Creates a new customer with the given json data
58
+ #= Parameters: CustomerHash
59
+ # JSON is as follows:
60
+ # {
61
+ # "first_name": "string",
62
+ # "last_name": "string",
63
+ # "address": {
64
+ # "street_number": "string",
65
+ # "street_name": "",
66
+ # "city": "",
67
+ # "state": "",
68
+ # "zip": ""
69
+ # }
70
+ # }
71
+ # Returns http response code
72
+
73
+ def self.createCustomer(customer)
74
+ url = "#{self.urlWithEntity}?key=#{self.apiKey}"
75
+ uri = URI.parse(url)
76
+ http = Net::HTTP.new(uri.host, uri.port)
77
+ request = Net::HTTP::Post.new(uri.request_uri, initheader = {'Content-Type' =>'application/json'})
78
+ request.body = customer.to_json
79
+ response = http.request(request)
80
+ return JSON.parse(response.body)
81
+ end
82
+
83
+
84
+ # *** PUT ***
85
+
86
+ #== updateCustomer
87
+ # Updates a customer by id with given json data.
88
+ #= Parameters: CustomerId, CustomerHash.
89
+ # Json is as follows:
90
+ # {
91
+ # "address": {
92
+ # "street_number": "",
93
+ # "street_name": "",
94
+ # "city": "",
95
+ # "state": "",
96
+ # "zip": ""
97
+ # }
98
+ # }
99
+ # Returns http response code.
100
+
101
+ def self.updateCustomer(custID, customer)
102
+ customerToUpdate = customer.to_json
103
+ url = "#{self.urlWithEntity}/#{custID}?key=#{self.apiKey}"
104
+ uri = URI.parse(url)
105
+ http = Net::HTTP.new(uri.host, uri.port)
106
+ key = "?key=#{self.apiKey}"
107
+ request = Net::HTTP::Put.new(uri.path+key, initheader = {'Content-Type' =>'application/json'})
108
+ request.body = customerToUpdate
109
+ response = http.request(request)
110
+ return JSON.parse(response.body)
111
+ end
112
+
80
113
  end
@@ -1,77 +1,110 @@
1
- class Deposit
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
- # *** GET ***
17
- #==getAllByAccountId
18
- #Get all deposits for a specific account
19
- #Returns an array of hashes.
20
- #Parameters: AccountID
21
- #Returns an array of hashes containing the deposits for that account.
22
- def self.getAllByAccountId(accID)
23
- url = "#{self.urlWithEntity}/#{accID}/deposits?key=#{self.apiKey}"
24
- resp = Net::HTTP.get_response(URI.parse(url))
25
- data = JSON.parse(resp.body)
26
- return data
27
- end
28
-
29
- #==getOneByAccountIdDepositId
30
- # Get a specific deposit from a specific account.
31
- #Parameters: AccountID, DepositID
32
- # Returns a hash with the specified deposit
33
-
34
- def self.getOneByAccountIdDepositId(accID, depositID)
35
- url = "#{self.urlWithEntity}/#{accID}/deposits/#{depositID}?key=#{self.apiKey}"
36
- resp = Net::HTTP.get_response(URI.parse(url))
37
- data = JSON.parse(resp.body)
38
- end
39
-
40
-
41
- # *** POST ***
42
-
43
- # Create a new deposit into an account
44
- #==createDeposit
45
- #Creates a new deposit.
46
- #Parameters: toAccountId, hashWithDepositData
47
- #Returns http response code.
48
- def self.createDeposit(toAcc, deposit)
49
- depositToCreate = deposit.to_json
50
- url = "#{self.urlWithEntity}/#{toAcc}/deposits?key=#{self.apiKey}"
51
- uri = URI.parse(url)
52
- http = Net::HTTP.new(uri.host, uri.port)
53
- request = Net::HTTP::Post.new(uri.request_uri, initheader = {'Content-Type' => 'application/json'})
54
- request.body = depositToCreate
55
- resp = http.request(request)
56
- data = JSON.parse(resp.body)
57
- end
58
-
59
-
60
- # *** DELETE ***
61
-
62
- #==deleteDeposit
63
- #Deletes a specified deposit from a specified account.
64
- #Parameters: accountID, depositID
65
- #Returns http response code.
66
- #=Note:
67
- #This does not actually delete the deposit from the database, it only sets it's
68
- #status to 'cancelled'
69
- def self.deleteDeposit(accID, depositID)
70
- url = "#{self.urlWithEntity}/#{accID}/deposits/#{depositID}?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::Delete.new(uri.path+key)
75
- resp = http.request(request)
76
- end
1
+ class Deposit
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
+ # *** GET ***
17
+ #==getAllByAccountId
18
+ # Get all deposits for a specific account
19
+ #= Parameters: AccountID
20
+ # Returns an array of hashes containing the deposits for that account.
21
+
22
+ def self.getAllByAccountId(accID)
23
+ url = "#{self.urlWithEntity}/#{accID}/deposits?key=#{self.apiKey}"
24
+ resp = Net::HTTP.get_response(URI.parse(url))
25
+ data = JSON.parse(resp.body)
26
+ return data
27
+ end
28
+
29
+
30
+ #==getOne
31
+ # Returns a deposit for a given ID
32
+ #= Parameters: DepositId
33
+ # Returns a hash with the deposit data
34
+ def self.getOne(id)
35
+ url = "#{self.url}/deposits/#{id}?key=#{self.apiKey}"
36
+ resp = Net::HTTP.get_response(URI.parse(url))
37
+ data = JSON.parse(resp.body)
38
+ end
39
+
40
+
41
+ # *** POST ***
42
+
43
+ #==createDeposit
44
+ # Creates a new deposit.
45
+ # Parameters: toAccountId, DepositHash
46
+ # DepositHash is formatted as follows:
47
+ # {
48
+ # "medium": "balance",
49
+ # "transaction_date": "string",
50
+ # "status": "pending",
51
+ # "amount": 0,
52
+ # "description": "string"
53
+ # }
54
+ # Returns http response code.
55
+
56
+ def self.createDeposit(toAcc, deposit)
57
+ depositToCreate = deposit.to_json
58
+ url = "#{self.urlWithEntity}/#{toAcc}/deposits?key=#{self.apiKey}"
59
+ uri = URI.parse(url)
60
+ http = Net::HTTP.new(uri.host, uri.port)
61
+ request = Net::HTTP::Post.new(uri.request_uri, initheader = {'Content-Type' => 'application/json'})
62
+ request.body = depositToCreate
63
+ resp = http.request(request)
64
+ data = JSON.parse(resp.body)
65
+ end
66
+
67
+
68
+ # *** PUT ***
69
+
70
+ #==updateDeposit
71
+ # Updates an existing deposit
72
+ #= Parameters: DepositId, DepositHash
73
+ # DepositHash is formatted as follows:
74
+ # {
75
+ # "medium": "balance",
76
+ # "transaction_date": "string",
77
+ # "status": "pending",
78
+ # "amount": 0,
79
+ # "description": "string"
80
+ # }
81
+ # Returns http response code
82
+
83
+ def self.updateDeposit(id, deposit)
84
+ depositToUpdate = deposit.to_json
85
+ url = "#{self.url}/deposits/#{id}?key=#{self.apiKey}"
86
+ uri = URI.parse(url)
87
+ http = Net::HTTP.new(uri.host, uri.port)
88
+ key = "?key=#{self.apiKey}"
89
+ request = Net::HTTP::Put.new(uri.path+key, initheader = {'Content-Type' =>'application/json'})
90
+ request.body = depositToUpdate
91
+ response = http.request(request)
92
+ return JSON.parse(response.body)
93
+ end
94
+
95
+ # *** DELETE ***
96
+
97
+ #==deleteDeposit
98
+ # Deletes an existing deposit
99
+ #= Parameters: DepositId
100
+ # Returns http response code
101
+
102
+ def self.deleteDeposit(id)
103
+ url = "#{self.url}/deposits/#{id}?key=#{self.apiKey}"
104
+ uri = URI.parse(url)
105
+ http = Net::HTTP.new(uri.host, uri.port)
106
+ key="?key=#{self.apiKey}"
107
+ request = Net::HTTP::Delete.new(uri.path+key)
108
+ resp = http.request(request)
109
+ end
77
110
  end