Module: Facebook::Messenger::Subscriptions

Includes:
HTTParty
Defined in:
lib/facebook/messenger/subscriptions.rb

Overview

Module Subscriptions handles subscribing and unsubscribing Applications

to Pages.

Defined Under Namespace

Classes: Error

Class Method Summary collapse

Class Method Details

.raise_errors(response) ⇒ Object

If there is any error in response, raise error.

Raises:


72
73
74
# File 'lib/facebook/messenger/subscriptions.rb', line 72

def raise_errors(response)
  raise Error, response['error'] if response.key? 'error'
end

.subscribe(access_token:) ⇒ Boolean

Function subscribe the facebook app to page.

Raises:

See Also:


30
31
32
33
34
35
36
37
38
# File 'lib/facebook/messenger/subscriptions.rb', line 30

def subscribe(access_token:)
  response = post '/subscribed_apps', query: {
    access_token: access_token
  }

  raise_errors(response)

  true
end

.unsubscribe(access_token:) ⇒ Boolean

Function unsubscribe the app from facebook page.

Raises:

See Also:


52
53
54
55
56
57
58
59
60
# File 'lib/facebook/messenger/subscriptions.rb', line 52

def unsubscribe(access_token:)
  response = delete '/subscribed_apps', query: {
    access_token: access_token
  }

  raise_errors(response)

  true
end