rs4 0.1.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d11e0ed8ace80f96d0ffde3b72915bfcd77c7eff73c47eb8682751e88b385755
4
- data.tar.gz: cc830ddf9f7684734e687a6f85a17aa21726f1ca01bb45798a7c0ae5951087fc
3
+ metadata.gz: 647f43f6fd372991e9ece30989f3562ddb75bebe11f75b57173de79c3a13e2ee
4
+ data.tar.gz: e3816cb16b081157cc2fb9cf2581e82054d344c11f9fa5c8e6b39a5ed8864751
5
5
  SHA512:
6
- metadata.gz: b07928a830d6a935334c2ae13384c322beb41056cb4648f5905fbf7c2774de91fc0b338587d50719c6b8acffd101d086ea1dbf0e6e9276f6970ccd2058e8b9bf
7
- data.tar.gz: 5ae429530d7eb69a6794d0458ee8c30ab28dec8499879bb4b4108977d8d4dc7025267fefd91337eff9ea0fe0885b02a0573ad37dec195129a38bf3705a8bd37a
6
+ metadata.gz: 971068d9b96fb2ae77ef7967e9b712c6a77fab92f3048b6c85103ab707abc1702ae97b65e56273baef55da88cec0565442f983daffb9d5d40a7923d9d82d629a
7
+ data.tar.gz: eaf0881298294fc46467aa6f4c8d0c4c1a8eff65bc4a9465209001dfd07cadde4b7e8c7e681adaf62d73b471f08fccc8ae7c5895d6251765378a62af16f58e09
data/lib/rs4.rb CHANGED
@@ -6,7 +6,10 @@ require 'rs4/request.rb'
6
6
  require 'rs4/document.rb'
7
7
  require 'rs4/configuration.rb'
8
8
  require 'rs4/request_error.rb'
9
+ require 'rs4/configuration_error.rb'
9
10
  require 'rs4/reusable_template.rb'
10
11
 
12
+ require 'test/mock_request.rb'
13
+
11
14
  module RS4
12
15
  end
@@ -11,7 +11,23 @@ module RS4
11
11
  end
12
12
 
13
13
  class Configuration
14
+ attr_accessor :request_handler
14
15
  attr_accessor :private_api_key
15
16
  attr_accessor :api_host
17
+ attr_accessor :errors
18
+
19
+ def valid?
20
+ @errors = []
21
+
22
+ @errors << '`private_api_key` not set' unless private_api_key.present?
23
+ @errors << '`api_host` not set' unless api_host.present?
24
+
25
+ if @errors.any?
26
+ Rails.logger.error("RS4 Configuration Invalid: #{@errors.join(',')}")
27
+ return false
28
+ else
29
+ return true
30
+ end
31
+ end
16
32
  end
17
33
  end
@@ -0,0 +1,15 @@
1
+ require 'rs4/error.rb'
2
+
3
+ module RS4
4
+ # Error should be returned when the module has been
5
+ # improperly configured
6
+ class ConfigurationError < Error
7
+ attr_accessor :error_fields
8
+
9
+ def initialize(error_fields = [], message)
10
+ super(message)
11
+
12
+ @error_fields = error_fields
13
+ end
14
+ end
15
+ end
@@ -9,6 +9,7 @@ module RS4
9
9
  EXECUTED_STATE = :executed
10
10
 
11
11
  attr_accessor :id
12
+ attr_accessor :original_guid
12
13
  attr_accessor :current_signer_id
13
14
  attr_accessor :name
14
15
  attr_accessor :filename
@@ -82,47 +83,49 @@ module RS4
82
83
  end
83
84
 
84
85
  class << self
86
+ def get_archive_document(document_guid)
87
+ return unless document_guid.present?
88
+
89
+ path = "archived_documents_by_original_guid/#{document_guid}"
90
+
91
+ response = RS4.configuration.request_handler.execute(path, :get)
92
+
93
+ unless response.is_a?(RS4::Error) || response.nil?
94
+ archived_document = response.dig(:archived_document)
95
+
96
+ Document.new(archived_document) if archived_document
97
+ end
98
+ end
99
+
85
100
  def get_document(document_guid)
86
- return unless document_guid
101
+ return unless document_guid.present?
87
102
 
88
103
  path = "documents/#{document_guid}"
89
104
 
90
- response = RS4::Request.execute(path, :get)
105
+ response = RS4.configuration.request_handler.execute(path, :get)
91
106
 
92
- if response.class == Net::HTTPOK
93
- raw_document = JSON.parse(response.body, symbolize_names: true)
107
+ unless response.is_a?(RS4::Error) || response.nil? # .class == Net::HTTPOK
108
+ raw_document = response.dig(:document) # JSON.parse(response.body, symbolize_names: true)
94
109
 
95
- Document.new(raw_document[:document])
96
- else
97
- Rails.logger.error("Unable to get document #{document_guid}")
98
- RS4::RequestError.new(
99
- response.code,
100
- response.class,
101
- JSON.parse(response.read_body)
102
- )
110
+ # Document.new(raw_document[:document])
111
+ Document.new(raw_document) if raw_document
103
112
  end
104
113
  end
105
114
 
106
115
  def get_documents
107
116
  path = 'documents'
108
- response = RS4::Request.execute(path, :get)
117
+ response = RS4.configuration.request_handler.execute(path, :get)
109
118
 
110
- if response.class == Net::HTTPOK
119
+ unless response.is_a?(RS4::Error) || response.nil?
111
120
  documents = []
112
121
 
113
- raw_documents = JSON.parse(response.body, symbolize_names: true)
114
-
115
- raw_documents.each do |raw_document|
116
- documents << Document.new(raw_document[:document])
122
+ response.dig(:documents).each do |document_hash|
123
+ # document_hash = raw_document.pluck(:document)
124
+ documents << Document.new(document_hash)
117
125
  end
118
- else
119
- Rails.logger.error('Unable to get documents')
120
- RS4::RequestError.new(
121
- response.code,
122
- response.class,
123
- JSON.parse(response.read_body)
124
- )
125
126
  end
127
+
128
+ documents
126
129
  end
127
130
  end
128
131
  end
@@ -0,0 +1,12 @@
1
+ module RS4
2
+ # Standard Error returning a simple message
3
+ # Should be extended by additional classes
4
+ # to provide needed behavior
5
+ class Error
6
+ attr_accessor :message
7
+
8
+ def initialize(message)
9
+ @message = message
10
+ end
11
+ end
12
+ end
@@ -7,6 +7,11 @@ module RS4
7
7
 
8
8
  class << self
9
9
  def execute(path, method = :get, body = {})
10
+ # Check required keys exist before continuing
11
+ unless RS4.configuration.valid?
12
+ return RS4::ConfigurationError.new(RS4.configuration.errors, 'Invalid Configuration')
13
+ end
14
+
10
15
  url = URI(RS4.configuration.api_host + '/public/v1/' + path)
11
16
 
12
17
  http = Net::HTTP.new(url.host, url.port)
@@ -30,7 +35,19 @@ module RS4
30
35
  # https://stackoverflow.com/questions/5370697/what-s-the-best-way-to-handle-exceptions-from-nethttp#answer-11802674
31
36
  begin
32
37
  retries ||= 0
33
- http.request(request)
38
+ response = http.request(request)
39
+
40
+ result = if response.class == Net::HTTPOK
41
+ JSON.parse(response.body, symbolize_names: true)
42
+ else
43
+ RS4::RequestError.new(
44
+ response.code,
45
+ response.class,
46
+ JSON.parse(response.read_body)
47
+ )
48
+ end
49
+
50
+ result
34
51
  rescue StandardError => e
35
52
  Rails.logger.error(e)
36
53
  retry if (retries += 1) < MAX_RETRIES
@@ -1,18 +1,20 @@
1
+ require 'rs4/error.rb'
2
+
1
3
  module RS4
2
4
  # The standard error returned when a request to the RS4
3
5
  # API fails
4
6
  # code - the NetHTTP response code as a number (eg - 200)
5
7
  # error_class - which NetHTTP class was returned by the response
6
8
  # message - the error message (if any) returned in the response
7
- class RequestError
9
+ class RequestError < Error
8
10
  attr_accessor :code
9
11
  attr_accessor :error_class
10
- attr_accessor :message
11
12
 
12
13
  def initialize(code, error_class, message)
14
+ super(message)
15
+
13
16
  @code = code
14
17
  @error_class = error_class
15
- @message = message
16
18
  end
17
19
  end
18
20
  end
@@ -48,20 +48,14 @@ module RS4
48
48
 
49
49
  path = "reusable_templates/#{template_guid}"
50
50
 
51
- response = RS4::Request.execute(path, :get)
51
+ response = RS4.configuration.request_handler.execute(path, :get)
52
52
 
53
- if response.class == Net::HTTPOK
54
- parsed_response = JSON.parse(response.read_body, symbolize_names: true)
53
+ unless response.is_a?(RS4::Error) || response.nil?
54
+ # parsed_response = JSON.parse(response.read_body, symbolize_names: true)
55
55
 
56
- template_hash = parsed_response[:reusable_template]
56
+ template_hash = response.dig(:reusable_template)
57
57
 
58
58
  RS4::ReusableTemplate.new(template_hash)
59
- else
60
- RS4::RequestError.new(
61
- response.code,
62
- response.class,
63
- JSON.parse(response.read_body)
64
- )
65
59
  end
66
60
  end
67
61
 
@@ -72,7 +66,7 @@ module RS4
72
66
 
73
67
  path = query.empty? ? base_path : "#{base_path}?#{query}"
74
68
 
75
- RS4::Request.execute(path, :get)
69
+ RS4.configuration.request_handler.execute(path, :get)
76
70
  end
77
71
 
78
72
  def send_document(template_guid, options = {})
@@ -80,25 +74,18 @@ module RS4
80
74
 
81
75
  body = options
82
76
 
83
- body[:in_person] = true
77
+ body[:in_person] = options[:in_person] || true
84
78
 
85
- response = RS4::Request.execute(path, :post, body)
79
+ response = RS4.configuration.request_handler.execute(path, :post, body)
86
80
 
87
81
  Rails.logger.info("RS4::ReusableTemplate::send_document:: #{response.inspect}")
88
82
 
89
- if response.class == Net::HTTPOK
90
- parsed_response = JSON.parse(response.read_body, symbolize_names: true)
83
+ unless response.is_a?(RS4::Error) || response.nil?
84
+ # parsed_response = JSON.parse(response.read_body, symbolize_names: true)
91
85
 
92
- document_hash = parsed_response[:document]
86
+ document_hash = response.dig(:document)
93
87
 
94
88
  return RS4::Document.new(document_hash)
95
-
96
- else
97
- return RS4::RequestError.new(
98
- response.code,
99
- response.class,
100
- JSON.parse(response.read_body)
101
- )
102
89
  end
103
90
  end
104
91
  end
@@ -1,3 +1,3 @@
1
1
  module RS4
2
- VERSION = "0.1.6"
2
+ VERSION = '0.2.7'.freeze
3
3
  end
@@ -0,0 +1,114 @@
1
+ module RS4
2
+ class MockRequest
3
+ class << self
4
+ def execute(path, method = :get, _body = {})
5
+ mockument = {
6
+ id: SecureRandom.uuid,
7
+ current_signer_id: 0,
8
+ name: 'noname',
9
+ filename: 'noname.pdf',
10
+ executed_at: Date.today,
11
+ expired_at: Date.today + 1.day,
12
+ sent_at: Date.today,
13
+ state: 'draft',
14
+ thumbnail_url: 'google.com',
15
+ sender: 'sender',
16
+ recipients: [
17
+ {
18
+ role_name: 'Investor',
19
+ sign_url: 'www.google.com'
20
+ }
21
+ ],
22
+ audits: nil,
23
+ page_image_urls: 'google.com',
24
+ signed_pdf_url: 'google.com/pdf.pdf',
25
+ tags: nil,
26
+ merge_field_values: nil,
27
+ embed_codes: nil,
28
+ in_person: true,
29
+ shared_with: nil,
30
+ identity_method: nil,
31
+ passcode_pin_enabled: false,
32
+ original_file_url: 'google.com'
33
+ }
34
+
35
+ if _body&.dig(:roles)&.any?
36
+
37
+ mockument[:recipients] = []
38
+
39
+ _body[:roles].each do |role|
40
+ mockument[:recipients] << {
41
+ role_name: role[:name],
42
+ sign_url: 'www.google.com'
43
+ }
44
+ end
45
+ end
46
+
47
+ mockplate = {
48
+ id: SecureRandom.uuid,
49
+ name: 'template',
50
+ creator: 'creator',
51
+ expires_in: Date.today + 1.day,
52
+ signer_sequencing: false,
53
+ shared_with: nil,
54
+ distribution_method: nil,
55
+ identity_method: nil,
56
+ kba: nil,
57
+ passcode: nil,
58
+ filename: 'template.pdf',
59
+ tags: nil,
60
+ user_id: 1,
61
+ roles: [],
62
+ merge_field_components: [],
63
+ created_at: Date.today,
64
+ updated_at: Date.today,
65
+ thumbnail_url: 'google.com/pdf.pdf',
66
+ page_image_urls: 'google.com/image'
67
+ }
68
+
69
+ case path
70
+ when %r{reusable_templates/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/send_document}
71
+ return {
72
+ document: mockument
73
+ }
74
+ when %r{reusable_templates/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}}
75
+ return {
76
+ reusable_template: mockplate
77
+ }
78
+ when /reusable_templates/
79
+ results = {
80
+ reusable_templates: []
81
+ }
82
+
83
+ i = 0
84
+ while i < 3
85
+ mockplate[:id] = SecureRandom.uuid
86
+ results[:reusable_templates] << mockplate
87
+ i += 1
88
+ end
89
+
90
+ return results
91
+ when %r{documents/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}}
92
+ return {
93
+ document: mockument
94
+ }
95
+
96
+ when /documents/
97
+ Rails.logger.info("#{method} documents")
98
+
99
+ results = {
100
+ documents: []
101
+ }
102
+ i = 0
103
+ while i < 3
104
+ results[:documents] << mockument
105
+ i += 1
106
+ end
107
+
108
+ return results
109
+
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rs4
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - donny
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-21 00:00:00.000000000 Z
11
+ date: 2020-07-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Provides ruby access to CRUD operations for RightSignature documents
14
14
  and reusable templates
@@ -29,11 +29,14 @@ files:
29
29
  - bin/setup
30
30
  - lib/rs4.rb
31
31
  - lib/rs4/configuration.rb
32
+ - lib/rs4/configuration_error.rb
32
33
  - lib/rs4/document.rb
34
+ - lib/rs4/error.rb
33
35
  - lib/rs4/request.rb
34
36
  - lib/rs4/request_error.rb
35
37
  - lib/rs4/reusable_template.rb
36
38
  - lib/rs4/version.rb
39
+ - lib/test/mock_request.rb
37
40
  - license.txt
38
41
  - rs4.gemspec
39
42
  homepage: https://github.com/equitymultiple/rs4