rasper_client 0.1.3 → 0.1.4

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: ad1b1e23e2e234873e1493e49377b95ef516f54a7d2cf2a4b069fd0c6c91f615
4
- data.tar.gz: c266e06cdb400c59345d29fc1086c8fa79c27b3fab5145d865dc4d49bbc6ebae
3
+ metadata.gz: e095ad00114767244b0b647545500383c9b1ed138934afd5cb0d0aad3ca3334d
4
+ data.tar.gz: 94d5c03f652b4e7044d7a95118ed18069f3d23a327ada852df25dac0e5181129
5
5
  SHA512:
6
- metadata.gz: b720447e9574241aae7a4f8a2463dc5c0188119e2d4c16158c03698aaa39c2922fba63baa42db030d1fca49c47b79226cc724cc91d6f65a93982f980d0fcd850
7
- data.tar.gz: 52b8b60cba6aa0e83c7209a38151554fbbcf9fc43cfb57889aaba8570de7b095ba060ffa66d1d5d1ab00ad6118d7342a12a7e10e2ed5b70b534d29065fecf3b7
6
+ metadata.gz: 4b37451fddf6dcb7dc397f966331c1509645d1652e58bb7f50012e39ed32bd1006781ef4e8b0fde5f041cb208db728b924e52753bb8008c206e9e2ba1a842259
7
+ data.tar.gz: a3947cbe7e623c748f75b829a5a57d1877d06a87d2a3b032f51ed5e3cff9b350d393efde588aba6f40ef9437108bc224bf0137ac9b1ea5a5599d25559c8bf168
@@ -4,8 +4,11 @@ require 'json'
4
4
 
5
5
  module RasperClient
6
6
  class Client
7
- def initialize(options)
8
- @host, @port, @timeout = options.values_at(:host, :port, :timeout)
7
+ def initialize(host:, port:, timeout: nil, empty_nil_values: false)
8
+ @host = host
9
+ @port = port
10
+ @timeout = timeout
11
+ @empty_nil_values = empty_nil_values
9
12
  @request_params = build_request_params
10
13
  end
11
14
 
@@ -14,12 +17,13 @@ module RasperClient
14
17
  encode_options(options)
15
18
  response = execute_request(:add, options)
16
19
  JSON.parse(response.body) == { 'success' => true }
17
- rescue Errno::ECONNREFUSED
20
+ rescue Errno::ECONNREFUSED, Errno::EADDRNOTAVAIL
18
21
  raise ConnectionRefusedError
19
22
  end
20
23
 
21
24
  def generate(options)
22
25
  symbolize_keys(options)
26
+ empty_nil_values(options) if @empty_nil_values
23
27
  options = encode_data(options)
24
28
  response = execute_request(:generate, options)
25
29
  result = JSON.parse(response.body)
@@ -71,6 +75,18 @@ module RasperClient
71
75
  { data: Base64.encode64(options.to_json) }
72
76
  end
73
77
 
78
+ def empty_nil_values(hash)
79
+ hash.each_key do |key|
80
+ if hash[key].is_a?(Hash)
81
+ empty_nil_values(hash[key])
82
+ elsif hash[key].is_a?(Array)
83
+ hash[key].each {|item| empty_nil_values(item) if item.is_a?(Hash) }
84
+ else
85
+ hash[key] = '' if hash[key].nil?
86
+ end
87
+ end
88
+ end
89
+
74
90
  def uri_for(action)
75
91
  "http://#{@host}:#{@port}/#{action}"
76
92
  end
@@ -1,3 +1,3 @@
1
1
  module RasperClient
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  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.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Manhães
@@ -115,8 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  - !ruby/object:Gem::Version
116
116
  version: '0'
117
117
  requirements: []
118
- rubyforge_project:
119
- rubygems_version: 2.7.6
118
+ rubygems_version: 3.0.3
120
119
  signing_key:
121
120
  specification_version: 4
122
121
  summary: JRuby client to RasperServer.