rasper_client 0.1.4 → 0.1.5
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/lib/rasper_client.rb +2 -2
- data/lib/rasper_client/client.rb +31 -10
- data/lib/rasper_client/error.rb +11 -0
- data/lib/rasper_client/fake_server.rb +26 -14
- data/lib/rasper_client/version.rb +1 -1
- metadata +3 -3
- data/lib/rasper_client/errors.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c4a041873bc25ff2131ace5c3c375ff3982a28af94541d4486d9e6a9c43d6a8
|
4
|
+
data.tar.gz: c84ffdf095ca4ca14e4c9c256cdfcd61acf22ef85a6df9e680147662df0428df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aeacb357e4fd2859c1616e41e912c7586ab5f60bfb18eaf1a307888a0ab8286353c0d7fbc41d27935881ce69da5294c72fff0e1ddc78c29087efa1dbd1605bee
|
7
|
+
data.tar.gz: be28beb6432db0dd655b895c570848918f6fdadce4ad49fa040abcf5a6cfcc38c88267612d33cc4800ffce2247d6339080a49c2adb3f1f85b456dd23cd3941fa
|
data/lib/rasper_client.rb
CHANGED
data/lib/rasper_client/client.rb
CHANGED
@@ -4,12 +4,17 @@ require 'json'
|
|
4
4
|
|
5
5
|
module RasperClient
|
6
6
|
class Client
|
7
|
-
def initialize(host:, port
|
7
|
+
def initialize(host:, port: nil, timeout: nil, path_prefix: nil,
|
8
|
+
secure: true, empty_nil_values: false,
|
9
|
+
username: nil, password: nil)
|
8
10
|
@host = host
|
9
11
|
@port = port
|
10
12
|
@timeout = timeout
|
11
13
|
@empty_nil_values = empty_nil_values
|
12
|
-
@
|
14
|
+
@path_prefix = path_prefix
|
15
|
+
@secure = secure
|
16
|
+
@username = username
|
17
|
+
@password = password
|
13
18
|
end
|
14
19
|
|
15
20
|
def add(options)
|
@@ -17,8 +22,6 @@ module RasperClient
|
|
17
22
|
encode_options(options)
|
18
23
|
response = execute_request(:add, options)
|
19
24
|
JSON.parse(response.body) == { 'success' => true }
|
20
|
-
rescue Errno::ECONNREFUSED, Errno::EADDRNOTAVAIL
|
21
|
-
raise ConnectionRefusedError
|
22
25
|
end
|
23
26
|
|
24
27
|
def generate(options)
|
@@ -33,17 +36,21 @@ module RasperClient
|
|
33
36
|
private
|
34
37
|
|
35
38
|
def execute_request(action, options)
|
36
|
-
Net::HTTP.start(
|
39
|
+
response = Net::HTTP.start(*build_request_params) do |http|
|
37
40
|
request = Net::HTTP::Post.new(uri_for(action))
|
38
41
|
request.body = options.to_json
|
42
|
+
request.basic_auth(@username, @password) if @username && @password
|
39
43
|
http.request(request)
|
40
44
|
end
|
45
|
+
check_for_errors(response)
|
46
|
+
response
|
41
47
|
end
|
42
48
|
|
43
49
|
def build_request_params
|
44
|
-
|
45
|
-
|
46
|
-
|
50
|
+
options = {}
|
51
|
+
options[:read_timeout] = @timeout if @timeout
|
52
|
+
options[:use_ssl] = true if @secure
|
53
|
+
[@host, @port, options].compact
|
47
54
|
end
|
48
55
|
|
49
56
|
def symbolize_keys(options)
|
@@ -59,7 +66,7 @@ module RasperClient
|
|
59
66
|
end
|
60
67
|
|
61
68
|
def symbolize_key(hash, key)
|
62
|
-
hash[key.to_sym] = hash.delete(key.to_s) if hash.
|
69
|
+
hash[key.to_sym] = hash.delete(key.to_s) if hash.key?(key.to_s)
|
63
70
|
end
|
64
71
|
|
65
72
|
def encode_options(options)
|
@@ -88,7 +95,21 @@ module RasperClient
|
|
88
95
|
end
|
89
96
|
|
90
97
|
def uri_for(action)
|
91
|
-
|
98
|
+
uri_build_class
|
99
|
+
.build(
|
100
|
+
host: @host,
|
101
|
+
port: @port,
|
102
|
+
path: "#{@path_prefix}/#{action}"
|
103
|
+
)
|
104
|
+
.to_s
|
105
|
+
end
|
106
|
+
|
107
|
+
def uri_build_class
|
108
|
+
@secure ? URI::HTTPS : URI::HTTP
|
109
|
+
end
|
110
|
+
|
111
|
+
def check_for_errors(response)
|
112
|
+
raise RasperClient::Error.invalid_credentials if response.code.to_i == 401
|
92
113
|
end
|
93
114
|
end
|
94
115
|
end
|
@@ -10,8 +10,12 @@ module RasperClient
|
|
10
10
|
attr_accessor :last_added_report, :last_generated_report
|
11
11
|
end
|
12
12
|
|
13
|
-
def start(port)
|
14
|
-
@thread = Thread.new
|
13
|
+
def start(port, username, password)
|
14
|
+
@thread = Thread.new do
|
15
|
+
FakeAppCreator
|
16
|
+
.create(username: username, password: password)
|
17
|
+
.run!(port: port, quiet: true)
|
18
|
+
end
|
15
19
|
sleep 1
|
16
20
|
self
|
17
21
|
end
|
@@ -22,18 +26,26 @@ module RasperClient
|
|
22
26
|
end
|
23
27
|
end
|
24
28
|
|
25
|
-
class
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
class FakeAppCreator < Sinatra::Application
|
30
|
+
def self.create(username: nil, password: nil)
|
31
|
+
Class.new(Sinatra::Application) do
|
32
|
+
use Rack::Auth::Basic, "Protected Area" do |user, pass|
|
33
|
+
username == user && password == pass
|
34
|
+
end if username && password
|
35
|
+
|
36
|
+
post '/add' do
|
37
|
+
content_type :json
|
38
|
+
FakeServer.last_added_report = JSON.parse(request.body.read)
|
39
|
+
{ success: true }.to_json
|
40
|
+
end
|
31
41
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
42
|
+
post '/generate' do
|
43
|
+
content_type :json
|
44
|
+
FakeServer.last_generated_report =
|
45
|
+
JSON.parse(Base64.decode64(JSON.parse(request.body.read)['data']))
|
46
|
+
{ content: Base64.encode64(File.read(resource('dummy.pdf'))) }.to_json
|
47
|
+
end
|
48
|
+
end
|
37
49
|
end
|
38
50
|
end
|
39
|
-
end
|
51
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rasper_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo Manhães
|
@@ -93,7 +93,7 @@ files:
|
|
93
93
|
- Rakefile
|
94
94
|
- lib/rasper_client.rb
|
95
95
|
- lib/rasper_client/client.rb
|
96
|
-
- lib/rasper_client/
|
96
|
+
- lib/rasper_client/error.rb
|
97
97
|
- lib/rasper_client/fake_server.rb
|
98
98
|
- lib/rasper_client/version.rb
|
99
99
|
homepage: https://github.com/rodrigomanhaes/rasper_client
|
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: '0'
|
117
117
|
requirements: []
|
118
|
-
rubygems_version: 3.
|
118
|
+
rubygems_version: 3.1.4
|
119
119
|
signing_key:
|
120
120
|
specification_version: 4
|
121
121
|
summary: JRuby client to RasperServer.
|
data/lib/rasper_client/errors.rb
DELETED