mini_fb 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +22 -1
- data/lib/mini_fb.rb +34 -11
- metadata +3 -3
data/README.markdown
CHANGED
@@ -71,7 +71,8 @@ Also pretty simple:
|
|
71
71
|
FQL
|
72
72
|
---
|
73
73
|
|
74
|
-
|
74
|
+
my_query = "select uid,a,b,c from users where ...."
|
75
|
+
@res = MiniFB.fql(@access_token, my_query)
|
75
76
|
|
76
77
|
Logging
|
77
78
|
-------
|
@@ -96,6 +97,26 @@ The most general case is to use MiniFB.call method:
|
|
96
97
|
|
97
98
|
Which simply returns the parsed json response from Facebook.
|
98
99
|
|
100
|
+
|
101
|
+
Oauth 2.0 Authentication and Original Rest Api
|
102
|
+
-------------
|
103
|
+
|
104
|
+
You can use the Graph api Oauth 2.0 token with original api methods. BEWARE: This has only been tested against stream.publish at present.
|
105
|
+
|
106
|
+
MiniFB.rest(@access_token, "rest.api.method", options)
|
107
|
+
|
108
|
+
eg:
|
109
|
+
|
110
|
+
response = MiniFB.rest(@access_token, "stream.publish", {
|
111
|
+
:uid => @user_id,
|
112
|
+
:to => @to_user_id,
|
113
|
+
:message => "....message.....",
|
114
|
+
:method => :post
|
115
|
+
})
|
116
|
+
|
117
|
+
the :method will default to :get if no value is supplied and all responses will be json. In the instance of 'bad json' methods, the response will formatted {'response': '#{bad_response_string}'}
|
118
|
+
|
119
|
+
|
99
120
|
Some Higher Level Objects for Common Uses
|
100
121
|
----------------------
|
101
122
|
|
data/lib/mini_fb.rb
CHANGED
@@ -56,8 +56,8 @@ module MiniFB
|
|
56
56
|
return MiniFB.call(api_key, secret_key, method, params.update("session_key"=>session_key))
|
57
57
|
end
|
58
58
|
|
59
|
-
|
60
59
|
end
|
60
|
+
|
61
61
|
class User
|
62
62
|
FIELDS = [:uid, :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, :work_history, :sex, :religion, :notes_count, :activities, :pic_square, :movies, :has_added_app, :education_history, :birthday, :birthday_date, :first_name, :meeting_for, :last_name, :interests, :current_location, :pic, :books, :affiliations, :locale, :profile_url, :proxied_email, :email, :email_hashes, :allowed_restrictions, :pic_with_logo, :pic_big_with_logo, :pic_small_with_logo, :pic_square_with_logo]
|
63
63
|
STANDARD_FIELDS = [:uid, :first_name, :last_name, :name, :timezone, :birthday, :sex, :affiliations, :locale, :profile_url, :proxied_email, :email]
|
@@ -175,16 +175,14 @@ module MiniFB
|
|
175
175
|
response = Net::HTTP.post_form( URI.parse(FB_URL), post_params(kwargs))
|
176
176
|
rescue SocketError => err
|
177
177
|
# why are we catching this and throwing as different error? hmmm..
|
178
|
-
#
|
178
|
+
# raise IOError.new( "Cannot connect to the facebook server: " + err )
|
179
179
|
raise err
|
180
180
|
end
|
181
181
|
end
|
182
182
|
|
183
|
-
|
184
183
|
# Handle response
|
185
184
|
return response.body if custom_format
|
186
185
|
|
187
|
-
|
188
186
|
body = response.body
|
189
187
|
|
190
188
|
puts 'response=' + body.inspect if @@logging
|
@@ -331,6 +329,7 @@ module MiniFB
|
|
331
329
|
return params
|
332
330
|
end
|
333
331
|
|
332
|
+
# Gets data from the Facebook Graph API
|
334
333
|
# options:
|
335
334
|
# - type: eg: feed, home, etc
|
336
335
|
# - metadata: to include metadata in response. true/false
|
@@ -339,20 +338,28 @@ module MiniFB
|
|
339
338
|
url << "/#{options[:type]}" if options[:type]
|
340
339
|
url << "?access_token=#{URI.escape(access_token)}"
|
341
340
|
url << "&metadata=1" if options[:metadata]
|
342
|
-
return fetch
|
341
|
+
return fetch(url)
|
343
342
|
end
|
344
343
|
|
345
344
|
def self.fetch(url, options={})
|
346
345
|
puts 'url=' + url if @@logging
|
347
|
-
begin
|
348
|
-
if options[:
|
346
|
+
begin
|
347
|
+
if options[:method] == :post
|
349
348
|
resp = RestClient.post url, options[:params]
|
350
349
|
else
|
351
350
|
resp = RestClient.get url
|
352
351
|
end
|
352
|
+
|
353
353
|
puts 'resp=' + resp.body.to_s if @@logging
|
354
|
-
|
355
|
-
|
354
|
+
|
355
|
+
begin
|
356
|
+
res_hash = JSON.parse(resp.body)
|
357
|
+
rescue
|
358
|
+
# quick fix for things like stream.publish that don't return json
|
359
|
+
res_hash = JSON.parse("{\"response\": #{resp.body.to_s}}")
|
360
|
+
end
|
361
|
+
|
362
|
+
if res_hash.is_a? Array # fql return this
|
356
363
|
res_hash.collect! {|x| Hashie::Mash.new(x) }
|
357
364
|
else
|
358
365
|
res_hash = Hashie::Mash.new(res_hash)
|
@@ -367,25 +374,41 @@ module MiniFB
|
|
367
374
|
|
368
375
|
end
|
369
376
|
|
377
|
+
# Posts data to the Facebook Graph API
|
370
378
|
# options:
|
371
379
|
# - type: eg: feed, home, etc
|
372
380
|
# - metadata: to include metadata in response. true/false
|
373
381
|
def self.post(access_token, id, options={})
|
374
382
|
url = "#{graph_base}#{id}"
|
375
383
|
url << "/#{options[:type]}" if options[:type]
|
384
|
+
options.delete(:type)
|
376
385
|
params = {}
|
386
|
+
options.each do |key,value|
|
387
|
+
params[key] = "#{value}"
|
388
|
+
end
|
377
389
|
params["access_token"] = "#{(access_token)}"
|
378
390
|
params["metadata"] = "1" if options[:metadata]
|
379
|
-
return fetch
|
391
|
+
return fetch(url, :params => params, :method => :post)
|
380
392
|
|
381
393
|
end
|
382
394
|
|
395
|
+
# Executes an FQL query
|
383
396
|
def self.fql(access_token, fql_query, options={})
|
384
397
|
url = "https://api.facebook.com/method/fql.query"
|
385
398
|
url << "?access_token=#{URI.escape(access_token)}"
|
386
399
|
url << "&query=#{URI.escape(fql_query)}"
|
387
400
|
url << "&format=JSON"
|
388
|
-
return fetch
|
401
|
+
return fetch(url)
|
402
|
+
end
|
403
|
+
|
404
|
+
# Uses new Oauth 2 authentication against old Facebook REST API
|
405
|
+
def self.rest(access_token, api_method, options={})
|
406
|
+
url = "https://api.facebook.com/method/#{api_method}"
|
407
|
+
options[:token] = access_token
|
408
|
+
options[:format] = "json"
|
409
|
+
method = (options[:method]) ? options[:method]: :get
|
410
|
+
options.delete(:method) if options[:method]
|
411
|
+
return fetch(url, :params => options, :method => method)
|
389
412
|
end
|
390
413
|
|
391
414
|
# Returns all available scopes.
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 1.0.
|
8
|
+
- 3
|
9
|
+
version: 1.0.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Travis Reeder
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-05-
|
18
|
+
date: 2010-05-07 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|