rs4 0.1.6 → 0.2.1

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
  SHA256:
3
- metadata.gz: d11e0ed8ace80f96d0ffde3b72915bfcd77c7eff73c47eb8682751e88b385755
4
- data.tar.gz: cc830ddf9f7684734e687a6f85a17aa21726f1ca01bb45798a7c0ae5951087fc
3
+ metadata.gz: 4e8e2fd74b61acb79edb0d4fbc64e49ef1c0fad6b8696d466b83a0cec8e6bab9
4
+ data.tar.gz: 2b611b82edec6aa6c897472a2163110cd8a1d01a8cb39cc85a47e1628de7d955
5
5
  SHA512:
6
- metadata.gz: b07928a830d6a935334c2ae13384c322beb41056cb4648f5905fbf7c2774de91fc0b338587d50719c6b8acffd101d086ea1dbf0e6e9276f6970ccd2058e8b9bf
7
- data.tar.gz: 5ae429530d7eb69a6794d0458ee8c30ab28dec8499879bb4b4108977d8d4dc7025267fefd91337eff9ea0fe0885b02a0573ad37dec195129a38bf3705a8bd37a
6
+ metadata.gz: '0975d5000647806f81c71796563a0f13857093da7e4e18518c02bce918ce293e2247f50f08cc03a831bb0eca2dfaaf4f77b2784eafaf5032230f42773ebcf7b4'
7
+ data.tar.gz: 3bccea9722d64d825e1dc8aa5e542fc7bc6fd98b5ff521e3bd93661b8e2f56a2af8fbfd7ccaf9cf6b82252cde7dbbb868c0fe0af910e0c7214426e50e45bece7
data/lib/rs4.rb CHANGED
@@ -8,5 +8,7 @@ require 'rs4/configuration.rb'
8
8
  require 'rs4/request_error.rb'
9
9
  require 'rs4/reusable_template.rb'
10
10
 
11
+ require 'test/mock_request.rb'
12
+
11
13
  module RS4
12
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 = RS4::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
- RS4::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 = RS4::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
- RS4::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
@@ -30,7 +30,19 @@ module RS4
30
30
  # https://stackoverflow.com/questions/5370697/what-s-the-best-way-to-handle-exceptions-from-nethttp#answer-11802674
31
31
  begin
32
32
  retries ||= 0
33
- http.request(request)
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
34
46
  rescue StandardError => e
35
47
  Rails.logger.error(e)
36
48
  retry if (retries += 1) < MAX_RETRIES
@@ -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.class == RS4::RequestError || 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 = {})
@@ -82,23 +76,16 @@ module RS4
82
76
 
83
77
  body[: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.class == RS4::RequestError || 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.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.6
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-21 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