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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: acfc38c392a8ce535063f4f4a998e6c595eaa65df1cdbb2c3293a41329aae942
4
- data.tar.gz: 760c3bbf2a9faa6a52222014177418dda32edd603fc23b66c57c3f16ced250fe
3
+ metadata.gz: 4e8e2fd74b61acb79edb0d4fbc64e49ef1c0fad6b8696d466b83a0cec8e6bab9
4
+ data.tar.gz: 2b611b82edec6aa6c897472a2163110cd8a1d01a8cb39cc85a47e1628de7d955
5
5
  SHA512:
6
- metadata.gz: aa701fad73581b95f521b673ab97f4165af8e72f484a5f8261075970ee702547bf36753b54da989c4ff59295b19a02ed84dd602f0737b03ae768a091acd27257
7
- data.tar.gz: ba66c9b74fb9c7a1d9ef25797c353abc4811e8adca8f3ea4b5063e55e1e3b8467f60bffd833397e456c4512424e4a9d784f3e496ae0626b805ce8d48dbef8342
6
+ metadata.gz: '0975d5000647806f81c71796563a0f13857093da7e4e18518c02bce918ce293e2247f50f08cc03a831bb0eca2dfaaf4f77b2784eafaf5032230f42773ebcf7b4'
7
+ data.tar.gz: 3bccea9722d64d825e1dc8aa5e542fc7bc6fd98b5ff521e3bd93661b8e2f56a2af8fbfd7ccaf9cf6b82252cde7dbbb868c0fe0af910e0c7214426e50e45bece7
data/.gitignore CHANGED
@@ -10,3 +10,4 @@
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
12
  *.gem
13
+ *.swp
@@ -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
@@ -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.2"
2
+ VERSION = '0.2.1'.freeze
3
3
  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.2
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-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,10 +27,12 @@ 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
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
@@ -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