Class: Nis::Client
- Inherits:
-
Object
- Object
- Nis::Client
- Defined in:
- lib/nis/client.rb
Constant Summary collapse
- DEFAULTS =
{ url: -> {ENV['NIS_URL']}, scheme: 'http', host: '127.0.0.1', port: 7890, timeout: 5 }
Instance Attribute Summary collapse
-
#options ⇒ Hash
connection options.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
-
#request(method, path, params = nil, &block) ⇒ Hash
Hash converted API Response.
-
#request!(method, path, params = nil, &block) ⇒ Hash
Hash converted API Response.
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
23 24 25 |
# File 'lib/nis/client.rb', line 23 def initialize( = {}) @options = () end |
Instance Attribute Details
#options ⇒ Hash
connection options
6 7 8 |
# File 'lib/nis/client.rb', line 6 def @options end |
Instance Method Details
#request(method, path, params = nil, &block) ⇒ Hash
Returns Hash converted API Response.
31 32 33 34 35 36 |
# File 'lib/nis/client.rb', line 31 def request(method, path, params = nil, &block) params.reject! { |_, value| value.nil? } unless params.nil? body = connection.send(method, path, params).body hash = parse_body(body) unless body.size == 0 block_given? ? yield(hash) : hash end |
#request!(method, path, params = nil, &block) ⇒ Hash
Returns Hash converted API Response.
42 43 44 45 46 |
# File 'lib/nis/client.rb', line 42 def request!(method, path, params = nil, &block) hash = request(method, path, params) raise Nis::Util.error_handling(hash) if hash.has_key?(:error) block_given? ? yield(hash) : hash end |