rs4 0.1.2 → 0.1.3

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rs4/version.rb +1 -1
  3. data/lib/rs4.rb +45 -0
  4. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: acfc38c392a8ce535063f4f4a998e6c595eaa65df1cdbb2c3293a41329aae942
4
- data.tar.gz: 760c3bbf2a9faa6a52222014177418dda32edd603fc23b66c57c3f16ced250fe
3
+ metadata.gz: c68d7c9729dc665292fad36e4941883c8463cc1023646ae749cb90aae8d1c086
4
+ data.tar.gz: 1ca39c4a0bb4332e0fb0f3b31cd613bf5fea3145a4547f3ae2c6a2bf3a70a3f2
5
5
  SHA512:
6
- metadata.gz: aa701fad73581b95f521b673ab97f4165af8e72f484a5f8261075970ee702547bf36753b54da989c4ff59295b19a02ed84dd602f0737b03ae768a091acd27257
7
- data.tar.gz: ba66c9b74fb9c7a1d9ef25797c353abc4811e8adca8f3ea4b5063e55e1e3b8467f60bffd833397e456c4512424e4a9d784f3e496ae0626b805ce8d48dbef8342
6
+ metadata.gz: 8c7f1236840b7da3593c717416b5313dab2a6a1c1e5982e4accd7d161b246981d64efc2ddced70cd4cd1a834bc32e3a036252c1cf575c70739e2c696a3d449de
7
+ data.tar.gz: 743fc9ff74312577fd610019519487a0312a81de74de7e4f951020d9befd048357e230d851ce1facc24a1e5f38ec6f71c010c9e087987e5b0f96f555e8bec603
data/lib/rs4/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RS4
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
data/lib/rs4.rb ADDED
@@ -0,0 +1,45 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+ require 'openssl'
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
18
+
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
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
45
+ end
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.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - donny
@@ -31,6 +31,7 @@ files:
31
31
  - lib/document.rb
32
32
  - lib/request_error.rb
33
33
  - lib/reusable_template.rb
34
+ - lib/rs4.rb
34
35
  - lib/rs4/version.rb
35
36
  - license.txt
36
37
  - rs4.gemspec