synapse_fi 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/Gemfile +1 -0
- data/Gemfile.lock +15 -9
- data/README.md +12 -1
- data/Rakefile +1 -1
- data/lib/synapse_api/client.rb +66 -59
- data/lib/synapse_api/error.rb +0 -27
- data/lib/synapse_api/http_request.rb +12 -3
- data/lib/synapse_api/user.rb +130 -87
- data/lib/synapse_api/version.rb +1 -1
- data/lib/synapse_fi.rb +28 -0
- data/pkg/synapse_fi-0.0.3.gem +0 -0
- data/samples.md +260 -247
- metadata +4 -14
- data/.DS_Store +0 -0
- data/node_modules/.yarn-integrity +0 -16
- data/node_modules/dotenv/CHANGELOG.md +0 -117
- data/node_modules/dotenv/LICENSE +0 -23
- data/node_modules/dotenv/README.md +0 -295
- data/node_modules/dotenv/config.js +0 -11
- data/node_modules/dotenv/lib/cli-options.js +0 -13
- data/node_modules/dotenv/lib/env-options.js +0 -18
- data/node_modules/dotenv/lib/main.js +0 -103
- data/node_modules/dotenv/package.json +0 -45
- data/package.json +0 -5
- data/synapse_fi-0.0.2.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8cc51024fe0828282d58774469281168581763a1
|
4
|
+
data.tar.gz: d22606acecf1fad82d2fa6dc0cf4ab4a09ca277a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1306539458898b0f9431f245a6c4dc78c69e9870c9c3a43e476cef037114145ccad809b99a965d4213e7543df88c1298ba5d39e931ccefd5b704c730ccc7a0a4
|
7
|
+
data.tar.gz: '08f46888c70fa12e9025171c8553770979d20e48f693849c4081004042fbe324dbe42049f68c34cb765fae657537fb2f5db0a5615a25be434ad9ce878b09cfdc'
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
synapse_fi (0.0.3)
|
5
|
+
rest-client (~> 2.0)
|
6
|
+
|
1
7
|
GEM
|
2
8
|
remote: https://rubygems.org/
|
3
9
|
specs:
|
@@ -5,26 +11,25 @@ GEM
|
|
5
11
|
builder (3.2.3)
|
6
12
|
domain_name (0.5.20180417)
|
7
13
|
unf (>= 0.0.5, < 1.0.0)
|
8
|
-
dotenv (2.
|
14
|
+
dotenv (2.1.2)
|
9
15
|
http-cookie (1.0.3)
|
10
16
|
domain_name (~> 0.5)
|
11
17
|
mime-types (3.2.2)
|
12
18
|
mime-types-data (~> 3.2015)
|
13
19
|
mime-types-data (3.2018.0812)
|
14
|
-
minitest (5.
|
15
|
-
minitest-reporters (1.
|
20
|
+
minitest (5.8.5)
|
21
|
+
minitest-reporters (1.1.19)
|
16
22
|
ansi
|
17
23
|
builder
|
18
24
|
minitest (>= 5.0)
|
19
25
|
ruby-progressbar
|
20
26
|
netrc (0.11.0)
|
27
|
+
rake (10.5.0)
|
21
28
|
rest-client (2.0.2)
|
22
29
|
http-cookie (>= 1.0.2, < 2.0)
|
23
30
|
mime-types (>= 1.16, < 4.0)
|
24
31
|
netrc (~> 0.8)
|
25
32
|
ruby-progressbar (1.10.0)
|
26
|
-
synapse_pay_rest (3.4.3)
|
27
|
-
rest-client (~> 2.0)
|
28
33
|
unf (0.1.4)
|
29
34
|
unf_ext
|
30
35
|
unf_ext (0.0.7.5)
|
@@ -34,10 +39,11 @@ PLATFORMS
|
|
34
39
|
|
35
40
|
DEPENDENCIES
|
36
41
|
bundler
|
37
|
-
dotenv
|
38
|
-
minitest
|
39
|
-
minitest-reporters
|
40
|
-
|
42
|
+
dotenv (~> 2.1.1)
|
43
|
+
minitest (~> 5.8.2)
|
44
|
+
minitest-reporters (~> 1.1.5)
|
45
|
+
rake (~> 10.0)
|
46
|
+
synapse_fi!
|
41
47
|
|
42
48
|
BUNDLED WITH
|
43
49
|
1.17.1
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# SynapseFI-Ruby-v2
|
2
2
|
|
3
|
-
Native API library for
|
3
|
+
Native API library for SynapseFI REST v3.x
|
4
4
|
|
5
5
|
Not all API endpoints are supported.
|
6
6
|
|
@@ -32,6 +32,17 @@ $ gem install synapse_fi
|
|
32
32
|
|
33
33
|
For minor issues, please open a pull request. For larger changes or features, please email hello@synapsepay.com. Please document and test any public constants/methods.
|
34
34
|
|
35
|
+
## Running the Test Suite
|
36
|
+
|
37
|
+
If you haven't already, set the `TEST_CLIENT_ID` and `TEST_CLIENT_SECRET` environment variables in `.env` file .
|
38
|
+
Please read and update test files with your user own test id's
|
39
|
+
|
40
|
+
To run all tests, execute:
|
41
|
+
|
42
|
+
```bash
|
43
|
+
rake test
|
44
|
+
```
|
45
|
+
|
35
46
|
## License
|
36
47
|
|
37
48
|
[MIT License](LICENSE)
|
data/Rakefile
CHANGED
data/lib/synapse_api/client.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'json'
|
2
1
|
require_relative './http_request'
|
3
2
|
require_relative './user'
|
4
3
|
require_relative './users'
|
@@ -12,8 +11,6 @@ require_relative './subnet'
|
|
12
11
|
require_relative './subnets'
|
13
12
|
require 'pp'
|
14
13
|
|
15
|
-
|
16
|
-
|
17
14
|
module Synapse
|
18
15
|
# Initializes various wrapper settings such as development mode and request
|
19
16
|
# header values
|
@@ -29,7 +26,6 @@ module Synapse
|
|
29
26
|
# Alias for #http_client
|
30
27
|
alias_method :client, :http_client
|
31
28
|
|
32
|
-
|
33
29
|
# @param client_id [String] should be stored in environment variable
|
34
30
|
# @param client_secret [String] should be stored in environment variable
|
35
31
|
# @param ip_address [String] user's IP address
|
@@ -52,7 +48,8 @@ module Synapse
|
|
52
48
|
fingerprint: fingerprint,
|
53
49
|
ip_address: ip_address,
|
54
50
|
raise_for_202: raise_for_202,
|
55
|
-
**options
|
51
|
+
**options
|
52
|
+
)
|
56
53
|
end
|
57
54
|
|
58
55
|
# Queries Synapse API to create a new user
|
@@ -63,14 +60,12 @@ module Synapse
|
|
63
60
|
def create_user(payload:, **options)
|
64
61
|
response = client.post(user_path,payload, options)
|
65
62
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
)
|
73
|
-
user
|
63
|
+
User.new(user_id: response['_id'],
|
64
|
+
refresh_token: response['refresh_token'],
|
65
|
+
client: client,
|
66
|
+
full_dehydrate: "no",
|
67
|
+
payload: response
|
68
|
+
)
|
74
69
|
end
|
75
70
|
|
76
71
|
# Update headers in HTTPClient class
|
@@ -97,14 +92,12 @@ module Synapse
|
|
97
92
|
path = user_path(user_id: user_id, full_dehydrate: options[:full_dehydrate])
|
98
93
|
response = client.get(path)
|
99
94
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
)
|
107
|
-
user
|
95
|
+
User.new(user_id: response['_id'],
|
96
|
+
refresh_token: response['refresh_token'],
|
97
|
+
client: client,
|
98
|
+
full_dehydrate: options[:full_dehydrate] == "yes" ? true : false,
|
99
|
+
payload: response
|
100
|
+
)
|
108
101
|
end
|
109
102
|
|
110
103
|
# Queries Synapse API for platform users
|
@@ -112,16 +105,24 @@ module Synapse
|
|
112
105
|
# users with matching name/email
|
113
106
|
# @param page [Integer] (optional) response will default to 1
|
114
107
|
# @param per_page [Integer] (optional) response will default to 20
|
115
|
-
# @note users created this way are not automatically OAuthed
|
116
108
|
# @return [Array<Synapse::Users>]
|
117
109
|
def get_users(**options)
|
118
110
|
path = user_path(options)
|
119
111
|
response = client.get(path)
|
120
112
|
return [] if response["users"].empty?
|
121
|
-
users = response["users"].map { |user_data| User.new(user_id:
|
122
|
-
|
123
|
-
|
124
|
-
|
113
|
+
users = response["users"].map { |user_data| User.new(user_id: user_data['_id'],
|
114
|
+
refresh_token: user_data['refresh_token'],
|
115
|
+
client: client,
|
116
|
+
full_dehydrate: "no",
|
117
|
+
payload: user_data
|
118
|
+
)}
|
119
|
+
Users.new(limit: response["limit"],
|
120
|
+
page: response["page"],
|
121
|
+
page_count: response["page_count"],
|
122
|
+
user_count: response["user_count"],
|
123
|
+
payload: users,
|
124
|
+
http_client: client
|
125
|
+
)
|
125
126
|
end
|
126
127
|
|
127
128
|
# Queries Synapse for all transactions on platform
|
@@ -141,9 +142,12 @@ module Synapse
|
|
141
142
|
|
142
143
|
return [] if trans["trans"].empty?
|
143
144
|
response = trans["trans"].map { |trans_data| Transaction.new(trans_id: trans_data['_id'], payload: trans_data)}
|
144
|
-
|
145
|
-
|
146
|
-
|
145
|
+
Transactions.new(limit: trans["limit"],
|
146
|
+
page: trans["page"],
|
147
|
+
page_count: trans["page_count"],
|
148
|
+
trans_count: trans["trans_count"],
|
149
|
+
payload: response
|
150
|
+
)
|
147
151
|
end
|
148
152
|
|
149
153
|
# Queries Synapse API for all nodes belonging to platform
|
@@ -160,8 +164,17 @@ module Synapse
|
|
160
164
|
nodes = client.get(path)
|
161
165
|
|
162
166
|
return [] if nodes["nodes"].empty?
|
163
|
-
response = nodes["nodes"].map { |node_data| Node.new(node_id:
|
164
|
-
|
167
|
+
response = nodes["nodes"].map { |node_data| Node.new(node_id: node_data['_id'],
|
168
|
+
user_id: node_data['user_id'],
|
169
|
+
payload: node_data,
|
170
|
+
full_dehydrate: "no"
|
171
|
+
)}
|
172
|
+
Nodes.new(limit: nodes["limit"],
|
173
|
+
page: nodes["page"],
|
174
|
+
page_count: nodes["page_count"],
|
175
|
+
nodes_count: nodes["node_count"],
|
176
|
+
payload: response
|
177
|
+
)
|
165
178
|
end
|
166
179
|
|
167
180
|
# Queries Synapse API for all institutions available for bank logins
|
@@ -173,18 +186,12 @@ module Synapse
|
|
173
186
|
end
|
174
187
|
|
175
188
|
# Queries Synapse API to create a webhook subscriptions for platform
|
176
|
-
# @param scope [
|
189
|
+
# @param scope [Hash]
|
177
190
|
# @param idempotency_key [String] (optional)
|
178
|
-
# @param url [String]
|
179
191
|
# @see https://docs.synapsefi.com/docs/create-subscription
|
180
192
|
# @return [Synapse::Subscription]
|
181
|
-
def create_subscriptions(scope:,
|
182
|
-
|
183
|
-
'scope' => scope,
|
184
|
-
'url' => url,
|
185
|
-
}
|
186
|
-
|
187
|
-
response = client.post(subscriptions_path , payload, options)
|
193
|
+
def create_subscriptions(scope:, **options)
|
194
|
+
response = client.post(subscriptions_path , scope, options)
|
188
195
|
|
189
196
|
Subscription.new(subscription_id: response["_id"], url: response["url"], payload: response)
|
190
197
|
end
|
@@ -197,11 +204,17 @@ module Synapse
|
|
197
204
|
subscriptions = client.get(subscriptions_path(options))
|
198
205
|
|
199
206
|
return [] if subscriptions["subscriptions"].empty?
|
200
|
-
response = subscriptions["subscriptions"].map { |subscription_data| Subscription.new(subscription_id: subscription_data["_id"],
|
201
|
-
|
207
|
+
response = subscriptions["subscriptions"].map { |subscription_data| Subscription.new(subscription_id: subscription_data["_id"],
|
208
|
+
url: subscription_data["url"],
|
209
|
+
payload: subscription_data)}
|
210
|
+
Subscriptions.new(limit: subscriptions["limit"],
|
211
|
+
page: subscriptions["page"],
|
212
|
+
page_count: subscriptions["page_count"],
|
213
|
+
subscriptions_count: subscriptions["subscription_count"],
|
214
|
+
payload: response
|
215
|
+
)
|
202
216
|
end
|
203
217
|
|
204
|
-
|
205
218
|
# Queries Synapse API for a subscription by subscription_id
|
206
219
|
# @param subscription_id [String]
|
207
220
|
# @return [Synapse::Subscription]
|
@@ -211,34 +224,30 @@ module Synapse
|
|
211
224
|
Subscription.new(subscription_id: response["_id"], url: response["url"], payload: response)
|
212
225
|
end
|
213
226
|
|
214
|
-
#
|
227
|
+
# Updates subscription platform subscription
|
215
228
|
# @param subscription_id [String]
|
216
|
-
# @param
|
217
|
-
# @param url [String]
|
218
|
-
# @param scope [Array<String>]
|
229
|
+
# @param body [Hash]
|
219
230
|
# see https://docs.synapsefi.com/docs/update-subscription
|
220
231
|
# @return [Synapse::Subscription]
|
221
|
-
def update_subscriptions(subscription_id:,
|
232
|
+
def update_subscriptions(subscription_id:, body:)
|
222
233
|
path = subscriptions_path + "/#{subscription_id}"
|
223
234
|
|
224
|
-
|
225
|
-
|
226
|
-
payload["url"] = url if url
|
227
|
-
payload["scope"] = scope if scope
|
228
|
-
payload["is_active"] = is_active if is_active
|
229
|
-
|
230
|
-
response = client.patch(path, payload)
|
235
|
+
response = client.patch(path, body)
|
231
236
|
Subscription.new(subscription_id: response["_id"], url: response["url"], payload: response)
|
232
237
|
end
|
233
238
|
|
239
|
+
# Returns all of the webhooks belonging to client
|
240
|
+
# @return [Hash]
|
241
|
+
def webhook_logs()
|
242
|
+
path = subscriptions_path + "/logs"
|
243
|
+
client.get(path)
|
244
|
+
end
|
234
245
|
|
235
246
|
# Issues public key for client
|
236
|
-
# @param client [Synapse::Client]
|
237
247
|
# @param scope [String]
|
238
248
|
# @see https://docs.synapsefi.com/docs/issuing-public-key
|
239
249
|
# @note valid scope "OAUTH|POST,USERS|POST,USERS|GET,USER|GET,USER|PATCH,SUBSCRIPTIONS|GET,SUBSCRIPTIONS|POST,SUBSCRIPTION|GET,SUBSCRIPTION|PATCH,CLIENT|REPORTS,CLIENT|CONTROLS"
|
240
250
|
def issue_public_key(scope:)
|
241
|
-
raise ArgumentError, 'scope must be a string' unless scope.is_a?(String)
|
242
251
|
path = '/client?issue_public_key=YES'
|
243
252
|
path += "&scope=#{scope}"
|
244
253
|
response = client.get(path)
|
@@ -293,9 +302,7 @@ module Synapse
|
|
293
302
|
data
|
294
303
|
end
|
295
304
|
|
296
|
-
|
297
305
|
private
|
298
|
-
|
299
306
|
def user_path(user_id: nil, **options)
|
300
307
|
path = "/users"
|
301
308
|
path += "/#{user_id}" if user_id
|
data/lib/synapse_api/error.rb
CHANGED
@@ -16,28 +16,12 @@ module Synapse
|
|
16
16
|
# Raised on the HTTP status code 402
|
17
17
|
RequestDeclined = Class.new(ClientError)
|
18
18
|
|
19
|
-
# Raised on the HTTP status code 403
|
20
|
-
# Forbidden = Class.new(ClientError)
|
21
|
-
# '403' => Synapse::Error::Forbidden,
|
22
|
-
|
23
19
|
# Raised on the HTTP status code 404
|
24
20
|
NotFound = Class.new(ClientError)
|
25
21
|
|
26
|
-
# Raised on the HTTP status code 406
|
27
|
-
# NotAcceptable = Class.new(ClientError)
|
28
|
-
# '406' => Synapse::Error::NotAcceptable,
|
29
|
-
|
30
22
|
# Raised on the HTTP status code 409
|
31
23
|
Conflict = Class.new(ClientError)
|
32
24
|
|
33
|
-
# Raised on the HTTP status code 415
|
34
|
-
# UnsupportedMediaType = Class.new(ClientError)
|
35
|
-
# '415' => Synapse::Error::UnsupportedMediaType,
|
36
|
-
|
37
|
-
# Raised on the HTTP status code 422
|
38
|
-
# UnprocessableEntity = Class.new(ClientError)
|
39
|
-
# '422' => Synapse::Error::UnprocessableEntity,
|
40
|
-
|
41
25
|
# Raised on the HTTP status code 429
|
42
26
|
TooManyRequests = Class.new(ClientError)
|
43
27
|
|
@@ -47,21 +31,10 @@ module Synapse
|
|
47
31
|
# Raised on the HTTP status code 500
|
48
32
|
InternalServerError = Class.new(ServerError)
|
49
33
|
|
50
|
-
# Raised on the HTTP status code 502
|
51
|
-
# BadGateway = Class.new(ServerError)
|
52
|
-
# '502' => Synapse::Error::BadGateway,
|
53
|
-
|
54
34
|
# Raised on the HTTP status code 503
|
55
35
|
ServiceUnavailable = Class.new(ServerError)
|
56
36
|
|
57
|
-
# Raised on the HTTP status code 504
|
58
|
-
# GatewayTimeout = Class.new(ServerError)
|
59
|
-
# '504' => Synapse::Error::GatewayTimeout
|
60
|
-
|
61
37
|
# HTTP status code to Error subclass mapping
|
62
|
-
#
|
63
|
-
# @todo doesn't do well when there's an html response from nginx for bad gateway/timeout
|
64
|
-
|
65
38
|
ERRORS = {
|
66
39
|
'202' => Synapse::Error::Accepted,
|
67
40
|
'400' => Synapse::Error::BadRequest,
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'rest-client'
|
2
2
|
require 'open-uri'
|
3
3
|
require 'json'
|
4
|
-
require_relative './error'
|
5
4
|
|
6
5
|
module Synapse
|
7
6
|
# Wrapper for HTTP requests using RestClient.
|
@@ -93,7 +92,12 @@ module Synapse
|
|
93
92
|
headers = headers.merge({'X-SP-IDEMPOTENCY-KEY' => options[:idempotency_key]})
|
94
93
|
end
|
95
94
|
|
96
|
-
response = with_error_handling { RestClient::Request.execute(:method =>
|
95
|
+
response = with_error_handling { RestClient::Request.execute(:method => :post,
|
96
|
+
:url => full_url(path),
|
97
|
+
:payload => payload.to_json,
|
98
|
+
:headers => headers,
|
99
|
+
:timeout => 300
|
100
|
+
) }
|
97
101
|
puts 'RESPONSE:', JSON.parse(response) if @logging
|
98
102
|
response = JSON.parse(response)
|
99
103
|
|
@@ -148,7 +152,12 @@ module Synapse
|
|
148
152
|
# @return [Hash] API response
|
149
153
|
# @raise [Synapse::Error] subclass depends on HTTP response
|
150
154
|
def patch(path, payload)
|
151
|
-
response = with_error_handling {RestClient::Request.execute(:method =>
|
155
|
+
response = with_error_handling {RestClient::Request.execute(:method => :patch,
|
156
|
+
:url => full_url(path),
|
157
|
+
:payload => payload.to_json,
|
158
|
+
:headers => headers,
|
159
|
+
:timeout => 300
|
160
|
+
)}
|
152
161
|
p 'RESPONSE:', JSON.parse(response) if @logging
|
153
162
|
response = JSON.parse(response)
|
154
163
|
|