Class: Messenger::Client

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

Class Method Summary collapse

Class Method Details

.get_user_profile(user_id) ⇒ Object



3
4
5
6
7
# File 'lib/messenger/client.rb', line 3

def self.(user_id)
  JSON.parse(RestClient.get(
    "https://graph.facebook.com/v2.6/#{user_id}?access_token=#{Messenger.config.page_access_token}",
  ))
end

.send(data) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/messenger/client.rb', line 9

def self.send(data)
  RestClient.post(
    "https://graph.facebook.com/v2.6/me/messages?access_token=#{Messenger.config.page_access_token}",
    data.build.to_json,
    content_type: :json
  )
rescue RestClient::ExceptionWithResponse => err
  puts "\nFacebook API response from invalid request:\n#{err.response}\n\n"
end