rs4 0.1.3 → 0.2.2

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: c68d7c9729dc665292fad36e4941883c8463cc1023646ae749cb90aae8d1c086
4
- data.tar.gz: 1ca39c4a0bb4332e0fb0f3b31cd613bf5fea3145a4547f3ae2c6a2bf3a70a3f2
3
+ metadata.gz: 8edb979aea62c9329b7a46903ecbcd1821a6c06095529ae43706b87f4035a944
4
+ data.tar.gz: 8bf89c83e2c4c62a4c3cbbe5b1706e3e330e62fbfbda634da22d10cc2deb7355
5
5
  SHA512:
6
- metadata.gz: 8c7f1236840b7da3593c717416b5313dab2a6a1c1e5982e4accd7d161b246981d64efc2ddced70cd4cd1a834bc32e3a036252c1cf575c70739e2c696a3d449de
7
- data.tar.gz: 743fc9ff74312577fd610019519487a0312a81de74de7e4f951020d9befd048357e230d851ce1facc24a1e5f38ec6f71c010c9e087987e5b0f96f555e8bec603
6
+ metadata.gz: c1141f8182f210b2752da9b4ec45609448a9bb8cd5de2eb96034c90e95b89a16d416fbabc82e368d72d5b95735ea13bf90f6f2d6b4f8a492ad438a8d2218e1dc
7
+ data.tar.gz: 29d24cebaace5128a40bad69153cad70112bd2a8bceb461a1487a364b7bfe9db361113c621ba6092f7e7e6166d9a01b8b6e39b86edfa7ac370d4f04916477561
data/.gitignore CHANGED
@@ -10,3 +10,4 @@
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
12
  *.gem
13
+ *.swp
data/lib/rs4.rb CHANGED
@@ -2,44 +2,13 @@ require 'uri'
2
2
  require 'net/http'
3
3
  require 'openssl'
4
4
 
5
- module RS4
6
- # Prepares the HTTP request with the headers
7
- # required by the RS4 endpoints
8
- class Request
9
- # Reattempt the request before giving up
10
- MAX_RETRIES = 5
11
-
12
- class << self
13
- def execute(path, method = :get, body = {})
14
- url = URI(RS4.configuration.api_host + '/public/v1/' + path)
15
-
16
- http = Net::HTTP.new(url.host, url.port)
17
- http.use_ssl = true
5
+ require 'rs4/request.rb'
6
+ require 'rs4/document.rb'
7
+ require 'rs4/configuration.rb'
8
+ require 'rs4/request_error.rb'
9
+ require 'rs4/reusable_template.rb'
18
10
 
19
- request = case method
20
- when :get
21
- Net::HTTP::Get.new(url)
22
- when :post
23
- Net::HTTP::Post.new(url)
24
- when :put
25
- Net::HTTP::Put.new(url)
26
- when :delete
27
- Net::HTTP::Delete.new(url)
28
- end
11
+ require 'test/mock_request.rb'
29
12
 
30
- request.body = body.to_json unless method == :get
31
- request['Content-Type'] = 'application/json' unless method == :get
32
- request['Authorization'] = "Basic #{Base64.strict_encode64(RS4.configuration.private_api_key)}"
33
-
34
- # https://stackoverflow.com/questions/5370697/what-s-the-best-way-to-handle-exceptions-from-nethttp#answer-11802674
35
- begin
36
- retries ||= 0
37
- http.request(request)
38
- rescue StandardError => e
39
- Rails.logger.error(e)
40
- retry if (retries += 1) < MAX_RETRIES
41
- end
42
- end
43
- end
44
- end
13
+ module RS4
45
14
  end
@@ -11,6 +11,7 @@ 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
16
17
  end
@@ -87,42 +87,30 @@ module RS4
87
87
 
88
88
  path = "documents/#{document_guid}"
89
89
 
90
- response = RS4Api::Request.execute(path, :get)
90
+ response = RS4.configuration.request_handler.execute(path, :get)
91
91
 
92
- if response.class == Net::HTTPOK
93
- raw_document = JSON.parse(response.body, symbolize_names: true)
92
+ unless response.class == RS4::RequestError || response.nil? # .class == Net::HTTPOK
93
+ raw_document = response.dig(:document) # JSON.parse(response.body, symbolize_names: true)
94
94
 
95
- Document.new(raw_document[:document])
96
- else
97
- Rails.logger.error("Unable to get document #{document_guid}")
98
- RS4Api::RequestError.new(
99
- response.code,
100
- response.class,
101
- JSON.parse(response.read_body)
102
- )
95
+ # Document.new(raw_document[:document])
96
+ Document.new(raw_document) if raw_document
103
97
  end
104
98
  end
105
99
 
106
100
  def get_documents
107
101
  path = 'documents'
108
- response = RS4Api::Request.execute(path, :get)
102
+ response = RS4.configuration.request_handler.execute(path, :get)
109
103
 
110
- if response.class == Net::HTTPOK
104
+ unless response.class == RS4::RequestError || response.nil?
111
105
  documents = []
112
106
 
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])
107
+ response.dig(:documents).each do |document_hash|
108
+ # document_hash = raw_document.pluck(:document)
109
+ documents << Document.new(document_hash)
117
110
  end
118
- else
119
- Rails.logger.error('Unable to get documents')
120
- RS4Api::RequestError.new(
121
- response.code,
122
- response.class,
123
- JSON.parse(response.read_body)
124
- )
125
111
  end
112
+
113
+ documents
126
114
  end
127
115
  end
128
116
  end
@@ -0,0 +1,53 @@
1
+ module RS4
2
+ # Prepares the HTTP request with the headers
3
+ # required by the RS4 endpoints
4
+ class Request
5
+ # Reattempt the request before giving up
6
+ MAX_RETRIES = 5
7
+
8
+ class << self
9
+ def execute(path, method = :get, body = {})
10
+ url = URI(RS4.configuration.api_host + '/public/v1/' + path)
11
+
12
+ http = Net::HTTP.new(url.host, url.port)
13
+ http.use_ssl = true
14
+
15
+ request = case method
16
+ when :get
17
+ Net::HTTP::Get.new(url)
18
+ when :post
19
+ Net::HTTP::Post.new(url)
20
+ when :put
21
+ Net::HTTP::Put.new(url)
22
+ when :delete
23
+ Net::HTTP::Delete.new(url)
24
+ end
25
+
26
+ request.body = body.to_json unless method == :get
27
+ request['Content-Type'] = 'application/json' unless method == :get
28
+ request['Authorization'] = "Basic #{Base64.strict_encode64(RS4.configuration.private_api_key)}"
29
+
30
+ # https://stackoverflow.com/questions/5370697/what-s-the-best-way-to-handle-exceptions-from-nethttp#answer-11802674
31
+ begin
32
+ retries ||= 0
33
+ response = http.request(request)
34
+
35
+ result = if response.class == Net::HTTPOK
36
+ JSON.parse(response.body, symbolize_names: true)
37
+ else
38
+ RS4::RequestError.new(
39
+ response.code,
40
+ response.class,
41
+ JSON.parse(response.read_body)
42
+ )
43
+ end
44
+
45
+ result
46
+ rescue StandardError => e
47
+ Rails.logger.error(e)
48
+ retry if (retries += 1) < MAX_RETRIES
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,93 @@
1
+ module RS4
2
+ class ReusableTemplate
3
+ attr_accessor :id
4
+ attr_accessor :name
5
+ attr_accessor :creator
6
+ attr_accessor :expires_in
7
+ attr_accessor :signer_sequencing
8
+ attr_accessor :shared_with
9
+ attr_accessor :distribution_method
10
+ attr_accessor :identity_method
11
+ attr_accessor :kba
12
+ attr_accessor :passcode
13
+ attr_accessor :filename
14
+ attr_accessor :tags
15
+ attr_accessor :user_id
16
+ attr_accessor :roles
17
+ attr_accessor :merge_field_components
18
+ attr_accessor :created_at
19
+ attr_accessor :updated_at
20
+ attr_accessor :thumbnail_url
21
+ attr_accessor :page_image_urls
22
+
23
+ def initialize(options = {})
24
+ @id = options[:id]
25
+ @name = name
26
+ @creator = options[:creator]
27
+ @expires_in = options[:expires_in]
28
+ @signer_sequencing = options[:signer_sequencing]
29
+ @shared_with = options[:shared_with]
30
+ @distribution_method = options[:distribution_method]
31
+ @identity_method = options[:identity_method]
32
+ @kba = options[:kba]
33
+ @passcode = options[:passcode]
34
+ @filename = options[:filename]
35
+ @tags = options[:tags]
36
+ @user_id = options[:user_id]
37
+ @roles = options[:roles]
38
+ @merge_field_components = options[:merge_field_components]
39
+ @created_at = options[:created_at]
40
+ @updated_at = options[:updated_at]
41
+ @thumbnail_url = options[:thumbnail_url]
42
+ @page_image_urls = options[:page_image_urls]
43
+ end
44
+
45
+ class << self
46
+ def get_reusable_template(template_guid)
47
+ return unless template_guid
48
+
49
+ path = "reusable_templates/#{template_guid}"
50
+
51
+ response = RS4.configuration.request_handler.execute(path, :get)
52
+
53
+ unless response.class == RS4::RequestError || response.nil?
54
+ # parsed_response = JSON.parse(response.read_body, symbolize_names: true)
55
+
56
+ template_hash = response.dig(:reusable_template)
57
+
58
+ RS4::ReusableTemplate.new(template_hash)
59
+ end
60
+ end
61
+
62
+ def get_reusable_templates(options = {})
63
+ base_path = 'reusable_templates'
64
+
65
+ query = CGI.unescape(options.to_query)
66
+
67
+ path = query.empty? ? base_path : "#{base_path}?#{query}"
68
+
69
+ RS4.configuration.request_handler.execute(path, :get)
70
+ end
71
+
72
+ def send_document(template_guid, options = {})
73
+ path = "reusable_templates/#{template_guid}/send_document"
74
+
75
+ body = options
76
+
77
+ body[:in_person] = true
78
+
79
+ response = RS4.configuration.request_handler.execute(path, :post, body)
80
+
81
+ Rails.logger.info("RS4::ReusableTemplate::send_document:: #{response.inspect}")
82
+
83
+ unless response.class == RS4::RequestError || response.nil?
84
+ # parsed_response = JSON.parse(response.read_body, symbolize_names: true)
85
+
86
+ document_hash = response.dig(:document)
87
+
88
+ return RS4::Document.new(document_hash)
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -1,3 +1,3 @@
1
1
  module RS4
2
- VERSION = "0.1.3"
2
+ VERSION = '0.2.2'.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.3
4
+ version: 0.2.2
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-20 00:00:00.000000000 Z
11
+ date: 2020-06-24 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
@@ -27,12 +27,14 @@ files:
27
27
  - Rakefile
28
28
  - bin/console
29
29
  - bin/setup
30
- - lib/configuration.rb
31
- - lib/document.rb
32
- - lib/request_error.rb
33
- - lib/reusable_template.rb
34
30
  - lib/rs4.rb
31
+ - lib/rs4/configuration.rb
32
+ - lib/rs4/document.rb
33
+ - lib/rs4/request.rb
34
+ - lib/rs4/request_error.rb
35
+ - lib/rs4/reusable_template.rb
35
36
  - lib/rs4/version.rb
37
+ - lib/test/mock_request.rb
36
38
  - license.txt
37
39
  - rs4.gemspec
38
40
  homepage: https://github.com/equitymultiple/rs4
@@ -1,104 +0,0 @@
1
- module RS4
2
- class ReusableTemplate
3
- attr_accessor :id
4
- attr_accessor :name
5
- attr_accessor :creator
6
- attr_accessor :expires_in
7
- attr_accessor :signer_sequencing
8
- attr_accessor :shared_with
9
- attr_accessor :distribution_method
10
- attr_accessor :identity_method
11
- attr_accessor :kba
12
- attr_accessor :passcode
13
- attr_accessor :filename
14
- attr_accessor :tags
15
- attr_accessor :user_id
16
- attr_accessor :roles
17
- attr_accessor :merge_field_components
18
- attr_accessor :created_at
19
- attr_accessor :updated_at
20
- attr_accessor :thumbnail_url
21
- attr_accessor :page_image_urls
22
-
23
- def initialize(options = {})
24
- @id = options[:id]
25
- @name = name
26
- @creator = options[:creator]
27
- @expires_in = options[:expires_in]
28
- @signer_sequencing = options[:signer_sequencing]
29
- @shared_with = options[:shared_with]
30
- @distribution_method = options[:distribution_method]
31
- @identity_method = options[:identity_method]
32
- @kba = options[:kba]
33
- @passcode = options[:passcode]
34
- @filename = options[:filename]
35
- @tags = options[:tags]
36
- @user_id = options[:user_id]
37
- @roles = options[:roles]
38
- @merge_field_components = options[:merge_field_components]
39
- @created_at = options[:created_at]
40
- @updated_at = options[:updated_at]
41
- @thumbnail_url = options[:thumbnail_url]
42
- @page_image_urls = options[:page_image_urls]
43
- end
44
-
45
- def get_reusable_template(template_guid)
46
- return unless template_guid
47
-
48
- path = "reusable_templates/#{template_guid}"
49
-
50
- response = RS4::Request.execute(path, :get)
51
-
52
- if response.class == Net::HTTPOK
53
- parsed_response = JSON.parse(response.read_body, symbolize_names: true)
54
-
55
- template_hash = parsed_response[:reusable_template]
56
-
57
- RS4Api::ReusableTemplate.new(template_hash)
58
- else
59
- RS4Api::RequestError.new(
60
- response.code,
61
- response.class,
62
- JSON.parse(response.read_body)
63
- )
64
- end
65
- end
66
-
67
- def get_reusable_templates(options = {})
68
- base_path = 'reusable_templates'
69
-
70
- query = CGI.unescape(options.to_query)
71
-
72
- path = query.empty? ? base_path : "#{base_path}?#{query}"
73
-
74
- RS4::Request.execute(path, :get)
75
- end
76
-
77
- def send_document(template_guid, options = {})
78
- path = "reusable_templates/#{template_guid}/send_document"
79
-
80
- body = options
81
-
82
- body[:in_person] = true
83
-
84
- response = RS4::Request.execute(path, :post, body)
85
-
86
- Rails.logger.info("RS4::ReusableTemplate::send_document:: #{response.inspect}")
87
-
88
- if response.class == Net::HTTPOK
89
- parsed_response = JSON.parse(response.read_body, symbolize_names: true)
90
-
91
- document_hash = parsed_response[:document]
92
-
93
- return RS4Api::Document.new(document_hash)
94
-
95
- else
96
- return RS4Api::RequestError.new(
97
- response.code,
98
- response.class,
99
- JSON.parse(response.read_body)
100
- )
101
- end
102
- end
103
- end
104
- end