Class: Upkey::Chatterly::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Client

Returns a new instance of Client.



20
21
22
23
24
25
26
# File 'lib/upkey/chatterly/client.rb', line 20

def initialize(args = {})
  MissingArgument.alert unless args[:access_key] && args[:chatterly_url]

  @access_key = args[:access_key]
  @chatterly_url = args[:chatterly_url]
  @conn = set_up_faraday
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/upkey/chatterly/client.rb', line 38

def method_missing(*args)
  case args[0]
  when :post_url
    Upkey::Chatterly::Urls::Builder.post_url(args[1], self)
  when :get_url
    Upkey::Chatterly::Urls::Accessor.get_url(args[1], self)
  else
    raise NoMethodError
  end
end

Instance Attribute Details

#access_keyObject (readonly)

Returns the value of attribute access_key.



18
19
20
# File 'lib/upkey/chatterly/client.rb', line 18

def access_key
  @access_key
end

#chatterly_urlObject (readonly)

Returns the value of attribute chatterly_url.



18
19
20
# File 'lib/upkey/chatterly/client.rb', line 18

def chatterly_url
  @chatterly_url
end

#connObject (readonly)

Returns the value of attribute conn.



18
19
20
# File 'lib/upkey/chatterly/client.rb', line 18

def conn
  @conn
end

Instance Method Details

#respond(args = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/upkey/chatterly/client.rb', line 28

def respond(args = {})
  key = args[:key]
  id = args[:id]

  message = Upkey::Chatterly::Accessor.get_message(self, key, id)
  resp = Upkey::Chatterly::Accessor.get_resp(self, message.body)

  Upkey::Chatterly::Response.new(message, resp)
end