mmangino-facebooker 1.0.12 → 1.0.13

Sign up to get free protection for your applications and to get access to all the features.
data/TODO.txt CHANGED
@@ -1,10 +1,4 @@
1
- [ ] Refactor facebook form builder so erbout won't be deeply nested, causing erubis to break
2
- [ ] Support missing parameters on methods---most notably authentication-related parameters such as next and canvas
3
- [ ] Finish FQL Querying
4
- [ ] Refactor FQL Querying
5
- [ ] Transform incoming data into appropriate classes (Integers, Dates, etc.)
1
+ [ ] Document session handling. Come up with different cases and paths for the flow and create tests for each
2
+ [ ] Verify that sessions are used only where required. Raise exceptions on User methods that require a session when none is available
3
+ [ ] Refactor setup / Adapter loading code
6
4
 
7
- [x] Specify fields wanted when getting user info (defaults to all now) [shane]
8
- [x] Create facebooker.yml config file and merge with tunnel.yml [shane]
9
- [X] Remove facebook prefix from resource routes, making them worth with facebook and regular Rails controllers [mike]
10
- [X] Use fb_sig_request_method to make facebook routes more Rails-like [mike]
@@ -77,6 +77,18 @@ module Facebooker
77
77
  end)
78
78
  end
79
79
  end
80
+
81
+ def id_is(attribute)
82
+ class_eval <<-EOS
83
+ def #{attribute}=(value)
84
+ @#{attribute} = value.to_i
85
+ end
86
+
87
+ attr_reader #{attribute.inspect}
88
+ alias :id #{attribute.inspect}
89
+ alias :id= #{"#{attribute}=".to_sym.inspect}
90
+ EOS
91
+ end
80
92
  end
81
93
 
82
94
  ##
@@ -22,5 +22,7 @@ module Facebooker
22
22
 
23
23
  include Model
24
24
  attr_accessor :eid, :pic, :pic_small, :pic_big, :name, :creator, :update_time, :description, :tagline, :venue, :host, :event_type, :nid, :location, :end_time, :start_time, :event_subtype
25
+
26
+ id_is :eid
25
27
  end
26
28
  end
@@ -6,6 +6,8 @@ module Facebooker
6
6
  include Model
7
7
  attr_accessor :flid, :name
8
8
 
9
+ id_is :flid
10
+
9
11
  # We need this to be an integer, so do the conversion
10
12
  def flid=(f)
11
13
  @flid= ( f.nil? ? nil : f.to_i)
@@ -10,6 +10,7 @@ module Facebooker
10
10
  include Model
11
11
  attr_accessor :pic, :pic_small, :pic_big, :name, :creator, :recent_news, :gid, :update_time, :group_subtype, :group_type, :website, :office, :description, :venue, :nid
12
12
 
13
+ id_is :gid
13
14
 
14
15
  ##
15
16
  # Get the full list of members as populated User objects. First time fetches group members via Facebook API call.
@@ -6,5 +6,7 @@ module Facebooker
6
6
  :link, :caption, :created,
7
7
  :src, :src_big, :src_small,
8
8
  :story_fbid
9
+
10
+ id_is :pid
9
11
  end
10
12
  end
@@ -12,7 +12,6 @@ module Facebooker
12
12
  end
13
13
  FIELDS = [:status, :political, :pic_small, :name, :quotes, :is_app_user, :tv, :profile_update_time, :meeting_sex, :hs_info, :timezone, :relationship_status, :hometown_location, :about_me, :wall_count, :significant_other_id, :pic_big, :music, :uid, :work_history, :sex, :religion, :notes_count, :activities, :pic_square, :movies, :has_added_app, :education_history, :birthday, :first_name, :meeting_for, :last_name, :interests, :current_location, :pic, :books, :affiliations, :locale, :profile_url, :proxied_email,:email_hashes]
14
14
  STANDARD_FIELDS = [:uid, :first_name, :last_name, :name, :timezone, :birthday, :sex, :affiliations, :locale, :profile_url]
15
- attr_accessor :session
16
15
  populating_attr_accessor *FIELDS
17
16
  attr_reader :affiliations
18
17
  populating_hash_settable_accessor :current_location, Location
@@ -39,17 +38,8 @@ module Facebooker
39
38
  end
40
39
  end
41
40
 
42
- def uid
43
- @uid
44
- end
45
-
46
- def uid=(uid)
47
- @uid = uid.to_i
48
- end
49
-
50
- alias :id :uid
51
- alias :id= :uid=
52
- alias :facebook_id :uid
41
+ id_is :uid
42
+ alias :facebook_id :id
53
43
 
54
44
  # Returns a user's events, params correspond to API call parameters (except UID):
55
45
  # http://wiki.developers.facebook.com/index.php/Events.get
@@ -282,7 +272,7 @@ module Facebooker
282
272
  # requires extended permission.
283
273
  def set_status(message)
284
274
  self.status=message
285
- session.post('facebook.users.setStatus',:status=>message,:status_includes_verb=>1) do |ret|
275
+ session.post('facebook.users.setStatus',{:status=>message,:status_includes_verb=>1,:uid => uid}, false) do |ret|
286
276
  ret
287
277
  end
288
278
  end
@@ -58,23 +58,23 @@ module Facebooker
58
58
 
59
59
  def self.hashinate(response_element)
60
60
  response_element.children.reject{|c| c.kind_of? REXML::Text}.inject({}) do |hash, child|
61
- # If the node hasn't any child, and is not a list, we want empty strings, not empty hashes.
62
- hash[child.name] = if (child.children.size == 1 && child.children.first.kind_of?(REXML::Text)) || (child.children.size == 0 && child.attributes['list'] != 'true')
61
+ # If the node hasn't any child, and is not a list, we want empty strings, not empty hashes,
62
+ # except if attributes['nil'] == true
63
+ hash[child.name] =
64
+ if (child.attributes['nil'] == 'true')
65
+ nil
66
+ elsif (child.children.size == 1 && child.children.first.kind_of?(REXML::Text)) || (child.children.size == 0 && child.attributes['list'] != 'true')
63
67
  anonymous_field_from(child, hash) || child.text_value
68
+ elsif child.attributes['list'] == 'true'
69
+ child.children.reject{|c| c.kind_of? REXML::Text}.map { |subchild| hash_or_value_for(subchild)}
64
70
  else
65
- if child.attributes['list'] == 'true'
66
- child.children.reject{|c| c.kind_of? REXML::Text}.map do |subchild|
67
- hash_or_value_for(subchild)
68
- end
69
- else
70
- child.children.reject{|c| c.kind_of? REXML::Text}.inject({}) do |subhash, subchild|
71
- subhash[subchild.name] = hash_or_value_for(subchild)
72
- subhash
73
- end
71
+ child.children.reject{|c| c.kind_of? REXML::Text}.inject({}) do |subhash, subchild|
72
+ subhash[subchild.name] = hash_or_value_for(subchild)
73
+ subhash
74
74
  end
75
- end
75
+ end #if (child.attributes)
76
76
  hash
77
- end
77
+ end #do |hash, child|
78
78
  end
79
79
 
80
80
  def self.anonymous_field_from(child, hash)
@@ -252,7 +252,8 @@ module Facebooker
252
252
  end
253
253
 
254
254
  def application_is_not_installed_by_facebook_user
255
- redirect_to session[:facebook_session].install_url
255
+ url_params = after_facebook_login_url.nil? ? {} : { :next => after_facebook_login_url }
256
+ redirect_to session[:facebook_session].install_url(url_params)
256
257
  end
257
258
 
258
259
  def set_fbml_format
@@ -78,11 +78,11 @@ module Facebooker
78
78
  end
79
79
 
80
80
  def self.current
81
- @current_session
81
+ Thread.current['facebook_session']
82
82
  end
83
83
 
84
84
  def self.current=(session)
85
- @current_session=session
85
+ Thread.current['facebook_session'] = session
86
86
  end
87
87
 
88
88
  def login_url(options={})
@@ -319,24 +319,15 @@ module Facebooker
319
319
  # Register a template bundle with Facebook.
320
320
  # returns the template id to use to send using this template
321
321
  def register_template_bundle(one_line_story_templates,short_story_templates=nil,full_story_template=nil, action_links=nil)
322
- if !one_line_story_templates.is_a?(Array)
323
- one_line_story_templates = [one_line_story_templates]
324
- end
325
- parameters = {:one_line_story_templates=>one_line_story_templates.to_json}
322
+ parameters = {:one_line_story_templates => Array(one_line_story_templates).to_json}
326
323
 
327
- if !action_links.blank?
328
- parameters[:action_links] = action_links.to_json
329
- end
324
+ parameters[:action_links] = action_links.to_json unless action_links.blank?
330
325
 
331
- if !short_story_templates.blank?
332
- short_story_templates = [short_story_templates] unless short_story_templates.is_a?(Array)
333
- parameters[:short_story_templates]= short_story_templates.to_json
334
- end
326
+ parameters[:short_story_templates] = Array(short_story_templates).to_json unless short_story_templates.blank?
335
327
 
336
- if !full_story_template.blank?
337
- parameters[:full_story_template]= full_story_template.to_json
338
- end
339
- post("facebook.feed.registerTemplateBundle", parameters,false)
328
+ parameters[:full_story_template] = full_story_template.to_json unless full_story_template.blank?
329
+
330
+ post("facebook.feed.registerTemplateBundle", parameters, false)
340
331
  end
341
332
 
342
333
  ##
@@ -546,7 +537,7 @@ module Facebooker
546
537
  end
547
538
 
548
539
  def uid?
549
- ! @uid.nil?
540
+ !! @uid
550
541
  end
551
542
 
552
543
  def signature_for(params)
@@ -97,7 +97,14 @@ class TestFacebooker < Test::Unit::TestCase
97
97
  assert_equal('I rule', friend.status.message)
98
98
  assert_equal(nil, friend.hometown_location)
99
99
  end
100
-
100
+
101
+ def test_can_handle_nil_data
102
+ friends = populate_session_friends_with_nil_data
103
+ friend = friends.detect{|f| f.id == 222333}
104
+ assert_equal(nil,friend.current_location)
105
+ assert_equal(nil,friend.pic)
106
+ end
107
+
101
108
  def test_session_can_expire_on_server_and_client_handles_appropriately
102
109
  expect_http_posts_with_responses(example_session_expired_error_response)
103
110
  assert_raises(Facebooker::Session::SessionExpired) {
@@ -217,6 +224,7 @@ class TestFacebooker < Test::Unit::TestCase
217
224
  photos = @session.get_photos([97503428461115590, 97503428461115573])
218
225
  assert_equal 2, photos.size
219
226
  assert_equal "Rooftop barbecues make me act funny", photos.first.caption
227
+ assert_equal 97503428461115590, photos[0].id
220
228
  end
221
229
 
222
230
  def test_can_get_photos_by_subject_and_album
@@ -355,7 +363,12 @@ class TestFacebooker < Test::Unit::TestCase
355
363
  expect_http_posts_with_responses(example_friends_xml, example_limited_user_info_xml)
356
364
  @session.user.friends!(:affiliations, :status, :meeting_for)
357
365
  end
358
-
366
+
367
+ def populate_session_friends_with_nil_data
368
+ expect_http_posts_with_responses(example_friends_xml, example_nil_user_info_xml)
369
+ @session.user.friends!(:name, :current_location, :pic)
370
+ end
371
+
359
372
  def sample_args_to_post
360
373
  {:method=>"facebook.auth.createToken", :sig=>"18b3dc4f5258a63c0ad641eebd3e3930"}
361
374
  end
@@ -636,6 +649,21 @@ class TestFacebooker < Test::Unit::TestCase
636
649
  end
637
650
 
638
651
 
652
+ def example_nil_user_info_xml
653
+ <<-XML
654
+ <?xml version="1.0" encoding="UTF-8"?>
655
+ <users_getInfo_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" list="true">
656
+ <user>
657
+ <uid>222333</uid>
658
+ <name>Kevin Lochner</name>
659
+ <current_location xsi:nil="true"/>
660
+ <pic xsi:nil="true"/>
661
+ </user>
662
+ </users_getInfo_response>
663
+ XML
664
+ end
665
+
666
+
639
667
  def example_friends_xml
640
668
  <<-XML
641
669
  <?xml version="1.0" encoding="UTF-8"?>
data/test/user_test.rb CHANGED
@@ -71,6 +71,10 @@ class UserTest < Test::Unit::TestCase
71
71
  user=Facebooker::User.new(1)
72
72
  assert_equal("current",user.session)
73
73
  end
74
+
75
+ def test_raises_when_no_session_bound
76
+ assert_raises(Facebooker::Model::UnboundSessionException) { Facebooker::User.new(1, nil).populate }
77
+ end
74
78
 
75
79
  def test_can_set_mobile_fbml
76
80
  @user.expects(:set_profile_fbml).with(nil,"test",nil)
@@ -135,7 +139,7 @@ class UserTest < Test::Unit::TestCase
135
139
  @user.status="my status"
136
140
  end
137
141
  def test_can_set_status_with_string
138
- @session.expects(:post).with('facebook.users.setStatus', :status=>"my status",:status_includes_verb=>1)
142
+ @session.expects(:post).with('facebook.users.setStatus', {:status=>"my status",:status_includes_verb=>1, :uid => @user.uid}, false)
139
143
  @user.set_status("my status")
140
144
  end
141
145
 
@@ -143,7 +147,7 @@ class UserTest < Test::Unit::TestCase
143
147
  @user = Facebooker::User.new(9507801, @session)
144
148
  expect_http_posts_with_responses(example_events_get_xml)
145
149
  events = @user.events
146
- assert_equal "29511517904", events.first.eid
150
+ assert_equal 29511517904, events.first.eid
147
151
  end
148
152
 
149
153
  def test_events_caching_honors_params
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mmangino-facebooker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.12
4
+ version: 1.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chad Fowler