mogli 0.0.25 → 0.0.26
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.rb +1 -1
- data/lib/mogli/authenticator.rb +11 -8
- data/lib/mogli/client.rb +12 -1
- data/lib/mogli/fql_multiquery.rb +43 -0
- data/lib/mogli/user.rb +2 -1
- metadata +5 -4
data/lib/mogli.rb
CHANGED
data/lib/mogli/authenticator.rb
CHANGED
@@ -24,28 +24,31 @@ module Mogli
|
|
24
24
|
keystr = session_keys.is_a?(Array) ?
|
25
25
|
session_keys.join(',') : session_keys
|
26
26
|
client = Mogli::Client.new
|
27
|
-
client.post("oauth/exchange_sessions", nil,
|
27
|
+
response = client.post("oauth/exchange_sessions", nil,
|
28
28
|
{:type => 'client_cred',
|
29
29
|
:client_id => client_id,
|
30
30
|
:client_secret => secret,
|
31
31
|
:sessions => keystr})
|
32
|
+
raise_exception_if_required(response)
|
33
|
+
response
|
32
34
|
end
|
33
35
|
|
34
36
|
def get_access_token_for_application
|
35
37
|
client = Mogli::Client.new
|
36
|
-
|
38
|
+
response = client.class.post(client.api_path('oauth/access_token'),
|
37
39
|
:body=> {
|
38
40
|
:grant_type => 'client_credentials',
|
39
41
|
:client_id => client_id,
|
40
42
|
:client_secret => secret
|
41
43
|
}
|
42
44
|
)
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
raise_exception_if_required(response)
|
46
|
+
response.to_s.split("=").last
|
47
|
+
end
|
48
|
+
|
49
|
+
def raise_exception_if_required(response)
|
50
|
+
raise Mogli::Client::HTTPException if response.code != 200
|
51
|
+
end
|
49
52
|
|
50
53
|
end
|
51
54
|
end
|
data/lib/mogli/client.rb
CHANGED
@@ -10,7 +10,7 @@ module Mogli
|
|
10
10
|
include HTTParty
|
11
11
|
include Mogli::Client::Event
|
12
12
|
include Mogli::Client::User
|
13
|
-
|
13
|
+
|
14
14
|
class ClientException < Exception; end
|
15
15
|
class UnrecognizeableClassError < ClientException; end
|
16
16
|
class QueryParseException < ClientException; end
|
@@ -19,6 +19,7 @@ module Mogli
|
|
19
19
|
class OAuthException < ClientException; end
|
20
20
|
# represents case that the facebook limit on posts to a feed has been exceeded
|
21
21
|
class FeedActionRequestLimitExceeded < ClientException; end
|
22
|
+
class HTTPException < ClientException; end
|
22
23
|
|
23
24
|
def api_path(path)
|
24
25
|
"https://graph.facebook.com/#{path}"
|
@@ -28,6 +29,10 @@ module Mogli
|
|
28
29
|
"https://api.facebook.com/method/fql.query"
|
29
30
|
end
|
30
31
|
|
32
|
+
def fql_multiquery_path
|
33
|
+
"https://api.facebook.com/method/fql.multiquery"
|
34
|
+
end
|
35
|
+
|
31
36
|
def initialize(access_token = nil,expiration=nil)
|
32
37
|
@access_token = access_token
|
33
38
|
# nil expiration means extended access
|
@@ -107,6 +112,11 @@ module Mogli
|
|
107
112
|
map_data(data,klass)
|
108
113
|
end
|
109
114
|
|
115
|
+
def fql_multiquery(queries)
|
116
|
+
data = self.class.post(fql_multiquery_path,:body=>default_params.merge({:queries=>queries.to_json,:format=>"json"}))
|
117
|
+
map_data(data)
|
118
|
+
end
|
119
|
+
|
110
120
|
def get_and_map(path,klass=nil,body_args = {})
|
111
121
|
data = self.class.get(api_path(path),:query=>default_params.merge(body_args))
|
112
122
|
data = data.values if body_args.key?(:ids) && !data.key?('error')
|
@@ -183,6 +193,7 @@ module Mogli
|
|
183
193
|
end
|
184
194
|
|
185
195
|
def raise_error_if_necessary(data)
|
196
|
+
raise HTTPException if data.respond_to?(:code) and data.code != 200
|
186
197
|
if data.kind_of?(Hash)
|
187
198
|
if data.keys.size == 1 and data["error"]
|
188
199
|
self.class.raise_error_by_type_and_message(data["error"]["type"], data["error"]["message"])
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Mogli
|
2
|
+
class FqlMultiquery
|
3
|
+
attr_reader :client, :queries, :raw_response
|
4
|
+
|
5
|
+
# Takes Mogli::Client object
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
8
|
+
@queries = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
# Adds single query to multiquery with class used to populate results
|
12
|
+
def add_named_query_for_class(query_name, query, klass)
|
13
|
+
@queries[query_name] = [query, klass]
|
14
|
+
end
|
15
|
+
|
16
|
+
# Fetch and parse results.
|
17
|
+
# Returns hash with the query names as keys, class objects as values.
|
18
|
+
# An empty or missing subquery value is returned as an empty array.
|
19
|
+
def results
|
20
|
+
parse_response @raw_response = @client.fql_multiquery(query_map)
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
|
25
|
+
def query_map
|
26
|
+
@queries.each_key.inject({}) { |res,k| res[k] = @queries[k][0]; res }
|
27
|
+
end
|
28
|
+
|
29
|
+
def parse_response(response)
|
30
|
+
# Fetch each subquery and map its results to the desired class,
|
31
|
+
@queries.each_key.inject({}) do |res, query|
|
32
|
+
# Default value is empty array
|
33
|
+
res[query] = []
|
34
|
+
# Find subquery by name in response
|
35
|
+
vals = response.find{|r| r['name'] == query.to_s}
|
36
|
+
if vals && vals.has_key?('fql_result_set')
|
37
|
+
res[query] = @client.map_to_class(vals['fql_result_set'], @queries[query][1])
|
38
|
+
end
|
39
|
+
res
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/mogli/user.rb
CHANGED
@@ -3,7 +3,7 @@ module Mogli
|
|
3
3
|
set_search_type
|
4
4
|
|
5
5
|
define_properties :first_name, :last_name, :link, :about, :birthday, :gender,
|
6
|
-
:email, :website, :timezone, :updated_time, :verified, :political,
|
6
|
+
:email, :website, :timezone, :updated_time, :verified, :political, :bio,
|
7
7
|
:relationship_status, :locale, :religion, :quotes, :third_party_id
|
8
8
|
|
9
9
|
def self.recognize?(hash)
|
@@ -16,6 +16,7 @@ module Mogli
|
|
16
16
|
hash_populating_accessor :location, "Page"
|
17
17
|
hash_populating_accessor :hometown, "Page"
|
18
18
|
hash_populating_accessor :languages, "Page"
|
19
|
+
hash_populating_accessor :significant_other, "User"
|
19
20
|
|
20
21
|
has_association :activities, "Activity"
|
21
22
|
has_association :friends, "User"
|
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: 43
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 26
|
10
|
+
version: 0.0.26
|
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-02
|
18
|
+
date: 2011-03-02 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- lib/mogli/education.rb
|
61
61
|
- lib/mogli/event.rb
|
62
62
|
- lib/mogli/fetching_array.rb
|
63
|
+
- lib/mogli/fql_multiquery.rb
|
63
64
|
- lib/mogli/group.rb
|
64
65
|
- lib/mogli/insight.rb
|
65
66
|
- lib/mogli/insight_value.rb
|