Class: Evostream::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/evostream/client.rb', line 11

def initialize(options = {})
  # Merge the config values from the module and those passed
  # to the client.
  merged_options = Evostream.options.merge(options)

  # Copy the merged values to this client and ignore those
  # not part of our configuration
  Configuration::VALID_CONFIG_KEYS.each do |key|
    send("#{key}=", merged_options[key])
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object (private)



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/evostream/client.rb', line 24

def method_missing(method, *args)
  params = !args.empty? ? args.first : {}
  response = api_call(method, params)
  if response.code.to_i == 200
    json = parse(response.body)
    if json['status'] == 'SUCCESS'
      json['data']
    elsif json['status'] == 'FAIL' && json['description'] =~ /command .* not known/
      super
    else
      raise json['description']
    end
  else
    raise response.body
  end
end