mogli 0.0.16 → 0.0.17
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/lib/mogli/authenticator.rb +12 -0
- data/lib/mogli/client.rb +18 -9
- data/lib/mogli/page.rb +1 -1
- data/lib/mogli/user.rb +86 -0
- metadata +4 -4
data/lib/mogli/authenticator.rb
CHANGED
@@ -30,6 +30,18 @@ module Mogli
|
|
30
30
|
:client_secret => secret,
|
31
31
|
:sessions => keystr})
|
32
32
|
end
|
33
|
+
|
34
|
+
def get_access_token_for_application
|
35
|
+
client = Mogli::Client.new
|
36
|
+
request = client.class.post(client.api_path('oauth/access_token'),
|
37
|
+
:body=> {
|
38
|
+
:grant_type => 'client_credentials',
|
39
|
+
:client_id => client_id,
|
40
|
+
:client_secret => secret
|
41
|
+
}
|
42
|
+
)
|
43
|
+
request.parsed_response.split('=').last
|
44
|
+
end
|
33
45
|
|
34
46
|
end
|
35
47
|
end
|
data/lib/mogli/client.rb
CHANGED
@@ -17,6 +17,8 @@ module Mogli
|
|
17
17
|
class OAuthAccessTokenException < ClientException; end
|
18
18
|
class OAuthUnauthorizedClientException < ClientException; end
|
19
19
|
class OAuthException < ClientException; end
|
20
|
+
# represents case that the facebook limit on posts to a feed has been exceeded
|
21
|
+
class FeedActionRequestLimitExceeded < ClientException; end
|
20
22
|
|
21
23
|
def api_path(path)
|
22
24
|
"https://graph.facebook.com/#{path}"
|
@@ -52,12 +54,16 @@ module Mogli
|
|
52
54
|
end
|
53
55
|
|
54
56
|
def self.raise_client_exception(post_data)
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
57
|
+
raise_error_by_type_and_message(post_data["error"]["type"], post_data["error"]["message"])
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.raise_error_by_type_and_message(type, message)
|
61
|
+
if type == 'OAuthException' && message =~ /Feed action request limit reached/
|
62
|
+
raise FeedActionRequestLimitExceeded.new(message)
|
63
|
+
elsif Mogli::Client.const_defined?(type)
|
64
|
+
raise Mogli::Client.const_get(type).new(message)
|
59
65
|
else
|
60
|
-
raise ClientException.new("#{type}: #{message}")
|
66
|
+
raise ClientException.new("#{type}: #{message}")
|
61
67
|
end
|
62
68
|
end
|
63
69
|
|
@@ -73,6 +79,12 @@ module Mogli
|
|
73
79
|
new(access_data['access_token'],
|
74
80
|
Time.now.to_i + access_data['expires'].to_i)
|
75
81
|
end
|
82
|
+
|
83
|
+
def self.create_and_authenticate_as_application(client_id, secret)
|
84
|
+
authenticator = Mogli::Authenticator.new(client_id, secret, nil)
|
85
|
+
access_data = authenticator.get_access_token_for_application
|
86
|
+
new(access_data)
|
87
|
+
end
|
76
88
|
|
77
89
|
def post(path,klass,body_args)
|
78
90
|
data = self.class.post(api_path(path),:body=>default_params.merge(body_args))
|
@@ -158,10 +170,7 @@ module Mogli
|
|
158
170
|
def raise_error_if_necessary(data)
|
159
171
|
if data.kind_of?(Hash)
|
160
172
|
if data.keys.size == 1 and data["error"]
|
161
|
-
type
|
162
|
-
message = data["error"]["message"]
|
163
|
-
raise Mogli::Client.const_get(type).new(message) if Mogli::Client.const_defined?(type)
|
164
|
-
raise ClientException.new("#{type}: #{message}")
|
173
|
+
self.class.raise_error_by_type_and_message(data["error"]["type"], data["error"]["message"])
|
165
174
|
end
|
166
175
|
end
|
167
176
|
end
|
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 :
|
8
|
+
define_properties :likes, :link, :picture, :has_added_app, :website, :description, :can_post
|
9
9
|
|
10
10
|
# Retail
|
11
11
|
define_properties :founded, :products, :mission, :company_overview
|
data/lib/mogli/user.rb
CHANGED
@@ -26,5 +26,91 @@ module Mogli
|
|
26
26
|
has_association :likes, "Page"
|
27
27
|
has_association :home, "Post"
|
28
28
|
has_association :accounts, "Page"
|
29
|
+
|
30
|
+
attr_reader :extended_permissions
|
31
|
+
|
32
|
+
# raised when asked to check for a permission that mogli doesn't know about
|
33
|
+
class UnrecognizedExtendedPermissionException < Exception; end
|
34
|
+
|
35
|
+
# the entire list of extended permissions the user is able to grant the
|
36
|
+
# application. the list should be kept in sync with
|
37
|
+
# http://developers.facebook.com/docs/authentication/permissions
|
38
|
+
ALL_EXTENDED_PERMISSIONS = [
|
39
|
+
# publishing permissions
|
40
|
+
:publish_stream,
|
41
|
+
:create_event,
|
42
|
+
:rsvp_event,
|
43
|
+
:sms,
|
44
|
+
:offline_access,
|
45
|
+
:publish_checkins,
|
46
|
+
|
47
|
+
# data permissions
|
48
|
+
:user_about_me,
|
49
|
+
:user_activities,
|
50
|
+
:user_birthday,
|
51
|
+
:user_education_history,
|
52
|
+
:user_events,
|
53
|
+
:user_groups,
|
54
|
+
:user_hometown,
|
55
|
+
:user_interests,
|
56
|
+
:user_likes,
|
57
|
+
:user_location,
|
58
|
+
:user_notes,
|
59
|
+
:user_online_presence,
|
60
|
+
:user_photo_video_tags,
|
61
|
+
:user_photos,
|
62
|
+
:user_relationships,
|
63
|
+
:user_relationship_details,
|
64
|
+
:user_religion_politics,
|
65
|
+
:user_status,
|
66
|
+
:user_videos,
|
67
|
+
:user_website,
|
68
|
+
:user_work_history,
|
69
|
+
:email,
|
70
|
+
:read_friendlists,
|
71
|
+
:read_insights,
|
72
|
+
:read_mailbox,
|
73
|
+
:read_requests,
|
74
|
+
:read_stream,
|
75
|
+
:xmpp_login,
|
76
|
+
:ads_management,
|
77
|
+
:user_checkins,
|
78
|
+
|
79
|
+
# page permissions
|
80
|
+
:manage_pages
|
81
|
+
]
|
82
|
+
|
83
|
+
# check if the facebook user has a specific permission. the permission arg
|
84
|
+
# is a symbol matching the facebook extended permission names exactly:
|
85
|
+
# http://developers.facebook.com/docs/authentication/permissions
|
86
|
+
def has_permission?(permission)
|
87
|
+
if !ALL_EXTENDED_PERMISSIONS.include? permission
|
88
|
+
raise UnrecognizedExtendedPermissionException,
|
89
|
+
"The requested permission is not recognized as a facebook extended permission: '#{permission}'"
|
90
|
+
end
|
91
|
+
|
92
|
+
if !defined?(@extended_permissions)
|
93
|
+
fetch_permissions
|
94
|
+
end
|
95
|
+
|
96
|
+
extended_permissions[permission]
|
97
|
+
end
|
98
|
+
|
99
|
+
private
|
100
|
+
|
101
|
+
# queries all extended permissions for this user for the current application
|
102
|
+
# caches a hash of permission names => boolean indicating if the user has
|
103
|
+
# granted the specified permission to this app
|
104
|
+
def fetch_permissions
|
105
|
+
fql = "SELECT #{ALL_EXTENDED_PERMISSIONS.map(&:to_s).join(',')} " +
|
106
|
+
"FROM permissions " +
|
107
|
+
"WHERE uid = #{self.id}"
|
108
|
+
@extended_permissions = {}
|
109
|
+
perms_query_result = client.fql_query(fql).parsed_response.first
|
110
|
+
ALL_EXTENDED_PERMISSIONS.each do |perm|
|
111
|
+
@extended_permissions[perm] = (perms_query_result[perm.to_s] == 1)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
29
115
|
end
|
30
116
|
end
|
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:
|
4
|
+
hash: 61
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 17
|
10
|
+
version: 0.0.17
|
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:
|
18
|
+
date: 2011-01-11 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|