Module: Facebook::Messenger::Subscriptions

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

Overview

This module handles subscribing and unsubscribing Applications to Pages.

Defined Under Namespace

Classes: Error

Class Method Summary collapse

Class Method Details

.raise_errors(response) ⇒ Object

Raises:


31
32
33
# File 'lib/facebook/messenger/subscriptions.rb', line 31

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

.subscribeObject


11
12
13
14
15
16
17
18
19
# File 'lib/facebook/messenger/subscriptions.rb', line 11

def self.subscribe
  response = post '/subscribed_apps', format: :json, query: {
    access_token: Facebook::Messenger.config.access_token
  }

  raise_errors(response)

  true
end

.unsubscribeObject


21
22
23
24
25
26
27
28
29
# File 'lib/facebook/messenger/subscriptions.rb', line 21

def self.unsubscribe
  response = delete '/subscribed_apps', format: :json, query: {
    access_token: Facebook::Messenger.config.access_token
  }

  raise_errors(response)

  true
end