mogli 0.0.39 → 0.0.40

Sign up to get free protection for your applications and to get access to all the features.
data/lib/mogli.rb CHANGED
@@ -20,6 +20,7 @@ require "mogli/comment"
20
20
  require "mogli/domain"
21
21
  require "mogli/education"
22
22
  require "mogli/event"
23
+ require "mogli/friendlist"
23
24
  require "mogli/group"
24
25
  require "mogli/insight"
25
26
  require "mogli/insight_value"
@@ -31,6 +32,7 @@ require "mogli/music"
31
32
  require "mogli/note"
32
33
  require "mogli/page"
33
34
  require "mogli/photo"
35
+ require "mogli/place"
34
36
  require "mogli/post"
35
37
  require "mogli/status"
36
38
  require "mogli/television"
@@ -41,3 +43,4 @@ require "mogli/test_user"
41
43
  require "mogli/client"
42
44
  require "mogli/app_client"
43
45
  require "mogli/fql_multiquery"
46
+ require "mogli/permissions"
data/lib/mogli/client.rb CHANGED
@@ -27,7 +27,7 @@ module Mogli
27
27
  end
28
28
 
29
29
  def fql_path
30
- "https://api.facebook.com/method/fql.query"
30
+ "https://graph.facebook.com/fql"
31
31
  end
32
32
 
33
33
  def fql_multiquery_path
@@ -137,9 +137,9 @@ module Mogli
137
137
  end
138
138
 
139
139
  def fql_query(query,klass=nil,format="json")
140
- data = self.class.post(fql_path,:body=>default_params.merge({:query=>query,:format=>format}))
140
+ data = self.class.get(fql_path,:query=>default_params.merge({:q=>query,:format=>format})).parsed_response
141
141
  return data unless format=="json"
142
- map_data(data,klass)
142
+ map_data(data["data"],klass)
143
143
  end
144
144
 
145
145
  def fql_multiquery(queries)
@@ -161,6 +161,11 @@ module Mogli
161
161
  def map_data(data,klass=nil)
162
162
  raise_error_if_necessary(data)
163
163
  hash_or_array = extract_hash_or_array(data,klass)
164
+ if hash_or_array.is_a?(Array) && hash_or_array.size == 2 && hash_or_array[1].is_a?(Hash) && hash_or_array[1]['body']
165
+ # responses from batch queries are buried inside a
166
+ # completely different data structure
167
+ hash_or_array = JSON.parse(hash_or_array[1]['body'].first).values
168
+ end
164
169
  hash_or_array = map_to_class(hash_or_array,klass) if klass
165
170
  hash_or_array
166
171
  end
data/lib/mogli/event.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Mogli
2
2
  class Event < Model
3
3
  set_search_type
4
- define_properties :id, :name, :description, :start_time, :end_time, :location, :privacy, :updated_time
4
+ define_properties :id, :name, :description, :start_time, :end_time, :location, :privacy, :updated_time, :rsvp_status
5
5
  creation_properties :start_time, :end_time, :link, :name, :description, :privacy
6
6
 
7
7
  hash_populating_accessor :venue, "Address"
@@ -12,5 +12,7 @@ module Mogli
12
12
  has_association :attending, "User"
13
13
  has_association :declined, "User"
14
14
  has_association :feed, "Post"
15
+
16
+ fql_mapping :eid=>:id
15
17
  end
16
18
  end
@@ -0,0 +1,10 @@
1
+ module Mogli
2
+
3
+ # requires read_friendlists permission
4
+ # https://developers.facebook.com/docs/reference/api/FriendList/
5
+
6
+ class FriendList < Model
7
+ define_properties :name, :list_type, :id
8
+
9
+ end
10
+ end
data/lib/mogli/model.rb CHANGED
@@ -20,10 +20,11 @@ module Mogli
20
20
  @_values = {}
21
21
  self.client=client
22
22
  hash.each do |k,v|
23
- self.send("#{k}=",v)
23
+ self.send("#{self.class.fql_mapping[k]||k}=",v)
24
24
  end
25
25
  end
26
26
 
27
+
27
28
  def post_params
28
29
  post_params = {}
29
30
  self.class.creation_keys.each do |key|
@@ -54,6 +55,12 @@ module Mogli
54
55
  other.extend(ClassMethods)
55
56
  end
56
57
 
58
+ def self.fql_mapping(hash=nil)
59
+ if hash
60
+ @fql_mapping = hash
61
+ end
62
+ @fql_mapping || {}
63
+ end
57
64
  def method_missing(method, *args)
58
65
  method_as_s = method.to_s
59
66
  if method_as_s.to_s[-1].chr == "="
@@ -0,0 +1,80 @@
1
+ module Mogli
2
+ class Permissions < Model
3
+
4
+ define_properties \
5
+ :user_about_me,
6
+ :user_activities,
7
+ :user_birthday,
8
+ :user_checkins,
9
+ :user_education_history,
10
+ :user_events,
11
+ :user_games_activity,
12
+ :user_groups,
13
+ :user_hometown,
14
+ :user_interests,
15
+ :user_likes,
16
+ :user_location,
17
+ :user_notes,
18
+ :user_online_presence,
19
+ :user_photo_video_tags,
20
+ :user_photos,
21
+ :user_relationship_details,
22
+ :user_relationships,
23
+ :user_religion_politics,
24
+ :user_status,
25
+ :user_subscriptions,
26
+ :user_videos,
27
+ :user_website,
28
+ :user_work_history,
29
+ :friends_about_me,
30
+ :friends_activities,
31
+ :friends_birthday,
32
+ :friends_checkins,
33
+ :friends_education_history,
34
+ :friends_events,
35
+ :friends_games_activity,
36
+ :friends_groups,
37
+ :friends_hometown,
38
+ :friends_interests,
39
+ :friends_likes,
40
+ :friends_location,
41
+ :friends_notes,
42
+ :friends_online_presence,
43
+ :friends_photo_video_tags,
44
+ :friends_photos,
45
+ :friends_relationship_details,
46
+ :friends_relationships,
47
+ :friends_religion_politics,
48
+ :friends_status,
49
+ :friends_subscriptions,
50
+ :friends_videos,
51
+ :friends_website,
52
+ :friends_work_history,
53
+ :ads_management,
54
+ :create_event,
55
+ :create_note,
56
+ :email,
57
+ :export_stream,
58
+ :manage_friendlists,
59
+ :manage_notifications,
60
+ :manage_pages,
61
+ :offline_access,
62
+ :photo_upload,
63
+ :publish_actions,
64
+ :publish_checkins,
65
+ :publish_stream,
66
+ :read_friendlists,
67
+ :read_insights,
68
+ :read_mailbox,
69
+ :read_requests,
70
+ :read_stream,
71
+ :rsvp_event,
72
+ :share_item,
73
+ :sms,
74
+ :status_update,
75
+ :video_upload,
76
+ :xmpp_login
77
+
78
+
79
+ end
80
+ end
@@ -0,0 +1,40 @@
1
+
2
+ module Mogli
3
+ class Place < Model
4
+
5
+ define_properties :id, :name, :category, :username, :can_post, :phone, :website, :checkins, :link, :public_transit, :likes, :picture
6
+ hash_populating_accessor :location, "Address"
7
+ hash_populating_accessor :restaurant_services, "RestaurantServices"
8
+ hash_populating_accessor :restaurant_specialties, "RestaurantSpecialties"
9
+ hash_populating_accessor :parking, "Parking"
10
+ hash_populating_accessor :payment_options, "PaymentOptions"
11
+ hash_populating_accessor :hours, "Hours"
12
+ end
13
+
14
+ class RestaurantServices < Model
15
+ define_properties :groups, :catering, :waiter, :kids, :outdoor, :reserve, :walkins, :delivery, :takeout
16
+ end
17
+
18
+ class RestaurantSpecialties < Model
19
+ define_properties :drinks, :coffee, :breakfast, :dinner, :lunch
20
+ end
21
+
22
+ class Parking < Model
23
+ define_properties :valet, :street, :lot
24
+ end
25
+
26
+ class PaymentOptions < Model
27
+ define_properties :mastercard, :amex, :cash_only, :visa, :discover
28
+ end
29
+
30
+ class Hours < Model
31
+ define_properties :sun_1_open, :sun_1_close, :sun_2_open, :sun_2_close
32
+ define_properties :mon_1_open, :mon_1_close, :mon_2_open, :mon_2_close
33
+ define_properties :tue_1_open, :tue_1_close, :tue_2_open, :tue_2_close
34
+ define_properties :wed_1_open, :wed_1_close, :wed_2_open, :wed_2_close
35
+ define_properties :thu_1_open, :thu_1_close, :thu_2_open, :thu_2_close
36
+ define_properties :fri_1_open, :fri_1_close, :fri_2_open, :fri_2_close
37
+ define_properties :sat_1_open, :sat_1_close, :sat_2_open, :sat_2_close
38
+ end
39
+
40
+ end
data/lib/mogli/user.rb CHANGED
@@ -108,6 +108,11 @@ module Mogli
108
108
  extended_permissions[permission]
109
109
  end
110
110
 
111
+ # revoke all permissions for this user
112
+ def revoke_permission
113
+ client.delete("#{id}/permissions")
114
+ end
115
+
111
116
  private
112
117
 
113
118
  # queries all extended permissions for this user for the current application
data/spec/client_spec.rb CHANGED
@@ -205,31 +205,52 @@ describe Mogli::Client do
205
205
 
206
206
  describe "fql queries" do
207
207
  it "defaults to json" do
208
- Mogli::Client.should_receive(:post).with("https://api.facebook.com/method/fql.query",:body=>{:query=>"query",:format=>"json",:access_token=>"1234"})
208
+ Mogli::Client.should_receive(:get).with("https://graph.facebook.com/fql",:query=>{:q=>"query",:format=>"json",:access_token=>"1234"}).and_return({:data=>[]})
209
209
  client = Mogli::Client.new("1234")
210
210
  client.fql_query("query")
211
211
  end
212
212
 
213
213
  it "supports xml" do
214
- Mogli::Client.should_receive(:post).with("https://api.facebook.com/method/fql.query",:body=>{:query=>"query",:format=>"xml",:access_token=>"1234"})
214
+ Mogli::Client.should_receive(:get).with("https://graph.facebook.com/fql",:query=>{:q=>"query",:format=>"xml",:access_token=>"1234"}).and_return({:data=>[]})
215
215
  client = Mogli::Client.new("1234")
216
216
  client.fql_query("query",nil,"xml")
217
217
  end
218
218
 
219
219
  it "creates objects if given a class" do
220
- Mogli::Client.should_receive(:post).and_return({"id"=>12451752, "first_name"=>"Mike", "last_name"=>"Mangino" })
220
+ Mogli::Client.should_receive(:get).and_return({:data=>{"id"=>12451752, "first_name"=>"Mike", "last_name"=>"Mangino" }})
221
221
  client = Mogli::Client.new("1234")
222
222
  client.fql_query("query","user").should be_an_instance_of(Mogli::User)
223
223
  end
224
224
 
225
+ it "Maps the fields if necessary" do
226
+ Mogli::Client.should_receive(:get).and_return({:data=>
227
+ [
228
+ {
229
+ :eid=> 182880348415052,
230
+ :name=> "Eeyores 48th Birthday Party"
231
+ },
232
+ {
233
+ :eid=> 172962332756022,
234
+ :name=> "Cake Walk - Featuring the Artwork of Emily Pelton"
235
+ }
236
+ ]
237
+ })
238
+ client = Mogli::Client.new("1234")
239
+ events = client.fql_query("query","event")
240
+ events.first.should be_an_instance_of(Mogli::Event)
241
+ events.first.id.should == 182880348415052
242
+
243
+ end
244
+
245
+
225
246
  it "returns a hash if no class is given" do
226
- Mogli::Client.should_receive(:post).and_return({"id"=>12451752, "first_name"=>"Mike", "last_name"=>"Mangino" })
247
+ Mogli::Client.should_receive(:get).and_return(:data=>{"id"=>12451752, "first_name"=>"Mike", "last_name"=>"Mangino" })
227
248
  client = Mogli::Client.new("1234")
228
249
  client.fql_query("query").should be_an_instance_of(Hash)
229
250
  end
230
251
 
231
252
  it "doesn't create objects if the format is xml" do
232
- Mogli::Client.should_receive(:post).and_return({"id"=>12451752, "first_name"=>"Mike", "last_name"=>"Mangino" })
253
+ Mogli::Client.should_receive(:get).and_return(:data=>{"id"=>12451752, "first_name"=>"Mike", "last_name"=>"Mangino" })
233
254
  client = Mogli::Client.new("1234")
234
255
  client.fql_query("query","user","xml").should be_an_instance_of(Hash)
235
256
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mogli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.39
4
+ version: 0.0.40
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-22 00:00:00.000000000 Z
12
+ date: 2012-07-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hashie
@@ -154,6 +154,7 @@ files:
154
154
  - lib/mogli/event.rb
155
155
  - lib/mogli/fetching_array.rb
156
156
  - lib/mogli/fql_multiquery.rb
157
+ - lib/mogli/friendlist.rb
157
158
  - lib/mogli/group.rb
158
159
  - lib/mogli/insight.rb
159
160
  - lib/mogli/insight_value.rb
@@ -166,7 +167,9 @@ files:
166
167
  - lib/mogli/music.rb
167
168
  - lib/mogli/note.rb
168
169
  - lib/mogli/page.rb
170
+ - lib/mogli/permissions.rb
169
171
  - lib/mogli/photo.rb
172
+ - lib/mogli/place.rb
170
173
  - lib/mogli/post.rb
171
174
  - lib/mogli/profile.rb
172
175
  - lib/mogli/status.rb