synapse_fi 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,7 +22,7 @@ module Synapse
22
22
  # @param payload [Hash]
23
23
  # @param full_dehydrate [Boolean]
24
24
  def initialize(user_id:,refresh_token:, client:,payload:, full_dehydrate:)
25
- @user_id = user_id
25
+ @user_id = user_id
26
26
  @client = client
27
27
  @refresh_token = refresh_token
28
28
  @payload =payload
@@ -34,29 +34,27 @@ module Synapse
34
34
  # @param payload [Hash]
35
35
  # @return [Synapse::User]
36
36
  def user_update(payload:)
37
- path = get_user_path(user_id: self.user_id)
37
+ path = get_user_path(user_id: self.user_id)
38
38
  begin
39
39
  response = client.patch(path, payload)
40
40
  rescue Synapse::Error::Unauthorized
41
41
  self.authenticate()
42
42
  response =client.patch(path, payload)
43
43
  end
44
- user = User.new(
45
- user_id: response['_id'],
46
- refresh_token: response['refresh_token'],
47
- client: client,
48
- full_dehydrate: false,
49
- payload: response
50
- )
51
-
52
- user
44
+ User.new(user_id: response['_id'],
45
+ refresh_token: response['refresh_token'],
46
+ client: client,
47
+ full_dehydrate: false,
48
+ payload: response
49
+ )
53
50
  end
54
51
 
55
52
  # Queries the API for a node belonging to user
56
53
  # @param node_id [String]
57
- # @param full_dehydrate [String] (optional) if true, returns all trans data on node
58
- # @param force_refresh [String] (optional) if true, force refresh yes will attempt updating the account balance and transactions
59
- # for ACH node
54
+ # @param full_dehydrate [String] (optional)
55
+ # if true, returns all trans data on node
56
+ # @param force_refresh [String] (optional) if true, force refresh
57
+ # will attempt updating the account balance and transactions on node
60
58
  # @return [Synapse::Node]
61
59
  def get_user_node(node_id:, **options)
62
60
  options[:full_dehydrate] = "yes" if options[:full_dehydrate] == true
@@ -64,7 +62,9 @@ module Synapse
64
62
  options[:force_refresh] = "yes" if options[:force_refresh] == true
65
63
  options[:force_refresh] = "no" if options[:force_refresh] == false
66
64
 
67
- path = node(node_id:node_id, full_dehydrate: options[:full_dehydrate],force_refresh: options[:force_refresh] )
65
+ path = node(node_id: node_id,
66
+ full_dehydrate: options[:full_dehydrate],
67
+ force_refresh: options[:force_refresh] )
68
68
 
69
69
  begin
70
70
  node = client.get(path)
@@ -75,12 +75,11 @@ module Synapse
75
75
  end
76
76
 
77
77
  node = Node.new(node_id: node['_id'],
78
- user_id: self.user_id,
79
- payload: node,
80
- full_dehydrate: options[:full_dehydrate] == "yes" ? true : false,
81
- type: node["type"]
82
- )
83
- node
78
+ user_id: self.user_id,
79
+ payload: node,
80
+ full_dehydrate: options[:full_dehydrate] == "yes" ? true : false,
81
+ type: node["type"]
82
+ )
84
83
  end
85
84
 
86
85
  # Queries Synapse API for all nodes belonging to user
@@ -105,19 +104,17 @@ module Synapse
105
104
  end
106
105
 
107
106
  return [] if nodes["nodes"].empty?
108
- response = nodes["nodes"].map { |node_data| Node.new(node_id: node_data['_id'], user_id: node_data['user_id'], payload: node_data, full_dehydrate: "no", type: node_data["type"])}
109
- nodes = Nodes.new(limit: nodes["limit"], page: nodes["page"], page_count: nodes["page_count"], nodes_count: nodes["node_count"], payload: response)
107
+ response = nodes["nodes"].map { |node_data| Node.new(node_id: node_data['_id'],
108
+ user_id: node_data['user_id'],
109
+ payload: node_data, full_dehydrate: "no",
110
+ type: node_data["type"])}
111
+ nodes = Nodes.new(limit: nodes["limit"],
112
+ page: nodes["page"],
113
+ page_count: nodes["page_count"],
114
+ nodes_count: nodes["node_count"],
115
+ payload: response)
110
116
  end
111
117
 
112
- # Queries Synapse get user API for users refresh_token
113
- # @see https://docs.synapsefi.com/docs/get-user
114
- # @return refresh_token [String]
115
- # def refresh_token()
116
- # path = get_user_path(user_id: self.user_id)
117
- # response = client.get(path)
118
- # response["refresh_token"]
119
- # end
120
-
121
118
  # Quaries Synapse oauth API for uto authenitcate user
122
119
  # @params scope [Array<Strings>] (optional)
123
120
  # @param idempotency_key [String] (optional)
@@ -148,9 +145,9 @@ module Synapse
148
145
  # @return API response [Hash]
149
146
  def select_2fa_device(device:, **options)
150
147
  payload = {
151
- "refresh_token": self.refresh_token,
152
- "phone_number": device
153
- }
148
+ "refresh_token": self.refresh_token,
149
+ "phone_number": device
150
+ }
154
151
  path = oauth_path()
155
152
  device_response = client.post(path, payload, options)
156
153
  device_response
@@ -164,9 +161,9 @@ module Synapse
164
161
  # @return API response [Hash]
165
162
  def confirm_2fa_pin(pin:, **options)
166
163
  payload = {
167
- "refresh_token": self.refresh_token,
168
- "validation_pin": pin
169
- }
164
+ "refresh_token": self.refresh_token,
165
+ "validation_pin": pin
166
+ }
170
167
 
171
168
  payload["scope"] = options[:scope] if options[:scope]
172
169
 
@@ -203,8 +200,15 @@ module Synapse
203
200
  end
204
201
 
205
202
 
206
- response = trans["trans"].map { |trans_data| Transaction.new(trans_id: trans_data['_id'], payload: trans_data)}
207
- trans = Transactions.new(limit: trans["limit"], page: trans["page"], page_count: trans["page_count"], trans_count: trans["trans_count"], payload: response)
203
+ response = trans["trans"].map { |trans_data| Transaction.new(trans_id: trans_data['_id'],
204
+ payload: trans_data
205
+ )}
206
+ trans = Transactions.new(limit: trans["limit"],
207
+ page: trans["page"],
208
+ page_count: trans["page_count"],
209
+ trans_count: trans["trans_count"],
210
+ payload: response
211
+ )
208
212
 
209
213
  trans
210
214
  end
@@ -227,12 +231,21 @@ module Synapse
227
231
  end
228
232
 
229
233
  if response["nodes"]
230
- nodes = response["nodes"].map { |nodes_data| Node.new(user_id: self.user_id, node_id: nodes_data["_id"], full_dehydrate: false, payload: response, type: nodes_data["type"])}
231
- nodes = Nodes.new(page: response["page"], limit: response["limit"], page_count: response["page_count"], nodes_count: response["node_count"], payload: nodes)
234
+ nodes = response["nodes"].map { |nodes_data| Node.new(user_id: self.user_id,
235
+ node_id: nodes_data["_id"],
236
+ full_dehydrate: false,
237
+ payload: response,
238
+ type: nodes_data["type"]
239
+ )}
240
+ nodes = Nodes.new(page: response["page"],
241
+ limit: response["limit"],
242
+ page_count: response["page_count"],
243
+ nodes_count: response["node_count"],
244
+ payload: nodes
245
+ )
232
246
  else
233
247
  access_token = response
234
248
  end
235
-
236
249
  access_token ? access_token : nodes
237
250
  end
238
251
 
@@ -254,16 +267,24 @@ module Synapse
254
267
  end
255
268
 
256
269
  if response["nodes"]
257
- nodes = response["nodes"].map { |nodes_data| Node.new(user_id: self.user_id, node_id: nodes_data["_id"], full_dehydrate: false, payload: response, type: nodes_data["type"])}
258
- nodes = Nodes.new(page: response["page"], limit: response["limit"], page_count: response["page_count"], nodes_count: response["node_count"], payload: nodes)
270
+ nodes = response["nodes"].map { |nodes_data| Node.new(user_id: self.user_id,
271
+ node_id: nodes_data["_id"],
272
+ full_dehydrate: false,
273
+ payload: response,
274
+ type: nodes_data["type"]
275
+ )}
276
+ nodes = Nodes.new(page: response["page"],
277
+ limit: response["limit"],
278
+ page_count: response["page_count"],
279
+ nodes_count: response["node_count"],
280
+ payload: nodes
281
+ )
259
282
  else
260
283
  access_token = response
261
284
  end
262
-
263
285
  access_token ? access_token : nodes
264
286
  end
265
287
 
266
-
267
288
  # Allows you to upload an Ultimate Beneficial Ownership document
268
289
  # @param payload [Hash]
269
290
  # @see https://docs.synapsefi.com/docs/generate-ubo-form
@@ -278,7 +299,6 @@ module Synapse
278
299
  self.authenticate()
279
300
  response = client.patch(path,payload)
280
301
  end
281
-
282
302
  response
283
303
  end
284
304
 
@@ -300,7 +320,6 @@ module Synapse
300
320
  self.authenticate()
301
321
  statements = client.get(path)
302
322
  end
303
-
304
323
  statements
305
324
  end
306
325
 
@@ -309,16 +328,18 @@ module Synapse
309
328
  # @param payload [Hash]
310
329
  # @return [Synapse::Node] or [Hash]
311
330
  def ship_card(node_id:, payload:)
312
-
313
331
  path = node(user_id: self.user_id, node_id: node_id) + "?ship=YES"
314
-
315
332
  begin
316
333
  response = client.patch(path,payload)
317
334
  rescue Synapse::Error::Unauthorized
318
335
  self.authenticate()
319
336
  response = client.patch(path,payload)
320
337
  end
321
- Node.new(user_id: self.user_id, node_id:response["_id"], full_dehydrate: false, payload: response, type: response["type"])
338
+ Node.new(user_id: self.user_id,
339
+ node_id: response["_id"],
340
+ full_dehydrate: false,
341
+ payload: response,
342
+ type: response["type"])
322
343
  end
323
344
 
324
345
  # Resets debit card number, cvv, and expiration date
@@ -334,7 +355,12 @@ module Synapse
334
355
  self.authenticate()
335
356
  response = client.patch(path,payload)
336
357
  end
337
- Node.new(user_id: self.user_id, node_id:response["_id"], full_dehydrate: false, payload: response, type: response["type"])
358
+ Node.new(user_id: self.user_id,
359
+ node_id:response["_id"],
360
+ full_dehydrate: false,
361
+ payload: response,
362
+ type: response["type"]
363
+ )
338
364
  end
339
365
 
340
366
  # Creates a new transaction in the API belonging to the provided node
@@ -351,7 +377,10 @@ module Synapse
351
377
  self.authenticate()
352
378
  transaction = client.post(path,payload, options)
353
379
  end
354
- transaction = Transaction.new(trans_id: transaction['_id'], payload: transaction, node_id: node_id)
380
+ transaction = Transaction.new(trans_id: transaction['_id'],
381
+ payload: transaction,
382
+ node_id: node_id
383
+ )
355
384
  end
356
385
 
357
386
  # Queries the API for a transaction belonging to the supplied node by transaction id
@@ -367,8 +396,10 @@ module Synapse
367
396
  self.authenticate()
368
397
  trans = client.get(path)
369
398
  end
370
- transaction = Transaction.new(trans_id: trans['_id'], payload: trans, node_id: node_id)
371
- transaction
399
+ Transaction.new(trans_id: trans['_id'],
400
+ payload: trans,
401
+ node_id: node_id
402
+ )
372
403
  end
373
404
 
374
405
 
@@ -400,9 +431,16 @@ module Synapse
400
431
  end
401
432
 
402
433
 
403
- response = trans["trans"].map { |trans_data| Transaction.new(trans_id: trans_data['_id'], payload: trans_data, node_id: node_id)}
404
- trans = Transactions.new(limit: trans["limit"], page: trans["page"], page_count: trans["page_count"], trans_count: trans["trans_count"], payload: response)
405
- trans
434
+ response = trans["trans"].map { |trans_data| Transaction.new(trans_id: trans_data['_id'],
435
+ payload: trans_data,
436
+ node_id: node_id
437
+ )}
438
+ Transactions.new(limit: trans["limit"],
439
+ page: trans["page"],
440
+ page_count: trans["page_count"],
441
+ trans_count: trans["trans_count"],
442
+ payload: response
443
+ )
406
444
  end
407
445
 
408
446
  # Verifies microdeposits for a node
@@ -416,7 +454,12 @@ module Synapse
416
454
  self.authenticate()
417
455
  response = client.patch(path, payload)
418
456
  end
419
- Node.new(user_id: self.user_id, node_id:response["_id"], full_dehydrate: false, payload: response, type: response["type"])
457
+ Node.new(user_id: self.user_id,
458
+ node_id: response["_id"],
459
+ full_dehydrate: false,
460
+ payload: response,
461
+ type: response["type"]
462
+ )
420
463
  end
421
464
 
422
465
  # Reinitiate microdeposits on a node
@@ -430,7 +473,11 @@ module Synapse
430
473
  self.authenticate()
431
474
  response = client.patch(path, payload)
432
475
  end
433
- Node.new(user_id: self.user_id, node_id:response["_id"], full_dehydrate: false, payload: response, type: response["type"])
476
+ Node.new(user_id: self.user_id,
477
+ node_id: response["_id"],
478
+ full_dehydrate: false,
479
+ payload: response,
480
+ type: response["type"])
434
481
  end
435
482
 
436
483
  # Generate tokenized info for Apple Wallet
@@ -462,12 +509,12 @@ module Synapse
462
509
  self.authenticate()
463
510
  update = client.patch(path, payload)
464
511
  end
465
- update = Node.new(node_id: node_id,
466
- user_id: self.user_id,
467
- payload: update,
468
- full_dehydrate: false,
469
- type: update["type"]
470
- )
512
+ Node.new(node_id: node_id,
513
+ user_id: self.user_id,
514
+ payload: update,
515
+ full_dehydrate: false,
516
+ type: update["type"]
517
+ )
471
518
  end
472
519
 
473
520
  def delete_node(node_id:)
@@ -487,9 +534,9 @@ module Synapse
487
534
  # @param is_credit [Boolean], for credit send true, for debit send false
488
535
  # @see https://docs.synapsefi.com/docs/trigger-dummy-transactions
489
536
  def dummy_transactions(node_id:, is_credit: nil)
490
-
491
537
  is_credit = "YES" if is_credit == true
492
538
  is_credit = "NO" if is_credit == false
539
+
493
540
  if is_credit
494
541
  path = node(user_id: self.user_id, node_id: node_id) + "/dummy-tran?#{is_credit}"
495
542
  else
@@ -511,7 +558,6 @@ module Synapse
511
558
  # @param payload [Hash]
512
559
  # @return [Synapse::Transaction]
513
560
  def comment_transaction(node_id:,trans_id:,payload:)
514
-
515
561
  path = trans_path(user_id: self.user_id, node_id: node_id) + "/#{trans_id}"
516
562
 
517
563
  begin
@@ -520,8 +566,7 @@ module Synapse
520
566
  self.authenticate()
521
567
  trans = client.patch(path, payload)
522
568
  end
523
- transaction = Transaction.new(trans_id: trans['_id'], payload: trans)
524
- transaction
569
+ Transaction.new(trans_id: trans['_id'], payload: trans)
525
570
  end
526
571
 
527
572
  # Cancels transaction if it has not already settled
@@ -529,7 +574,6 @@ module Synapse
529
574
  # @param trans_id
530
575
  # @return API response [Hash]
531
576
  def cancel_transaction(node_id:, trans_id:)
532
-
533
577
  path = trans_path(user_id: self.user_id, node_id: node_id) + "/#{trans_id}"
534
578
  begin
535
579
  response = client.delete(path)
@@ -545,13 +589,10 @@ module Synapse
545
589
  # @param trans_id
546
590
  # @see https://docs.synapsefi.com/docs/dispute-card-transaction
547
591
  # @return API response [Hash]
548
- def dispute_card_transactions(node_id:, trans_id:)
592
+ def dispute_card_transactions(node_id:, trans_id:, payload:)
549
593
 
550
594
  path = trans_path(user_id: user_id, node_id: node_id) + "/#{trans_id}"
551
595
  path += "/dispute"
552
- payload = {
553
- "dispute_reason":"CHARGE_BACK"
554
- }
555
596
  begin
556
597
  dispute = client.patch(path, payload)
557
598
  rescue Synapse::Error::Unauthorized
@@ -575,10 +616,9 @@ module Synapse
575
616
  self.authenticate()
576
617
  subnet = client.post(path,payload, options)
577
618
  end
578
- subnet = Subnet.new(subnet_id: subnet['_id'], payload: subnet, node_id: node_id)
579
- subnet
580
- end
581
619
 
620
+ Subnet.new(subnet_id: subnet['_id'], payload: subnet, node_id: node_id)
621
+ end
582
622
 
583
623
  # Gets all node subnets
584
624
  # @param node_id [String]
@@ -605,11 +645,17 @@ module Synapse
605
645
  subnets = client.get(path)
606
646
  end
607
647
 
608
- response = subnets["subnets"].map { |subnets_data| Subnet.new(subnet_id: subnets_data['_id'], payload: subnets, node_id: node_id)}
609
-
610
- subnets = Subnets.new(limit: subnets["limit"], page: subnets["page"], page_count: subnets["page_count"], subnets_count: subnets["subnets_count"], payload: response, node_id: node_id)
611
-
612
- subnets
648
+ response = subnets["subnets"].map { |subnets_data| Subnet.new(subnet_id: subnets_data['_id'],
649
+ payload: subnets,
650
+ node_id: node_id
651
+ )}
652
+ Subnets.new(limit: subnets["limit"],
653
+ page: subnets["page"],
654
+ page_count: subnets["page_count"],
655
+ subnets_count: subnets["subnets_count"],
656
+ payload: response,
657
+ node_id: node_id
658
+ )
613
659
  end
614
660
 
615
661
  # Queries a node for a specific subnet by subnet_id
@@ -724,6 +770,3 @@ end
724
770
 
725
771
 
726
772
 
727
-
728
-
729
-
@@ -1,6 +1,6 @@
1
1
  module Synapse
2
2
  # Gem version
3
- VERSION = '0.0.3'.freeze
3
+ VERSION = '0.0.4'.freeze
4
4
  end
5
5
 
6
6
 
data/lib/synapse_fi.rb ADDED
@@ -0,0 +1,28 @@
1
+ # client
2
+ require "synapse_api/client"
3
+ # error
4
+ require "synapse_api/error"
5
+ # http_request
6
+ require "synapse_api/http_request"
7
+ # node
8
+ require "synapse_api/node"
9
+ # nodes
10
+ require "synapse_api/nodes"
11
+ # subnet
12
+ require "synapse_api/subnet"
13
+ # subnets
14
+ require "synapse_api/subnets"
15
+ # subscription
16
+ require "synapse_api/subscription"
17
+ # subscriptions
18
+ require "synapse_api/subscriptions"
19
+ # transaction
20
+ require "synapse_api/transaction"
21
+ # transactions
22
+ require "synapse_api/transactions"
23
+ # user
24
+ require "synapse_api/user"
25
+ # users
26
+ require "synapse_api/users"
27
+ # version
28
+ require "synapse_api/version"
Binary file