synapsis_v3 0.2.3 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f49da6fa15db4baf54ab69992d50d4c68361c45
4
- data.tar.gz: 9c1f9ae62fb312a41869c4848c9795ab5794b936
3
+ metadata.gz: a4ddc30a2ecbb6d13b32233a572c2d44829d5d94
4
+ data.tar.gz: dffafdb4732f83b7510261577884147d310f1186
5
5
  SHA512:
6
- metadata.gz: 184dd113995856cba644f142492294d9df38c7a113e7acc6b857db9552aa74f7ebfea3017ceb62f99d5f8668f868fbfbbb887bd963a9dc496600ade506c7eedd
7
- data.tar.gz: 25f612f560894483eda3cb1d752633faf1fa400b3f74ca1b315289adc13a4714777c1addb4227556cf212526bb67d8b624e2a84597cca38f73f711d4ea3bd402
6
+ metadata.gz: 8fd0962b03fb8bcb29e7bf0587af61e8ca2b5e8ef38a89a921015f819c6f4975eaf17a78fd3c65ea4eda6a20fc2c73327cd8aa7385a2deb65759d69372a390f2
7
+ data.tar.gz: 09b9e4e1a246377e5c235b079eaf6606cda877156103ab69ae0464d705fb6b21756be629ccedbc1d0c2bdce49eecfbd6978c4c5d4cf9a7b67426dbc0c1ac3474
data/lib/synapsis_v3.rb CHANGED
@@ -18,6 +18,7 @@ require "synapsis_v3/transaction"
18
18
  require "synapsis_v3/subscription"
19
19
 
20
20
  API_V3_PATH = 'api/v3/'
21
+ API_V3_NEW_PATH = 'api/3/'
21
22
 
22
23
  module Synapsis
23
24
  class << self
@@ -1,16 +1,16 @@
1
1
  class Synapsis::APIResource
2
- def self.request(method, url, params, oauth_key: nil, fingerprint: nil, ip_address: nil)
2
+ def self.request(method, url, params, headers = {})
3
3
  Synapsis.connection.send(method) do |req|
4
4
  req.headers['Content-Type'] = 'application/json'
5
5
  req.headers['X-SP-LANG'] = 'EN' # Set language to English
6
6
  req.headers['X-SP-GATEWAY'] = "#{Synapsis.client_id}|#{Synapsis.client_secret}"
7
7
 
8
- if oauth_key && fingerprint
9
- req.headers['X-SP-USER'] = "#{oauth_key}|#{fingerprint}"
8
+ if headers[:oauth_key] && headers[:fingerprint]
9
+ req.headers['X-SP-USER'] = "#{headers[:oauth_key]}|#{headers[:fingerprint]}"
10
10
  end
11
11
 
12
- if ip_address
13
- req.headers['X-SP-USER-IP'] = ip_address
12
+ if headers[:ip_address]
13
+ req.headers['X-SP-USER-IP'] = headers[:ip_address]
14
14
  end
15
15
 
16
16
  if Synapsis.environment == 'production'
@@ -28,6 +28,10 @@ class Synapsis::APIResource
28
28
  name.partition('::').last.downcase
29
29
  end
30
30
 
31
+ def self.class_name_pluralized
32
+ "#{class_name}s"
33
+ end
34
+
31
35
  def class_name
32
36
  self.class.name.partition('::').last.downcase
33
37
  end
@@ -38,6 +42,7 @@ class Synapsis::APIResource
38
42
  if response.success?
39
43
  return parsed_response
40
44
  else
45
+ puts parsed_response
41
46
  raise Synapsis::Error.new(
42
47
  error: parsed_response.error,
43
48
  http_code: parsed_response.http_code,
@@ -34,32 +34,30 @@ class Synapsis::User < Synapsis::APIResource
34
34
  return sign_in(params)
35
35
  end
36
36
 
37
- def self.add_kyc(params)
38
- add_kyc_url = "#{API_V3_PATH}#{class_name}/doc/add"
37
+ def self.add_document(payload, headers)
38
+ verify_kyc_new_url = "#{API_V3_NEW_PATH}users/#{headers[:synapse_id]}"
39
39
 
40
- response = request(:post, add_kyc_url, params)
41
- return_response(response)
42
- end
40
+ # Automatically convert all physical documents to base64 format
41
+ physical_doc_array = payload[:documents][0][:physical_docs]
42
+ physical_doc_array = convert_all_physical_documents_to_base64(physical_doc_array)
43
43
 
44
- def self.verify_kyc(params)
45
- verify_kyc_url = "#{API_V3_PATH}#{class_name}/doc/verify"
44
+ response = request(:patch, verify_kyc_new_url, payload, headers)
46
45
 
47
- response = request(:post, verify_kyc_url, params)
48
46
  return_response(response)
49
47
  end
50
48
 
51
- def self.add_document(params)
52
- add_document_url = "#{API_V3_PATH}user/doc/attachments/add"
53
-
54
- response = request(:post, add_document_url, convert_attachment_to_base_64(params))
55
-
56
- return_response(response)
49
+ def self.convert_all_physical_documents_to_base64(docs_array)
50
+ if docs_array
51
+ docs_array.map do |doc|
52
+ doc[:document_value] = convert_attachment_to_base_64(doc[:document_value])
53
+ end
54
+ end
57
55
  end
58
56
 
59
- def self.show(params)
60
- show_user_url = "#{API_V3_PATH}#{class_name}/client/users"
57
+ def self.show(payload, headers)
58
+ show_user_url = "#{API_V3_NEW_PATH}#{class_name_pluralized}/#{headers[:synapse_id]}"
61
59
 
62
- response = request(:post, show_user_url, params.merge(client_credentials))
60
+ response = request(:get, show_user_url, payload, headers)
63
61
 
64
62
  return_response(response)
65
63
  end
@@ -80,8 +78,8 @@ class Synapsis::User < Synapsis::APIResource
80
78
  return_response(response)
81
79
  end
82
80
 
83
- def self.convert_attachment_to_base_64(doc_params)
84
- file_type = MIME::Types.type_for(doc_params[:user][:doc][:attachment]).first.content_type
81
+ def self.convert_attachment_to_base_64(doc)
82
+ file_type = MIME::Types.type_for(doc).first.content_type
85
83
 
86
84
  if file_type == 'text/plain'
87
85
  mime_padding = "data:text/csv;base64,"
@@ -89,11 +87,10 @@ class Synapsis::User < Synapsis::APIResource
89
87
  mime_padding = "data:#{file_type};base64,"
90
88
  end
91
89
 
92
- doc_params[:user][:doc][:attachment] = "#{mime_padding}#{Base64.encode64(File.open(doc_params[:user][:doc][:attachment], 'rb') { |f| f.read })}"
93
-
94
- return doc_params
90
+ return "#{mime_padding}#{Base64.encode64(File.open(doc, 'rb') { |f| f.read })}"
95
91
  end
96
92
 
93
+ private_class_method :convert_all_physical_documents_to_base64
97
94
  private_class_method :convert_attachment_to_base_64
98
95
  end
99
96
 
@@ -1,3 +1,3 @@
1
1
  module SynapsisV3
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synapsis_v3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daryll Santos
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-07-11 00:00:00.000000000 Z
11
+ date: 2016-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday