fgraph 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/History +3 -0
- data/VERSION.yml +1 -1
- data/lib/fgraph.rb +8 -0
- data/lib/fgraph/client.rb +4 -10
- data/lib/fgraph/rails/fgraph_helper.rb +75 -0
- data/lib/fgraph/rails/fgraph_tag_helper.rb +0 -0
- data/test/fgraph/client_test.rb +4 -4
- metadata +5 -4
- data/lib/tasks/fgraph.rake +0 -14
data/History
CHANGED
data/VERSION.yml
CHANGED
data/lib/fgraph.rb
CHANGED
@@ -8,6 +8,14 @@ module FGraph
|
|
8
8
|
base_uri 'https://graph.facebook.com'
|
9
9
|
format :json
|
10
10
|
|
11
|
+
def self.config
|
12
|
+
@@config
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.config=(config)
|
16
|
+
@@config = config
|
17
|
+
end
|
18
|
+
|
11
19
|
# Facebook Error
|
12
20
|
class FacebookError < StandardError
|
13
21
|
attr_reader :data
|
data/lib/fgraph/client.rb
CHANGED
@@ -50,21 +50,15 @@ module FGraph
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def objects(*args)
|
53
|
-
return if args.blank?
|
54
53
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
55
|
-
|
56
|
-
args
|
57
|
-
|
58
|
-
FGraph.objects(args)
|
54
|
+
args << {:access_token => self.options[:access_token]}.merge(options)
|
55
|
+
FGraph.objects(*args)
|
59
56
|
end
|
60
57
|
|
61
58
|
def me(*args)
|
62
|
-
return if args.blank?
|
63
59
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
64
|
-
|
65
|
-
args
|
66
|
-
|
67
|
-
FGraph.me(args)
|
60
|
+
args << {:access_token => self.options[:access_token]}.merge(options)
|
61
|
+
FGraph.me(*args)
|
68
62
|
end
|
69
63
|
|
70
64
|
def publish(id, options={})
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module FGraph
|
2
|
+
module Rails
|
3
|
+
module FGraphHelper
|
4
|
+
def fgraph_config
|
5
|
+
FGraph.config || {}
|
6
|
+
end
|
7
|
+
|
8
|
+
def fgraph_session(app_id = fgraph_config['app_id'],
|
9
|
+
app_secret = fgraph_config['app_secret'])
|
10
|
+
|
11
|
+
return @fgraph_session if @fgraph_session
|
12
|
+
@fgraph_session = fgraph_session_cookies(app_id, app_secret)
|
13
|
+
end
|
14
|
+
|
15
|
+
def fgraph_session_cookies(app_id = fgraph_config['app_id'],
|
16
|
+
app_secret = fgraph_config['app_secret'])
|
17
|
+
|
18
|
+
return @fgraph_session_cookies if @fgraph_session_cookies
|
19
|
+
return if @fgraph_session_cookies == false
|
20
|
+
|
21
|
+
# retrieve session from cookies
|
22
|
+
fbs_cookies = request.cookies["fbs_#{app_id}"]
|
23
|
+
if app_id.blank? or app_secret.blank? or fbs_cookies.blank?
|
24
|
+
return @fgraph_session_cookies = false
|
25
|
+
end
|
26
|
+
|
27
|
+
# Parse facebook cookies
|
28
|
+
fbs_cookies = CGI.parse(fbs_cookies.gsub!(/(^\"|\"$)/, ''))
|
29
|
+
session_cookies = {}
|
30
|
+
fbs_cookies.each do |key, value|
|
31
|
+
session_cookies[key] = value[0]
|
32
|
+
end
|
33
|
+
|
34
|
+
# Validate session cookies
|
35
|
+
cookie_message = ''
|
36
|
+
session_cookies_list = session_cookies.sort
|
37
|
+
session_cookies_list.each do |cookie|
|
38
|
+
cookie_message += "#{cookie[0]}=#{cookie[1]}" if cookie[0] != 'sig'
|
39
|
+
end
|
40
|
+
|
41
|
+
# Message digest does not match
|
42
|
+
if Digest::MD5.hexdigest(cookie_message + app_secret) != session_cookies['sig']
|
43
|
+
@fgraph_session_cookies = false
|
44
|
+
end
|
45
|
+
|
46
|
+
@fgraph_session_cookies = session_cookies
|
47
|
+
end
|
48
|
+
|
49
|
+
def fgraph_access_token
|
50
|
+
return unless fgraph_session
|
51
|
+
fgraph_session['access_token']
|
52
|
+
end
|
53
|
+
|
54
|
+
def fgraph_logged_in?
|
55
|
+
return true if fgraph_session and fgraph_access_token
|
56
|
+
end
|
57
|
+
|
58
|
+
def fgraph_current_user
|
59
|
+
return @fgraph_current_user if @fgraph_current_user
|
60
|
+
@fgraph_current_user = fgraph_client.me
|
61
|
+
end
|
62
|
+
|
63
|
+
def fgraph_client
|
64
|
+
return @fgraph_client if @fgraph_client
|
65
|
+
session = fgraph_session || {}
|
66
|
+
|
67
|
+
@fgraph_client = FGraph::Client.new(
|
68
|
+
:client_id => fgraph_config['app_id'],
|
69
|
+
:client_secret => fgraph_config['app_secret'],
|
70
|
+
:access_token => fgraph_access_token
|
71
|
+
)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
File without changes
|
data/test/fgraph/client_test.rb
CHANGED
@@ -54,10 +54,10 @@ class ClientTest < Test::Unit::TestCase
|
|
54
54
|
|
55
55
|
context "FGraph::Client#objects" do
|
56
56
|
should "call FGraph.objects with :access_token option" do
|
57
|
-
FGraph.expects(:objects).with(
|
57
|
+
FGraph.expects(:objects).with('1', '2', {
|
58
58
|
:access_token => FACEBOOK_OAUTH_ACCESS_TOKEN,
|
59
59
|
:fields => 'publish_stream'
|
60
|
-
}
|
60
|
+
})
|
61
61
|
|
62
62
|
fb_client.objects('1', '2', :fields => 'publish_stream')
|
63
63
|
end
|
@@ -65,10 +65,10 @@ class ClientTest < Test::Unit::TestCase
|
|
65
65
|
|
66
66
|
context "FGraph::Client#me" do
|
67
67
|
should "call FGraph.me with :access_token option" do
|
68
|
-
FGraph.expects(:me).with(
|
68
|
+
FGraph.expects(:me).with({
|
69
69
|
:access_token => FACEBOOK_OAUTH_ACCESS_TOKEN,
|
70
70
|
:fields => 'publish_stream'
|
71
|
-
}
|
71
|
+
})
|
72
72
|
|
73
73
|
fb_client.me(:fields => 'publish_stream')
|
74
74
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 5
|
9
|
+
version: 0.1.5
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Herryanto Siatono
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-25 00:00:00 +08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -105,7 +105,8 @@ files:
|
|
105
105
|
- examples/publish_feed.rb
|
106
106
|
- lib/fgraph.rb
|
107
107
|
- lib/fgraph/client.rb
|
108
|
-
- lib/
|
108
|
+
- lib/fgraph/rails/fgraph_helper.rb
|
109
|
+
- lib/fgraph/rails/fgraph_tag_helper.rb
|
109
110
|
- test/fgraph/client_test.rb
|
110
111
|
- test/fgraph_test.rb
|
111
112
|
- test/fixtures/access_token.txt
|
data/lib/tasks/fgraph.rake
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
|
3
|
-
namespace :fgraph do
|
4
|
-
desc "Create fgraph.yml configuration file in Rails config folder"
|
5
|
-
task :setup => :environment do
|
6
|
-
fgraph_config = File.join(RAILS_ROOT, "config", "fgraph.yml")
|
7
|
-
unless File.exist?(fgraph_config)
|
8
|
-
|
9
|
-
else
|
10
|
-
puts "#{RAILS_ROOT}/config/fgraph.yml already exists."
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|