facebooker 1.0.48 → 1.0.50
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/facebooker.gemspec +2 -2
- data/lib/facebooker.rb +1 -1
- data/lib/facebooker/adapters/facebook_adapter.rb +5 -1
- data/lib/facebooker/models/group.rb +1 -1
- data/lib/facebooker/models/user.rb +17 -13
- data/lib/facebooker/parser.rb +7 -0
- data/lib/facebooker/rails/helpers/fb_connect.rb +2 -2
- data/lib/facebooker/rails/publisher.rb +23 -2
- data/lib/facebooker/session.rb +7 -0
- data/lib/facebooker/version.rb +1 -1
- data/test/facebooker/models/user_test.rb +17 -0
- data/test/facebooker/rails/publisher_test.rb +31 -0
- data/test/facebooker/session_test.rb +1 -1
- metadata +2 -2
data/Rakefile
CHANGED
@@ -23,7 +23,7 @@ HOE = Hoe.spec('facebooker') do
|
|
23
23
|
self.readme_file = 'README.rdoc'
|
24
24
|
self.history_file = 'CHANGELOG.rdoc'
|
25
25
|
self.remote_rdoc_dir = '' # Release to root
|
26
|
-
self.test_globs = 'test/**/*_test.rb'
|
26
|
+
self.test_globs = ['test/**/*_test.rb']
|
27
27
|
extra_deps << ['json', '>= 1.0.0']
|
28
28
|
self.extra_rdoc_files = FileList['*.rdoc']
|
29
29
|
end
|
data/facebooker.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{facebooker}
|
5
|
-
s.version = "1.0.
|
5
|
+
s.version = "1.0.50"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Chad Fowler", "Patrick Ewing", "Mike Mangino", "Shane Vitarana", "Corey Innis", "Mike Mangino"]
|
9
|
-
s.date = %q{2009-08
|
9
|
+
s.date = %q{2009-09-08}
|
10
10
|
s.description = %q{Facebooker is a Ruby wrapper over the Facebook[http://facebook.com] {REST API}[http://wiki.developers.facebook.com/index.php/API]. Its goals are:
|
11
11
|
|
12
12
|
* Idiomatic Ruby
|
data/lib/facebooker.rb
CHANGED
@@ -164,7 +164,7 @@ module Facebooker
|
|
164
164
|
@timeout
|
165
165
|
end
|
166
166
|
|
167
|
-
[:api_key,:secret_key, :www_server_base_url,:login_url_base,:install_url_base,:permission_url_base,:api_rest_path,:api_server_base,:api_server_base_url,:canvas_server_base, :video_server_base].each do |delegated_method|
|
167
|
+
[:api_key,:secret_key, :www_server_base_url,:login_url_base,:install_url_base,:permission_url_base,:connect_permission_url_base,:api_rest_path,:api_server_base,:api_server_base_url,:canvas_server_base, :video_server_base].each do |delegated_method|
|
168
168
|
define_method(delegated_method){ return current_adapter.send(delegated_method)}
|
169
169
|
end
|
170
170
|
|
@@ -45,8 +45,12 @@ module Facebooker
|
|
45
45
|
"http://#{www_server_base_url}/install.php?api_key=#{api_key}&v=1.0"
|
46
46
|
end
|
47
47
|
|
48
|
+
def connect_permission_url_base
|
49
|
+
"http://#{www_server_base_url}/connect/prompt_permissions.php?api_key=#{api_key}&v=1.0"
|
50
|
+
end
|
51
|
+
|
48
52
|
def permission_url_base
|
49
|
-
"http://#{www_server_base_url}/
|
53
|
+
"http://#{www_server_base_url}/authorize.php?api_key=#{api_key}&v=1.0"
|
50
54
|
end
|
51
55
|
|
52
56
|
end
|
@@ -8,7 +8,7 @@ module Facebooker
|
|
8
8
|
attr_accessor :position, :gid, :uid
|
9
9
|
end
|
10
10
|
include Model
|
11
|
-
attr_accessor :pic, :pic_small, :pic_big, :name, :creator, :recent_news, :update_time, :group_subtype, :group_type, :website, :office, :description, :venue, :nid
|
11
|
+
attr_accessor :pic, :pic_small, :pic_big, :name, :creator, :recent_news, :update_time, :group_subtype, :group_type, :website, :office, :description, :venue, :nid, :privacy
|
12
12
|
|
13
13
|
id_is :gid
|
14
14
|
|
@@ -137,21 +137,25 @@ module Facebooker
|
|
137
137
|
# :text => 'my website',
|
138
138
|
# :href => 'http://tenderlovemaking.com/'
|
139
139
|
# ])
|
140
|
-
def publish_to
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
140
|
+
def publish_to(target, options = {})
|
141
|
+
@session.post('facebook.stream.publish', prepare_publish_to_options(target, options), false)
|
142
|
+
end
|
143
|
+
|
144
|
+
# Prepares options for the stream.publish
|
145
|
+
def prepare_publish_to_options(target, options)
|
146
|
+
opts = {:uid => self.id,
|
147
|
+
:target_id => target.id,
|
148
|
+
:message => options[:message]}
|
149
|
+
|
150
|
+
if(attachment = options[:attachment] && Facebooker.json_encode(options[:attachment]))
|
151
|
+
opts[:attachment] = attachment
|
152
|
+
end
|
153
|
+
if (links = options[:action_links] && Facebooker.json_encode(options[:action_links]))
|
154
|
+
opts[:action_links] = links
|
155
|
+
end
|
156
|
+
opts
|
152
157
|
end
|
153
158
|
|
154
|
-
|
155
159
|
###
|
156
160
|
# Publish a comment on a post
|
157
161
|
#
|
data/lib/facebooker/parser.rb
CHANGED
@@ -459,6 +459,12 @@ module Facebooker
|
|
459
459
|
array_of_hashes(element('data_getCookie_response', data), 'cookies')
|
460
460
|
end
|
461
461
|
end
|
462
|
+
|
463
|
+
class EventsRsvp < Parser#:nodoc:
|
464
|
+
def self.process(data)
|
465
|
+
element('events_rsvp_response', data).content.strip
|
466
|
+
end
|
467
|
+
end
|
462
468
|
|
463
469
|
class EventsGet < Parser#:nodoc:
|
464
470
|
def self.process(data)
|
@@ -662,6 +668,7 @@ module Facebooker
|
|
662
668
|
'facebook.stream.publish' => StreamPublish,
|
663
669
|
'facebook.stream.addComment' => StreamAddComment,
|
664
670
|
'facebook.events.get' => EventsGet,
|
671
|
+
'facebook.events.rsvp' => EventsRsvp,
|
665
672
|
'facebook.groups.get' => GroupsGet,
|
666
673
|
'facebook.events.getMembers' => EventMembersGet,
|
667
674
|
'facebook.groups.getMembers' => GroupGetMembers,
|
@@ -33,9 +33,9 @@ module Facebooker
|
|
33
33
|
end
|
34
34
|
|
35
35
|
if request.ssl?
|
36
|
-
init_string = "FB.
|
36
|
+
init_string = "FB.init('#{Facebooker.api_key}','/xd_receiver_ssl.html', #{options[:app_settings]});"
|
37
37
|
else
|
38
|
-
init_string = "FB.
|
38
|
+
init_string = "FB.init('#{Facebooker.api_key}','/xd_receiver.html', #{options[:app_settings]});"
|
39
39
|
end
|
40
40
|
unless required_features.blank?
|
41
41
|
init_string = <<-FBML
|
@@ -4,7 +4,7 @@ module Facebooker
|
|
4
4
|
#
|
5
5
|
# To use, create a subclass and define methods
|
6
6
|
# Each method should start by calling send_as to specify the type of message
|
7
|
-
# Valid options are :email and :notification, :user_action, :profile, :ref
|
7
|
+
# Valid options are :email and :notification, :user_action, :profile, :ref, :publish_stream
|
8
8
|
#
|
9
9
|
#
|
10
10
|
# Below is an example of each type
|
@@ -78,6 +78,16 @@ module Facebooker
|
|
78
78
|
# handle "a_ref_handle"
|
79
79
|
# end
|
80
80
|
#
|
81
|
+
# # Publish a post into the stream on the user's Wall and News Feed.
|
82
|
+
# def publish_stream(user_with_session_to_use, user_to_update, params)
|
83
|
+
# send_as :publish_stream
|
84
|
+
# from user_with_session_to_use
|
85
|
+
# target user_to_update
|
86
|
+
# attachment params[:attachment]
|
87
|
+
# message params[:message]
|
88
|
+
# action_links params[:action_links]
|
89
|
+
# end
|
90
|
+
#
|
81
91
|
#
|
82
92
|
# To send a message, use ActionMailer like semantics
|
83
93
|
# TestPublisher.deliver_action(@user)
|
@@ -250,6 +260,13 @@ module Facebooker
|
|
250
260
|
end
|
251
261
|
end
|
252
262
|
|
263
|
+
class PublishStream
|
264
|
+
attr_accessor :target
|
265
|
+
attr_accessor :attachment
|
266
|
+
attr_accessor :action_links
|
267
|
+
attr_accessor :message
|
268
|
+
end
|
269
|
+
|
253
270
|
cattr_accessor :ignore_errors
|
254
271
|
attr_accessor :_body
|
255
272
|
|
@@ -288,6 +305,8 @@ module Facebooker
|
|
288
305
|
Ref.new
|
289
306
|
when :user_action
|
290
307
|
UserAction.new
|
308
|
+
when :publish_stream
|
309
|
+
PublishStream.new
|
291
310
|
else
|
292
311
|
raise UnknownBodyType.new("Unknown type to publish")
|
293
312
|
end
|
@@ -399,6 +418,8 @@ module Facebooker
|
|
399
418
|
Facebooker::Session.create.server_cache.set_ref_handle(_body.handle,_body.fbml)
|
400
419
|
when UserAction
|
401
420
|
@from.session.publish_user_action(_body.template_id,_body.data_hash,_body.target_ids,_body.body_general,_body.story_size)
|
421
|
+
when PublishStream
|
422
|
+
@from.publish_to(_body.target, {:attachment => _body.attachment, :action_links => @action_links, :message => _body.message })
|
402
423
|
else
|
403
424
|
raise UnspecifiedBodyType.new("You must specify a valid send_as")
|
404
425
|
end
|
@@ -529,7 +550,7 @@ module Facebooker
|
|
529
550
|
args.each do |arg|
|
530
551
|
case arg
|
531
552
|
when Symbol,String
|
532
|
-
add_template_helper("#{arg.to_s.
|
553
|
+
add_template_helper("#{arg.to_s.camelcase}Helper".constantize)
|
533
554
|
when Module
|
534
555
|
add_template_helper(arg)
|
535
556
|
end
|
data/lib/facebooker/session.rb
CHANGED
@@ -127,6 +127,13 @@ module Facebooker
|
|
127
127
|
"#{Facebooker.permission_url_base}#{options.join}"
|
128
128
|
end
|
129
129
|
|
130
|
+
def connect_permission_url(permission,options={})
|
131
|
+
options = default_login_url_options.merge(options)
|
132
|
+
options = add_next_parameters(options)
|
133
|
+
options << "&ext_perm=#{permission}"
|
134
|
+
"#{Facebooker.connect_permission_url_base}#{options.join}"
|
135
|
+
end
|
136
|
+
|
130
137
|
def install_url_optional_parameters(options)
|
131
138
|
optional_parameters = []
|
132
139
|
optional_parameters += add_next_parameters(options)
|
data/lib/facebooker/version.rb
CHANGED
@@ -130,6 +130,14 @@ class Facebooker::UserTest < Test::Unit::TestCase
|
|
130
130
|
assert_equal "2357384227378429949", photos.first.aid
|
131
131
|
end
|
132
132
|
|
133
|
+
def test_prepare_publish_to_options_pass_only_neccessary_parameters
|
134
|
+
options = @user.prepare_publish_to_options(@user, {:message => 'Hey there', :action_links => [:text => 'Link', :href => 'http://example.com']})
|
135
|
+
assert_equal(options[:uid], @user.uid)
|
136
|
+
assert_equal(options[:target_id], @user.id)
|
137
|
+
assert_equal(options[:message], 'Hey there')
|
138
|
+
assert_nil(options[:attachment])
|
139
|
+
assert_equal(options[:action_links], [:text => 'Link', :href => 'http://example.com'].to_json )
|
140
|
+
end
|
133
141
|
def test_publish_to
|
134
142
|
@user = Facebooker::User.new(548871286, @session)
|
135
143
|
expect_http_posts_with_responses(example_profile_publish_to_get_xml)
|
@@ -369,4 +377,13 @@ class Facebooker::UserTest < Test::Unit::TestCase
|
|
369
377
|
<stream_addComment_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">703826862_78463536863</stream_addComment_response>
|
370
378
|
eoxml
|
371
379
|
end
|
380
|
+
|
381
|
+
def example_events_rsvp_xml
|
382
|
+
<<-E
|
383
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
384
|
+
<events_rsvp_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
385
|
+
xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">1
|
386
|
+
</events_rsvp_response>
|
387
|
+
E
|
388
|
+
end
|
372
389
|
end
|
@@ -137,6 +137,23 @@ class TestPublisher < Facebooker::Rails::Publisher
|
|
137
137
|
recipients to
|
138
138
|
end
|
139
139
|
|
140
|
+
def publish_post_to_own_stream(user)
|
141
|
+
send_as :publish_stream
|
142
|
+
from user
|
143
|
+
target user
|
144
|
+
attachment({:name => "Facebooker", :href => "http://www.exampple.com"})
|
145
|
+
message "Posting post to own stream"
|
146
|
+
action_links([{:text => "Action Link", :href => "http://www.example.com/action_link"}])
|
147
|
+
end
|
148
|
+
|
149
|
+
def publish_post_to_friends_stream(from, to)
|
150
|
+
send_as :publish_stream
|
151
|
+
from from
|
152
|
+
target to
|
153
|
+
attachment({:name => "Facebooker", :href => "http://www.exampple.com"})
|
154
|
+
message "Posting post to friends stream"
|
155
|
+
action_links([{:text => "Action Link", :href => "http://www.example.com/action_link"}])
|
156
|
+
end
|
140
157
|
end
|
141
158
|
|
142
159
|
class Facebooker::Rails::Publisher::FacebookTemplateTest < Test::Unit::TestCase
|
@@ -413,6 +430,20 @@ class Facebooker::Rails::Publisher::PublisherTest < Test::Unit::TestCase
|
|
413
430
|
}
|
414
431
|
end
|
415
432
|
|
433
|
+
def test_publish_post_to_own_stream
|
434
|
+
@user = Facebooker::User.new
|
435
|
+
@user.expects(:publish_to).with(@user, has_entry(:attachment=>instance_of(Hash)))
|
436
|
+
|
437
|
+
TestPublisher.deliver_publish_post_to_own_stream(@user)
|
438
|
+
end
|
439
|
+
|
440
|
+
def test_publish_post_to_friends_stream
|
441
|
+
@from_user = Facebooker::User.new
|
442
|
+
@to_user = Facebooker::User.new
|
443
|
+
@from_user.expects(:publish_to).with(@to_user, has_entry(:action_links=>instance_of(Array)))
|
444
|
+
|
445
|
+
TestPublisher.deliver_publish_post_to_friends_stream(@from_user, @to_user)
|
446
|
+
end
|
416
447
|
|
417
448
|
def test_keeps_class_method_missing
|
418
449
|
assert_raises(NoMethodError) {
|
@@ -24,7 +24,7 @@ class Facebooker::SessionTest < Test::Unit::TestCase
|
|
24
24
|
|
25
25
|
def test_permission_url_returns_correct_url_and_parameters
|
26
26
|
fb_url = "http://www.facebook.com/connect/prompt_permissions.php?api_key=#{ENV['FACEBOOK_API_KEY']}&v=1.0&next=next_url&ext_perm=publish_stream,email"
|
27
|
-
url = Facebooker::Session.new(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY']).
|
27
|
+
url = Facebooker::Session.new(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY']).connect_permission_url('publish_stream,email', {:next => 'next_url'})
|
28
28
|
assert_equal url, fb_url
|
29
29
|
end
|
30
30
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: facebooker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.50
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chad Fowler
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2009-08
|
17
|
+
date: 2009-09-08 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|