module Facebook::Messenger::Profile

This module provide functionality to manage the messenger profile. @see developers.facebook.com/docs/messenger-platform/messenger-profile

Public Instance Methods

default_options() click to toggle source

Default HTTParty options.

@return [Hash] Default HTTParty options.

Calls superclass method
# File lib/facebook/messenger/profile.rb, line 78
def default_options
  super.merge(
    headers: {
      'Content-Type' => 'application/json'
    }
  )
end
raise_errors(response) click to toggle source

Function raise error if response has error key.

@raise [Facebook::Messenger::Profile::Error] if error is present

in response.

@param [Hash] response Response hash from facebook.

# File lib/facebook/messenger/profile.rb, line 69
def raise_errors(response)
  raise Error, response['error'] if response.key? 'error'
end
set(settings, access_token:) click to toggle source

Set the messenger profile.

@raise [Facebook::Messenger::Profile::Error] if there is any error

in response.

@param [Hash] settings Hash defining the profile settings. @param [String] access_token Access token of facebook page.

@return [Boolean] If profile is successfully set, return true.

# File lib/facebook/messenger/profile.rb, line 30
def set(settings, access_token:)
  response = post '/messenger_profile', body: settings.to_json, query: {
    access_token: access_token
  }

  raise_errors(response)

  true
end
unset(settings, access_token:) click to toggle source

Unset the messenger profile.

@raise [Facebook::Messenger::Profile::Error] if there is any error

in response.

@param [Hash] settings Hash defining the profile settings. @param [String] access_token Access token of facebook page.

@return [Boolean] If profile is successfully removed, return true.

# File lib/facebook/messenger/profile.rb, line 51
def unset(settings, access_token:)
  response = delete '/messenger_profile', body: settings.to_json, query: {
    access_token: access_token
  }

  raise_errors(response)

  true
end