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 }.freeze
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 = {}) ⇒ Hash
Hash converted API Response.
-
#request!(method, path, params = {}) ⇒ Hash
Hash converted API Response.
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
24 25 26 |
# File 'lib/nis/client.rb', line 24 def initialize( = {}) @options = () end |
Instance Attribute Details
#options ⇒ Hash
connection options
7 8 9 |
# File 'lib/nis/client.rb', line 7 def @options end |
Instance Method Details
#request(method, path, params = {}) ⇒ Hash
Returns Hash converted API Response.
32 33 34 35 36 37 38 |
# File 'lib/nis/client.rb', line 32 def request(method, path, params = {}) params.reject! { |_, value| value.nil? } unless params.empty? res = connection.send(method, path, params) body = res.body hash = parse_body(body) unless body.empty? block_given? ? yield(hash) : hash end |
#request!(method, path, params = {}) ⇒ Hash
Returns Hash converted API Response.
45 46 47 48 49 |
# File 'lib/nis/client.rb', line 45 def request!(method, path, params = {}) hash = request(method, path, params) raise Nis::Util.error_handling(hash) if hash.key?(:error) block_given? ? yield(hash) : hash end |