rs4 0.1.3 → 0.1.4
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 +4 -4
- data/.gitignore +1 -0
- data/lib/rs4.rb +6 -39
- data/lib/{configuration.rb → rs4/configuration.rb} +0 -0
- data/lib/{document.rb → rs4/document.rb} +0 -0
- data/lib/rs4/request.rb +41 -0
- data/lib/{request_error.rb → rs4/request_error.rb} +0 -0
- data/lib/{reusable_template.rb → rs4/reusable_template.rb} +0 -0
- data/lib/rs4/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dbf0795919c6835f30a843f728b8bfc7cbd3efdd1027d199bbe39c6450963380
|
4
|
+
data.tar.gz: 18578752a41d6727cf72b560aae3270194dedf3b033395410c0f41b32de3aa73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bfa79ca3aabe08ae7432c7224ad806d169bad8305b89f3ce8300fdfa7bce9871da58749becfa3cfc74c72f0248d7a8b00d68a9da8e5123cf93eeb1677511be23
|
7
|
+
data.tar.gz: 2731bf2ba14e69d77541441e1e064cbc90b8c1589047f6d30ac736e38a405e2e7a3aec89360e31d4e622e0cf6fec00207655720c5b1460472ca0c434e785dbb2
|
data/.gitignore
CHANGED
data/lib/rs4.rb
CHANGED
@@ -2,44 +2,11 @@ require 'uri'
|
|
2
2
|
require 'net/http'
|
3
3
|
require 'openssl'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
-
|
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
|
29
|
-
|
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
|
11
|
+
module RS4
|
45
12
|
end
|
File without changes
|
File without changes
|
data/lib/rs4/request.rb
ADDED
@@ -0,0 +1,41 @@
|
|
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
|
+
http.request(request)
|
34
|
+
rescue StandardError => e
|
35
|
+
Rails.logger.error(e)
|
36
|
+
retry if (retries += 1) < MAX_RETRIES
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
File without changes
|
File without changes
|
data/lib/rs4/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rs4
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- donny
|
@@ -27,11 +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
|
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
|
36
37
|
- license.txt
|
37
38
|
- rs4.gemspec
|