Class: Facebokr::App

Inherits:
Object
  • Object
show all
Defined in:
lib/facebokr/app.rb

Instance Method Summary collapse

Constructor Details

#initialize(app_id, app_secret) ⇒ App

Returns a new instance of App.

Parameters:

  • app_id (String)

    Facebook application id

  • app_secret (String)

    Facebook application secret



13
14
15
16
# File 'lib/facebokr/app.rb', line 13

def initialize(app_id, app_secret)
  @app_id     = app_id
  @app_secret = app_secret
end

Instance Method Details

#access_tokenObject



18
19
20
21
22
23
24
# File 'lib/facebokr/app.rb', line 18

def access_token
  @access_token ||= begin
    uri = og_uri("oauth/access_token", :client_id => @app_id, :client_secret => @app_secret, :grant_type => "client_credentials")
    response = open(uri).read
    response.gsub(/^access_token=/, "")
  end
end

#create_app_notification(fb_user_id, template, href = "") ⇒ Object

Creates an app notification from given Facebook application

Parameters:

  • fb_user_id (String)

    Facebook user id

  • template (String)

    Notification message template

  • href (String) (defaults to: "")

    optional href (relative path) to redirect user to



59
60
61
62
63
64
65
66
# File 'lib/facebokr/app.rb', line 59

def create_app_notification(fb_user_id, template, href = "")
  require 'net/http'
  uri = og_uri(fb_user_id, "notifications")
  response = JSON.parse(Net::HTTP.post_form(uri,
                                            :access_token => access_token,
                                            :template => template,
                                            :href => href).body)
end

#create_app_request(fb_user_id, message, data = "") ⇒ Object

Creates an app request from given Facebook application

Parameters:

  • fb_user_id (String)

    Facebook user id

  • message (String)

    Request message text

  • data (String) (defaults to: "")

    Optional request data



44
45
46
47
48
49
50
51
# File 'lib/facebokr/app.rb', line 44

def create_app_request(fb_user_id, message, data = "")
  require 'net/http'
  uri = og_uri(fb_user_id, "apprequests")
  response = JSON.parse(Net::HTTP.post_form(uri,
                                            :access_token => access_token,
                                            :message => message,
                                            :data => data).body)
end

#create_test_user(options = {}) ⇒ Object

Creates a test user for given Facebook application

Parameters:

  • options (Hash) (defaults to: {})

    Facebook test user options

  • installed (Hash)

    a customizable set of options

  • permissions (Hash)

    a customizable set of options



32
33
34
35
36
# File 'lib/facebokr/app.rb', line 32

def create_test_user(options = {})
  uri = og_uri(@app_id, "accounts/test-users", options.merge(:access_token => access_token))
  response = JSON.parse(open(uri).read)
  response["data"].first
end