sinbook 0.1.8 → 0.1.9
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 +25 -1
- data/examples/connect.rb +0 -1
- data/examples/simple.rb +0 -1
- data/lib/sinbook.rb +26 -12
- data/sinbook.gemspec +2 -2
- metadata +2 -2
data/README
CHANGED
@@ -84,6 +84,19 @@ sinbook: simple sinatra facebook extension in 300 lines of ruby
|
|
84
84
|
=> [{:name => 'Sinatra Users'}]
|
85
85
|
|
86
86
|
|
87
|
+
=== Standalone Usage
|
88
|
+
|
89
|
+
require 'sinbook'
|
90
|
+
fb = Sinbook.new(
|
91
|
+
:api_key => '4579...cbb0',
|
92
|
+
:secret => '5106...2342',
|
93
|
+
:app_id => 81747826609
|
94
|
+
)
|
95
|
+
|
96
|
+
>> fb.friends.get :uid => 1234, :session_key => 'user-session-key'
|
97
|
+
=> [4321,4567,9876]
|
98
|
+
|
99
|
+
|
87
100
|
=== Local Development
|
88
101
|
|
89
102
|
To develop locally, use ssh to setup a reverse tunnel to your external server.
|
@@ -94,10 +107,21 @@ sinbook: simple sinatra facebook extension in 300 lines of ruby
|
|
94
107
|
Then, simply launch sinatra on your local machine. Facebook will make requests to
|
95
108
|
http://myserver.com:4567/ which will be forwarded to port 4567 on your local machine.
|
96
109
|
|
110
|
+
For facebook connect, I generally add a CNAME on my domain for fb.myserver.com, and setup
|
111
|
+
nginx on my server with the following:
|
112
|
+
|
113
|
+
server {
|
114
|
+
server_name fb.myserver.com;
|
115
|
+
location / {
|
116
|
+
proxy_pass http://localhost:4567;
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
120
|
+
Make sure your connect url is set to 'http://myserver.com' and the base domain is set to 'myserver.com',
|
121
|
+
so that the fb.myserver.com subdomain works.
|
97
122
|
|
98
123
|
=== TODO
|
99
124
|
|
100
|
-
* Split out facebook api client so it can be used outside sinatra
|
101
125
|
* Add a batch mode for api calls:
|
102
126
|
|
103
127
|
groups, pics = fb.batch do |b|
|
data/examples/connect.rb
CHANGED
data/examples/simple.rb
CHANGED
data/lib/sinbook.rb
CHANGED
@@ -15,15 +15,23 @@ module Sinatra
|
|
15
15
|
|
16
16
|
class FacebookObject
|
17
17
|
def initialize app
|
18
|
-
|
18
|
+
if app.respond_to?(:options)
|
19
|
+
@app = app
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
[ :api_key, :secret, :app_id, :url, :callback, :symbolize_keys ].each do |var|
|
22
|
+
instance_variable_set("@#{var}", app.options.send("facebook_#{var}"))
|
23
|
+
end
|
24
|
+
else
|
25
|
+
[ :api_key, :secret, :app_id ].each do |var|
|
26
|
+
raise ArgumentError, "missing option #{var}" unless app[var]
|
27
|
+
instance_variable_set("@#{var}", app[var])
|
28
|
+
end
|
29
|
+
[:url, :callback, :symbolize_keys ].each do |var|
|
30
|
+
instance_variable_set("@#{var}", app[var]) if app.has_key?(var)
|
31
|
+
end
|
32
|
+
end
|
26
33
|
end
|
34
|
+
|
27
35
|
attr_reader :app
|
28
36
|
attr_accessor :api_key, :secret
|
29
37
|
attr_writer :url, :callback, :app_id
|
@@ -58,7 +66,11 @@ module Sinatra
|
|
58
66
|
|
59
67
|
def redirect url
|
60
68
|
url = self.url + url unless url =~ /^http/
|
61
|
-
|
69
|
+
if params[:in_iframe]
|
70
|
+
app.body "<script type=\"text/javascript\">top.location.href=\"#{url}\"</script>"
|
71
|
+
else
|
72
|
+
app.body "<fb:redirect url='#{url}'/>"
|
73
|
+
end
|
62
74
|
throw :halt
|
63
75
|
end
|
64
76
|
|
@@ -91,7 +103,9 @@ module Sinatra
|
|
91
103
|
end
|
92
104
|
|
93
105
|
def valid?
|
94
|
-
if app.
|
106
|
+
if app.nil?
|
107
|
+
return false
|
108
|
+
elsif app.params['fb_sig'] # canvas/iframe mode
|
95
109
|
prefix = 'fb_sig'
|
96
110
|
vars = app.request.POST[prefix] ? app.request.POST : app.request.GET
|
97
111
|
elsif app.request.cookies[api_key] # fbconnect mode
|
@@ -240,11 +254,10 @@ module Sinatra
|
|
240
254
|
MimeImage = %[Content-Disposition: form-data; filename="%s"\r\nContent-Type: image/%s\r\n\r\n%s\r\n] + MimeBoundary
|
241
255
|
|
242
256
|
require 'resolv'
|
243
|
-
API_SERVER = Resolv.getaddress('api.facebook.com')
|
244
257
|
@keepalive = false
|
245
258
|
|
246
259
|
def self.connect
|
247
|
-
sock = TCPSocket.new(
|
260
|
+
sock = TCPSocket.new(@api_server_ip ||= Resolv.getaddress('api.facebook.com'), 80)
|
248
261
|
begin
|
249
262
|
timeout = [3,0].pack('l_2') # 3 seconds
|
250
263
|
sock.setsockopt Socket::SOL_SOCKET, Socket::SO_RCVTIMEO, timeout
|
@@ -353,9 +366,10 @@ module Sinatra
|
|
353
366
|
def self.registered app
|
354
367
|
app.helpers FacebookHelper
|
355
368
|
app.before(&FixRequestMethod)
|
356
|
-
app.disable :sessions
|
357
369
|
end
|
358
370
|
end
|
359
371
|
|
360
372
|
Application.register Facebook
|
361
373
|
end
|
374
|
+
|
375
|
+
Sinbook = Sinatra::FacebookObject
|
data/sinbook.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
spec = Gem::Specification.new do |s|
|
2
2
|
s.name = 'sinbook'
|
3
|
-
s.version = '0.1.
|
4
|
-
s.date = '
|
3
|
+
s.version = '0.1.9'
|
4
|
+
s.date = '2010-02-04'
|
5
5
|
s.summary = 'simple sinatra facebook extension in 300 lines of ruby'
|
6
6
|
s.description = 'A full-featured facebook extension for the sinatra webapp framework'
|
7
7
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinbook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aman Gupta
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-02-04 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|