Class: Nis::Client

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.

Parameters:

  • options (hash) (defaults to: {})

    HTTP Client connection information

Options Hash (options):

  • :url (Symbol)

    URL

  • :scheme (Symbol)

    default http (http only)

  • :host (Symbol)

    default 127.0.0.1

  • :port (Symbol)

    default 7890

  • :timeout (Symbol)

    default 5



23
24
25
# File 'lib/nis/client.rb', line 23

def initialize(options = {})
  @options = parse_options(options)
end

Instance Attribute Details

#optionsHash

connection options

Returns:

  • (Hash)

    the current value of options



6
7
8
# File 'lib/nis/client.rb', line 6

def options
  @options
end

Instance Method Details

#request(method, path, params = nil, &block) ⇒ Hash

Returns Hash converted API Response.

Parameters:

  • method (Symbol)

    HTTP Method(GET or POST)

  • path (String)

    API Path

  • params (Hash) (defaults to: nil)

    API Parameters

Returns:

  • (Hash)

    Hash converted API Response



31
32
33
34
35
# File 'lib/nis/client.rb', line 31

def request(method, path, params = nil, &block)
  body = connection.send(method, path, params).body
  hash = parse_body(body) unless body.size == 0
  block_given? ? yield(hash) : hash
end