Class: IostRuby::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/iost_ruby/client.rb

Constant Summary collapse

DEFAULTS =
{
  url:     -> { ENV['IOST_URL'] },
  scheme:  'http',
  host:    '127.0.0.1',
  port:    30001,
  timeout: 5
}.freeze

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 30001

  • :timeout (Symbol)

    default 5



25
26
27
# File 'lib/iost_ruby/client.rb', line 25

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

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



17
18
19
# File 'lib/iost_ruby/client.rb', line 17

def options
  @options
end

Instance Method Details

#request(method, path, params = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/iost_ruby/client.rb', line 29

def request(method, path, params = {})
  if params.is_a?(Hash) && !params.empty?
    params.reject! { |_, value| value.nil? }
  end

  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 = {}) ⇒ Object



40
41
42
43
44
# File 'lib/iost_ruby/client.rb', line 40

def request!(method, path, params = {})
  hash = request(method, path, params)
  raise error_handling(hash) if hash && hash.key?(:error)
  block_given? ? yield(hash) : hash
end