Class: FacebookPlugin

Inherits:
Rubko::Plugin show all
Defined in:
lib/rubko/plugins/facebook.rb

Instance Attribute Summary collapse

Attributes included from Rubko::Base

#parent

Instance Method Summary collapse

Methods inherited from Rubko::Plugin

#config

Methods included from Rubko::Base

#camelize, #finalize, #httpGet, #initialize, #jsonParse, #loadController, #loadFile, #loadModel, #loadPlugin, #loadView, #method_missing, #uncamelize

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Rubko::Base

Instance Attribute Details

#homeObject

Returns the value of attribute home.



9
10
11
# File 'lib/rubko/plugins/facebook.rb', line 9

def home
  @home
end

#idObject

Returns the value of attribute id.



9
10
11
# File 'lib/rubko/plugins/facebook.rb', line 9

def id
  @id
end

#secretObject

Returns the value of attribute secret.



9
10
11
# File 'lib/rubko/plugins/facebook.rb', line 9

def secret
  @secret
end

#tokenObject (readonly)

Returns the value of attribute token.



10
11
12
# File 'lib/rubko/plugins/facebook.rb', line 10

def token
  @token
end

Instance Method Details

#initObject



4
5
6
7
# File 'lib/rubko/plugins/facebook.rb', line 4

def init
	@home = "http://#{url.host}/"
	config
end

#login(state, str) ⇒ Object

PART 2: Return user data, populate @token



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rubko/plugins/facebook.rb', line 22

def (state, str)
	raise 'Please supply the return value of #start to #login' unless state

	params = parse str
	return false if state != params['state']

	code = params['code']
	url = build 'https://graph.facebook.com/oauth/access_token', query.merge({
		client_secret: secret, code: code
	})
	@token = parse( httpGet url )['access_token']

	jsonParse httpGet build 'https://graph.facebook.com/me', access_token: token
end

#startObject

PART 1: Initiate login, ask user for permissions



13
14
15
16
17
18
19
# File 'lib/rubko/plugins/facebook.rb', line 13

def start
	SecureRandom.hex(16).tap { |state|
		url.redirect build 'https://www.facebook.com/dialog/oauth', query.merge({
			scope: 'email,publish_stream', state: state
		})
	}
end