Class: Aboie::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key = nil) ⇒ Client

Returns a new instance of Client.



4
5
6
# File 'lib/aboie/client.rb', line 4

def initialize(api_key=nil)
  self.api_key = api_key || Aboie.configuration.api_key
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



3
4
5
# File 'lib/aboie/client.rb', line 3

def api_key
  @api_key
end

Instance Method Details

#send_text(who, msg) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/aboie/client.rb', line 8

def send_text(who, msg)

  payload = {
    recipient: {id: who},
    message: {text: msg}
  }

  begin
    RestClient.post("https://graph.facebook.com/v2.6/me/messages?access_token=#{self.api_key}",
      payload.to_json,
      {accept: :json, content_type: :json}
    )
  rescue StandardError => e
    puts e.response.inspect
    puts e.response.body
    raise e
  end
end