ebanc 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/ebanc.rb +227 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ce3dca5e17e43b139b030a39ec2c644fad80aa80
|
4
|
+
data.tar.gz: eb7f023c7061a02acf02960b3ab6864d4c8d6b9a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d5d89f7f2ef15c619ccd1626efb0e856edf6b7165896d24f2b2897b141d3b8520dd68f394790180a143ad1dbf0618f7b070bb62d865bea0fd74650c1e6e1b10d
|
7
|
+
data.tar.gz: 8c3fdf4825e92482a34c2f4af46b4303ba7b92be7022a960c34a914fe33ce975e4e799c410539004847c84cde64d71a0ea805e43971788248ae70d3483863b67
|
data/lib/ebanc.rb
ADDED
@@ -0,0 +1,227 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'net/http'
|
4
|
+
require 'net/https'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
class Ebanc
|
8
|
+
def initialize(api_key, gateway_id)
|
9
|
+
@api_key = api_key
|
10
|
+
@api_version = 2
|
11
|
+
@gateway_id = gateway_id
|
12
|
+
@server = 'https://' + gateway_id + '.ebanccorp.com'
|
13
|
+
@ebanc_url = @server + '/api/v' + @api_version.to_s
|
14
|
+
@use_ssl = true
|
15
|
+
@error_message = ''
|
16
|
+
end
|
17
|
+
|
18
|
+
# Class Getters and Setters
|
19
|
+
|
20
|
+
def server=(value)
|
21
|
+
@ebanc_url = value + '/api/v' + @api_version.to_s
|
22
|
+
@server = value
|
23
|
+
end
|
24
|
+
|
25
|
+
def server
|
26
|
+
@server
|
27
|
+
end
|
28
|
+
|
29
|
+
def use_ssl=(value)
|
30
|
+
@use_ssl = value
|
31
|
+
end
|
32
|
+
|
33
|
+
def use_ssl
|
34
|
+
@use_ssl
|
35
|
+
end
|
36
|
+
|
37
|
+
def api_version=(value)
|
38
|
+
@ebanc_url = @server + '/api/v' + value.to_s
|
39
|
+
@api_version = value
|
40
|
+
end
|
41
|
+
|
42
|
+
def api_version
|
43
|
+
@api_version
|
44
|
+
end
|
45
|
+
|
46
|
+
def error
|
47
|
+
@error_message
|
48
|
+
end
|
49
|
+
|
50
|
+
#--------------------------------
|
51
|
+
# API endpoints
|
52
|
+
#--------------------------------
|
53
|
+
|
54
|
+
# Customers
|
55
|
+
def customers
|
56
|
+
m_customers = query_api(@ebanc_url + '/customers')
|
57
|
+
|
58
|
+
if m_customers['customers'].length == 0
|
59
|
+
@error_message = 'No customers found'
|
60
|
+
end
|
61
|
+
|
62
|
+
m_customers['customers']
|
63
|
+
end
|
64
|
+
|
65
|
+
def create_customer(customer = {})
|
66
|
+
if customer[:first_name] && customer[:last_name] && customer[:routing_number] && customer[:account_number]
|
67
|
+
params = URI.encode_www_form([["first_name", customer[:first_name]], ["last_name", customer[:last_name]], ["routing_number", customer[:routing_number]], ["account_number", customer[:account_number]]])
|
68
|
+
|
69
|
+
customer = query_api(@ebanc_url + '/customers', 'post', params)
|
70
|
+
|
71
|
+
if customer['base']
|
72
|
+
@error_message = customer['base'].first
|
73
|
+
return false
|
74
|
+
else
|
75
|
+
return customer
|
76
|
+
end
|
77
|
+
else
|
78
|
+
@error_message = 'Not all needed fields were included'
|
79
|
+
return false
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def update_customer(customer = {})
|
84
|
+
if customer[:uuid] && customer[:first_name] && customer[:last_name]
|
85
|
+
params = URI.encode_www_form([["first_name", customer[:first_name]], ["last_name", customer[:last_name]], ["routing_number", customer[:routing_number]], ["account_number", customer[:account_number]]])
|
86
|
+
|
87
|
+
if customer[:routing_number]
|
88
|
+
params = params + '&' + URI.encode_www_form([["routing_number", customer[:routing_number]]])
|
89
|
+
end
|
90
|
+
|
91
|
+
if customer[:account_number]
|
92
|
+
params = params + '&' + URI.encode_www_form([["account_number", customer[:account_number]]])
|
93
|
+
end
|
94
|
+
|
95
|
+
if customer(customer[:uuid])
|
96
|
+
customer = query_api(@ebanc_url + '/customers/' + customer[:uuid], 'patch', params)
|
97
|
+
return customer
|
98
|
+
else
|
99
|
+
return false
|
100
|
+
end
|
101
|
+
else
|
102
|
+
@error_message = 'Not all needed fields were included'
|
103
|
+
return false
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def customer(uuid)
|
108
|
+
m_customer = query_api(@ebanc_url + '/customers/' + uuid)
|
109
|
+
|
110
|
+
if m_customer.length == 0
|
111
|
+
@error_message = 'Customer not found'
|
112
|
+
return false
|
113
|
+
else
|
114
|
+
return m_customer
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# Transactions
|
119
|
+
def transactions
|
120
|
+
m_transactions = query_api(@ebanc_url + '/transactions')
|
121
|
+
|
122
|
+
if m_transactions['transactions'].length == 0
|
123
|
+
@error_message = 'No transactions found'
|
124
|
+
end
|
125
|
+
|
126
|
+
m_transactions['transactions']
|
127
|
+
end
|
128
|
+
|
129
|
+
def create_transaction(transaction = {})
|
130
|
+
#if we are creating this transaction by passing in the information
|
131
|
+
if transaction[:first_name] && transaction[:last_name] && transaction[:routing_number] && transaction[:account_number] && transaction[:amount]
|
132
|
+
params = URI.encode_www_form([["first_name", transaction[:first_name]], ["last_name", transaction[:last_name]], ["routing_number", transaction[:routing_number]], ["account_number", transaction[:account_number]], ["amount", transaction[:amount]]])
|
133
|
+
|
134
|
+
if transaction[:category]
|
135
|
+
params = params + '&' + URI.encode_www_form([["category", transaction[:category]]])
|
136
|
+
end
|
137
|
+
|
138
|
+
if transaction[:memo]
|
139
|
+
params = params + '&' + URI.encode_www_form([["memo", transaction[:memo]]])
|
140
|
+
end
|
141
|
+
|
142
|
+
m_transation = query_api(@ebanc_url + '/transactions', 'post', params)
|
143
|
+
|
144
|
+
if m_transation['base']
|
145
|
+
@error_message = m_transation['base'].first
|
146
|
+
return false
|
147
|
+
else
|
148
|
+
return m_transation
|
149
|
+
end
|
150
|
+
else
|
151
|
+
@error_message = 'Not all needed fields were included'
|
152
|
+
return false
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def create_transaction_from_customer(transaction = {})
|
157
|
+
#if we are creating this transaction by passing in the information
|
158
|
+
if transaction[:customer_uuid] && transaction[:amount]
|
159
|
+
params = URI.encode_www_form([["customer_uuid", transaction[:customer_uuid]], ["amount", transaction[:amount]]])
|
160
|
+
params = 'customer_uuid=' + transaction[:customer_uuid] + '&amount=' + transaction[:amount]
|
161
|
+
|
162
|
+
if transaction[:category]
|
163
|
+
params = params + '&' + URI.encode_www_form([["category", transaction[:category]]])
|
164
|
+
end
|
165
|
+
|
166
|
+
if transaction[:memo]
|
167
|
+
params = params + '&' + URI.encode_www_form([["memo", transaction[:memo]]])
|
168
|
+
end
|
169
|
+
|
170
|
+
m_transation = query_api(@ebanc_url + '/transactions', 'post', params)
|
171
|
+
|
172
|
+
if m_transation['base']
|
173
|
+
@error_message = m_transation['base'].first
|
174
|
+
return false
|
175
|
+
else
|
176
|
+
return m_transation
|
177
|
+
end
|
178
|
+
else
|
179
|
+
@error_message = 'Not all needed fields were included'
|
180
|
+
return false
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def transaction(uuid)
|
185
|
+
m_transaction = query_api(@ebanc_url + '/transactions/' + uuid)
|
186
|
+
|
187
|
+
if m_transaction.length == 0
|
188
|
+
@error_message = 'Transaction not found'
|
189
|
+
return false
|
190
|
+
else
|
191
|
+
return m_transaction
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
#--------------------------------
|
196
|
+
# Utility Methods
|
197
|
+
#--------------------------------
|
198
|
+
private
|
199
|
+
|
200
|
+
def query_api(url, req_type='get', fields=nil)
|
201
|
+
@error_message = '';
|
202
|
+
|
203
|
+
uri = URI.parse(url)
|
204
|
+
https = Net::HTTP.new(uri.host,uri.port)
|
205
|
+
https.use_ssl = @use_ssl
|
206
|
+
req = nil
|
207
|
+
|
208
|
+
if req_type == 'patch'
|
209
|
+
req = Net::HTTP::Patch.new(uri.path, initheader = {'Authorization' => "Token token=\"" + @api_key + "\""})
|
210
|
+
elsif req_type == 'post'
|
211
|
+
req = Net::HTTP::Post.new(uri.path, initheader = {'Authorization' => "Token token=\"" + @api_key + "\""})
|
212
|
+
else
|
213
|
+
req = Net::HTTP::Get.new(uri.path, initheader = {'Authorization' => "Token token=\"" + @api_key + "\""})
|
214
|
+
end
|
215
|
+
|
216
|
+
if fields
|
217
|
+
req.body = fields
|
218
|
+
end
|
219
|
+
res = https.request(req)
|
220
|
+
|
221
|
+
if res.code == 401
|
222
|
+
raise "eBanc API access denied"
|
223
|
+
end
|
224
|
+
|
225
|
+
JSON.parse res.body
|
226
|
+
end
|
227
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ebanc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kevin Kaske
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-03 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: eBanc is the best way to send and recieve ACH transactions. See more
|
14
|
+
at http://ebanccorp.com/
|
15
|
+
email: kevinkaske@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/ebanc.rb
|
21
|
+
homepage: http://ebanccorp.com/api
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.2.2
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: Ruby bindings for the eBanc API
|
45
|
+
test_files: []
|