rs4 0.1.2 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/rs4.rb +14 -0
- data/lib/{configuration.rb → rs4/configuration.rb} +1 -0
- data/lib/{document.rb → rs4/document.rb} +12 -24
- data/lib/rs4/request.rb +53 -0
- data/lib/{request_error.rb → rs4/request_error.rb} +0 -0
- data/lib/rs4/reusable_template.rb +93 -0
- data/lib/rs4/version.rb +1 -1
- metadata +8 -6
- data/lib/reusable_template.rb +0 -104
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e8e2fd74b61acb79edb0d4fbc64e49ef1c0fad6b8696d466b83a0cec8e6bab9
|
4
|
+
data.tar.gz: 2b611b82edec6aa6c897472a2163110cd8a1d01a8cb39cc85a47e1628de7d955
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0975d5000647806f81c71796563a0f13857093da7e4e18518c02bce918ce293e2247f50f08cc03a831bb0eca2dfaaf4f77b2784eafaf5032230f42773ebcf7b4'
|
7
|
+
data.tar.gz: 3bccea9722d64d825e1dc8aa5e542fc7bc6fd98b5ff521e3bd93661b8e2f56a2af8fbfd7ccaf9cf6b82252cde7dbbb868c0fe0af910e0c7214426e50e45bece7
|
data/.gitignore
CHANGED
data/lib/rs4.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/http'
|
3
|
+
require 'openssl'
|
4
|
+
|
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'
|
10
|
+
|
11
|
+
require 'test/mock_request.rb'
|
12
|
+
|
13
|
+
module RS4
|
14
|
+
end
|
@@ -87,42 +87,30 @@ module RS4
|
|
87
87
|
|
88
88
|
path = "documents/#{document_guid}"
|
89
89
|
|
90
|
-
response =
|
90
|
+
response = RS4.configuration.request_handler.execute(path, :get)
|
91
91
|
|
92
|
-
|
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
|
-
|
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 =
|
102
|
+
response = RS4.configuration.request_handler.execute(path, :get)
|
109
103
|
|
110
|
-
|
104
|
+
unless response.class == RS4::RequestError || response.nil?
|
111
105
|
documents = []
|
112
106
|
|
113
|
-
|
114
|
-
|
115
|
-
|
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
|
data/lib/rs4/request.rb
ADDED
@@ -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
|
File without changes
|
@@ -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
|
data/lib/rs4/version.rb
CHANGED
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
|
4
|
+
version: 0.2.1
|
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-
|
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,10 +27,12 @@ files:
|
|
27
27
|
- Rakefile
|
28
28
|
- bin/console
|
29
29
|
- bin/setup
|
30
|
-
- lib/
|
31
|
-
- lib/
|
32
|
-
- lib/
|
33
|
-
- lib/
|
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
|
34
36
|
- lib/rs4/version.rb
|
35
37
|
- license.txt
|
36
38
|
- rs4.gemspec
|
data/lib/reusable_template.rb
DELETED
@@ -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
|