Module: FbGraph::Connections::Subscriptions

Included in:
Application
Defined in:
lib/fb_graph/connections/subscriptions.rb

Instance Method Summary collapse

Instance Method Details

#subscribe!(options = {}) ⇒ Object

Subscribe

Subscriber have to setup PubSubHubbub subscriber endpoint. See details at “Subscription Verification” in the Facebook API document. ref) developers.facebook.com/docs/api/realtime

app = FbGraph::Application.new(APP_ID, :secret => APP_SECRET)
app.subscribe!(
  :object => "user",
  :fields => "name,email",
  :callback_url => "http://fbgraphsample.heroku.com/subscription",
  :verify_token => "Define by yourself"
)
=> Array of FbGraph::Subscriptions


31
32
33
34
# File 'lib/fb_graph/connections/subscriptions.rb', line 31

def subscribe!(options = {})
  options[:access_token] ||= self.access_token || get_access_token(options[:secret])
  post(options.merge(:connection => :subscriptions))
end

#subscriptions(options = {}) ⇒ Object

Fetch current subscriptions

app = FbGraph::Application.new(APP_ID, :secret => APP_SECRET)
app.subscriptions
=> Array of FbGraph::Subscriptions


9
10
11
12
13
14
15
# File 'lib/fb_graph/connections/subscriptions.rb', line 9

def subscriptions(options = {})
  options[:access_token] ||= self.access_token || get_access_token(options[:secret])
  subscriptions = self.connection(:subscriptions, options)
  subscriptions.map! do |subscription|
    Subscription.new(subscription.merge(:access_token => options[:access_token]))
  end
end

#unsubscribe!(options = {}) ⇒ Object

Subscribe

Delete all of your subscriptions. If you specify an object parameter, it will only delete the corresponding subscription. ref) developers.facebook.com/docs/api/realtime

app = FbGraph::Application.new(APP_ID, :secret => APP_SECRET)
app.unsubscribe!(
  :object => "user"
)
=> Array of FbGraph::Subscriptions


47
48
49
50
# File 'lib/fb_graph/connections/subscriptions.rb', line 47

def unsubscribe!(options = {})
  options[:access_token] ||= self.access_token || get_access_token(options[:secret])
  destroy(options.merge(:connection => :subscriptions))
end