fb_rails 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +12 -6
- data/lib/fb_rails/graph.rb +14 -14
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -41,14 +41,20 @@ Get the Facebook user id for the current user:
|
|
41
41
|
|
42
42
|
fb.uid
|
43
43
|
|
44
|
+
Retrieve your Facebook application app_id or secret:
|
45
|
+
fb.app_id
|
46
|
+
fb.secret
|
47
|
+
|
48
|
+
|
49
|
+
== Using the Graph
|
50
|
+
|
44
51
|
Make a request to the Facebook Graph:
|
45
52
|
|
46
|
-
<% result = fb.graph.get '
|
53
|
+
<% result = fb.graph.get 'me' %>
|
47
54
|
my name is <%= result['first_name'] %>
|
48
55
|
|
49
|
-
|
50
|
-
fb.
|
51
|
-
fb.secret
|
56
|
+
Post to the user's wall:
|
57
|
+
fb.graph.post 'me/feed', :message => 'I like turtles'
|
52
58
|
|
53
59
|
|
54
60
|
== Persisting the Facebook User:
|
@@ -76,11 +82,11 @@ One thing I like to do for new Facebook users is store them in a before filter:
|
|
76
82
|
|
77
83
|
== Testing
|
78
84
|
|
79
|
-
Facebook requests can be mocked, so that your
|
85
|
+
Facebook requests can be mocked, so that your tests do not require real HTTP
|
80
86
|
connections. This is done with FbRails::Mock:
|
81
87
|
|
82
88
|
FbRails::Mock.respond_to do |mock|
|
83
89
|
mock.add 'me', 'first_name' => 'Matt', 'last_name' => 'Higgins'
|
84
90
|
end
|
85
91
|
|
86
|
-
Now, a call to
|
92
|
+
Now, a call to fb.graph.get('me') returns the above response.
|
data/lib/fb_rails/graph.rb
CHANGED
@@ -17,21 +17,26 @@ module FbRails
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
21
|
-
|
20
|
+
def get(path, params)
|
21
|
+
request(:get, "#{path}?#{build_param_string(params)}")
|
22
|
+
end
|
23
|
+
|
24
|
+
def post(path, params)
|
25
|
+
request(:post, path, build_param_string(params))
|
26
|
+
end
|
22
27
|
|
28
|
+
def request(http_verb, path, *arguments)
|
23
29
|
response = ActiveSupport::Notifications.instrument('request.fb_rails') do |payload|
|
24
30
|
payload[:http_verb] = http_verb
|
25
|
-
payload[:request_uri] =
|
26
|
-
http.send(http_verb,
|
31
|
+
payload[:request_uri] = path
|
32
|
+
http.send(http_verb, path, *arguments)
|
27
33
|
end
|
28
34
|
|
29
35
|
ActiveSupport::JSON.decode(response.body)
|
30
36
|
end
|
31
37
|
|
32
|
-
def
|
33
|
-
|
34
|
-
"#{path}?#{param_string}"
|
38
|
+
def build_param_string(params)
|
39
|
+
params.map { |key, value| "#{key}=#{Rack::Utils.escape(value)}" }.join('&')
|
35
40
|
end
|
36
41
|
end
|
37
42
|
|
@@ -41,16 +46,11 @@ module FbRails
|
|
41
46
|
end
|
42
47
|
|
43
48
|
def post(path, params = {})
|
44
|
-
|
49
|
+
self.class.post(path, params.merge(:access_token => connect.access_token))
|
45
50
|
end
|
46
51
|
|
47
52
|
def get(path, params = {})
|
48
|
-
|
53
|
+
self.class.get(path, params.merge(:access_token => connect.access_token))
|
49
54
|
end
|
50
|
-
|
51
|
-
private
|
52
|
-
def request(http_verb, path, params)
|
53
|
-
self.class.request(http_verb, path, params.merge(:access_token => connect.access_token))
|
54
|
-
end
|
55
55
|
end
|
56
56
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 6
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.6.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Matthew Higgins
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-
|
17
|
+
date: 2011-02-07 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|