Class: Facebokr::App
- Inherits:
-
Object
- Object
- Facebokr::App
- Defined in:
- lib/facebokr/app.rb
Instance Method Summary collapse
- #access_token ⇒ Object
-
#create_app_notification(fb_user_id, template, href = "") ⇒ Object
Creates an app notification from given Facebook application.
-
#create_app_request(fb_user_id, message, data = "") ⇒ Object
Creates an app request from given Facebook application.
-
#create_test_user(options = {}) ⇒ Object
Creates a test user for given Facebook application.
-
#initialize(app_id, app_secret) ⇒ App
constructor
A new instance of App.
Constructor Details
#initialize(app_id, app_secret) ⇒ App
Returns a new instance of App.
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_token ⇒ Object
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
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
44 45 46 47 48 49 50 51 |
# File 'lib/facebokr/app.rb', line 44 def create_app_request(fb_user_id, , data = "") require 'net/http' uri = og_uri(fb_user_id, "apprequests") response = JSON.parse(Net::HTTP.post_form(uri, :access_token => access_token, :message => , :data => data).body) end |
#create_test_user(options = {}) ⇒ Object
Creates a test user for given Facebook application
32 33 34 35 36 |
# File 'lib/facebokr/app.rb', line 32 def create_test_user( = {}) uri = og_uri(@app_id, "accounts/test-users", .merge(:access_token => access_token)) response = JSON.parse(open(uri).read) response["data"].first end |