mogli 0.0.28 → 0.0.29

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,6 +5,11 @@ module Mogli
5
5
  class AppClient < Client
6
6
  attr_accessor :application_id
7
7
 
8
+ def initialize(app_token, application_id=nil)
9
+ super(app_token)
10
+ self.application_id = application_id
11
+ end
12
+
8
13
  def subscription_url
9
14
  "https://graph.facebook.com/#{application_id}/subscriptions"
10
15
  end
@@ -23,5 +28,13 @@ module Mogli
23
28
  def subscriptions
24
29
  get_and_map_url(subscription_url,"Subscription")
25
30
  end
31
+
32
+ def post(path, klass, query)
33
+ super("#{application_id}/#{path}", klass, query)
34
+ end
35
+
36
+ def get_and_map(path, klass, query)
37
+ super("#{application_id}/#{path}", klass, query)
38
+ end
26
39
  end
27
- end
40
+ end
data/lib/mogli/client.rb CHANGED
@@ -55,7 +55,14 @@ module Mogli
55
55
  parts.each do |p| (k,v) = p.split("=")
56
56
  hash[k]=CGI.unescape(v)
57
57
  end
58
- new(hash["access_token"],hash["expires"].to_s.to_i)
58
+
59
+ if hash["expires"]
60
+ expires = Time.now.to_i + hash["expires"].to_i
61
+ else
62
+ expires = nil
63
+ end
64
+
65
+ new(hash["access_token"],expires)
59
66
  end
60
67
 
61
68
  def self.raise_client_exception(post_data)
@@ -139,7 +146,8 @@ module Mogli
139
146
 
140
147
  def extract_hash_or_array(hash_or_array,klass)
141
148
  hash_or_array = hash_or_array.parsed_response if hash_or_array.respond_to?(:parsed_response)
142
- return nil if hash_or_array == false
149
+ return nil if hash_or_array == false || hash_or_array == true
150
+
143
151
  return hash_or_array if hash_or_array.nil? or hash_or_array.kind_of?(Array)
144
152
  return extract_fetching_array(hash_or_array,klass) if is_fetching_array?(hash_or_array)
145
153
  return hash_or_array
@@ -193,12 +201,12 @@ module Mogli
193
201
  end
194
202
 
195
203
  def raise_error_if_necessary(data)
196
- raise HTTPException if data.respond_to?(:code) and data.code != 200
197
204
  if data.kind_of?(Hash)
198
205
  if data.keys.size == 1 and data["error"]
199
206
  self.class.raise_error_by_type_and_message(data["error"]["type"], data["error"]["message"])
200
207
  end
201
208
  end
209
+ raise HTTPException if data.respond_to?(:code) and data.code != 200
202
210
  end
203
211
 
204
212
  def fields_to_serialize
data/lib/mogli/page.rb CHANGED
@@ -5,7 +5,7 @@ module Mogli
5
5
  define_properties :id, :name, :category, :username, :access_token
6
6
 
7
7
  # General
8
- define_properties :likes, :link, :picture, :has_added_app, :website, :description, :can_post
8
+ define_properties :likes, :link, :picture, :has_added_app, :website, :description, :can_post, :checkins
9
9
 
10
10
  # Retail
11
11
  define_properties :founded, :products, :mission, :company_overview
@@ -16,6 +16,9 @@ module Mogli
16
16
  # As a like
17
17
  define_properties :created_time
18
18
 
19
+ # Number of checkins, not Checkin assocciation.
20
+ define_properties :checkins
21
+
19
22
  def client_for_page
20
23
  if access_token.blank?
21
24
  raise MissingAccessToken.new("You can only get a client for this page if an access_token has been provided. i.e. via /me/accounts")
data/lib/mogli/post.rb CHANGED
@@ -7,7 +7,7 @@ module Mogli
7
7
  :description, :source, :icon, :attribution, :actions, :likes,
8
8
  :created_time, :updated_time, :privacy, :type
9
9
 
10
- creation_properties :message, :picture, :link, :name, :description, :caption, :source, :actions
10
+ creation_properties :message, :picture, :link, :name, :description, :caption, :source, :actions, :privacy
11
11
 
12
12
  hash_populating_accessor :actions, "Action"
13
13
  has_association :comments, "Comment"
@@ -0,0 +1,6 @@
1
+ module Mogli
2
+ class Subscription < Model
3
+ define_properties :object,:callback_url,:fields,:active
4
+
5
+ end
6
+ end
@@ -0,0 +1,45 @@
1
+ module Mogli
2
+ # Support for Facebook test users, as described here:
3
+ #
4
+ # http://developers.facebook.com/docs/test_users/
5
+ #
6
+ # Test user creation/listing requires an app access token and an app
7
+ # id.
8
+ #
9
+ # Example usage:
10
+ #
11
+ # +Mogli::TestUser.all({}, Mogli::AppClient.new('access_token', 'app_id'))+
12
+ class TestUser < User
13
+ define_properties :access_token, :login_url, :password
14
+
15
+ # test_user_params can include:
16
+ #
17
+ # installed: This is a Boolean parameter to specify whether your
18
+ # app should be installed for the test user at the time of
19
+ # creation. It is true by default.
20
+ #
21
+ # name: this is an optional string parameter. You can specify a
22
+ # name for the test user you create. The specified name will also
23
+ # be used in the email address assigned to the test user.
24
+ #
25
+ # permissions: This is a comma-separated list of {extended permissions}[http://developers.facebook.com/docs/reference/api/permissions/].
26
+ # Your app is granted these permissions for the new test user if
27
+ # installed is true.
28
+ #
29
+ # Example usage:
30
+ #
31
+ # Mogli::TestUser.create({:installed => false, :name => 'Zark Muckerberg', :permissions => 'user_events,create_event'}, client)
32
+ def self.create(test_user_params, app_client)
33
+ app_client.post("accounts/test-users", self, test_user_params)
34
+ end
35
+
36
+ def self.all(app_client)
37
+ app_client.get_and_map("accounts/test-users", self, {})
38
+ end
39
+
40
+ def to_s
41
+ # name is nil by default, so use id
42
+ id.to_s
43
+ end
44
+ end
45
+ end
data/lib/mogli/user.rb CHANGED
@@ -2,7 +2,7 @@ module Mogli
2
2
  class User < Profile
3
3
  set_search_type
4
4
 
5
- define_properties :first_name, :last_name, :link, :about, :birthday, :gender,
5
+ define_properties :username, :first_name, :last_name, :link, :about, :birthday, :gender,
6
6
  :email, :website, :timezone, :updated_time, :verified, :political, :bio,
7
7
  :relationship_status, :locale, :religion, :quotes, :third_party_id
8
8
 
data/lib/mogli.rb CHANGED
@@ -36,6 +36,7 @@ require "mogli/television"
36
36
  require "mogli/video"
37
37
  require "mogli/work"
38
38
  require "mogli/user"
39
+ require "mogli/test_user"
39
40
  require "mogli/client"
40
41
  require "mogli/app_client"
41
42
  require "mogli/fql_multiquery"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mogli
3
3
  version: !ruby/object:Gem::Version
4
- hash: 39
4
+ hash: 37
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 28
10
- version: 0.0.28
9
+ - 29
10
+ version: 0.0.29
11
11
  platform: ruby
12
12
  authors:
13
13
  - Mike Mangino
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-14 00:00:00 -04:00
18
+ date: 2011-07-28 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -34,6 +34,36 @@ dependencies:
34
34
  version: 0.4.3
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: hashie
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 23
46
+ segments:
47
+ - 1
48
+ - 0
49
+ - 0
50
+ version: 1.0.0
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: rspec
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ type: :development
66
+ version_requirements: *id003
37
67
  description: Simple library for accessing the facebook Open Graph API
38
68
  email: mmangino@elevatedrails.com
39
69
  executables: []
@@ -77,7 +107,9 @@ files:
77
107
  - lib/mogli/post.rb
78
108
  - lib/mogli/profile.rb
79
109
  - lib/mogli/status.rb
110
+ - lib/mogli/subscription.rb
80
111
  - lib/mogli/television.rb
112
+ - lib/mogli/test_user.rb
81
113
  - lib/mogli/user.rb
82
114
  - lib/mogli/video.rb
83
115
  - lib/mogli/work.rb