mini_fb 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mini_fb.rb +55 -40
- data/test/test_mini_fb.rb +6 -0
- metadata +4 -4
data/lib/mini_fb.rb
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
#MiniFB - the simple miniature facebook library
|
2
|
+
#MiniFB is a small, lightweight Ruby library for interacting with the Facebook API.
|
3
|
+
#
|
4
|
+
#Brought to you by: www.appoxy.com
|
5
|
+
#
|
6
|
+
#Support
|
7
|
+
#
|
8
|
+
#Join our Discussion Group at: http://groups.google.com/group/mini_fb
|
9
|
+
#
|
10
|
+
#Demo Rails Application
|
11
|
+
#
|
12
|
+
#There is a demo Rails app that uses mini_fb graph api at: http://github.com/appoxy/mini_fb_demo
|
13
|
+
|
1
14
|
require 'digest/md5'
|
2
15
|
require 'erb'
|
3
16
|
require 'json' unless defined? JSON
|
@@ -337,14 +350,52 @@ module MiniFB
|
|
337
350
|
# options:
|
338
351
|
# - type: eg: feed, home, etc
|
339
352
|
# - metadata: to include metadata in response. true/false
|
353
|
+
# - params: Any additional parameters you would like to submit
|
340
354
|
def self.get(access_token, id, options={})
|
341
355
|
url = "#{graph_base}#{id}"
|
342
356
|
url << "/#{options[:type]}" if options[:type]
|
343
|
-
|
344
|
-
|
357
|
+
params = options[:params] || {}
|
358
|
+
params["access_token"] = "#{(access_token)}"
|
359
|
+
params["metadata"] = "1" if options[:metadata]
|
345
360
|
return fetch(url)
|
346
361
|
end
|
347
362
|
|
363
|
+
# Posts data to the Facebook Graph API
|
364
|
+
# options:
|
365
|
+
# - type: eg: feed, home, etc
|
366
|
+
# - metadata: to include metadata in response. true/false
|
367
|
+
# - params: Any additional parameters you would like to submit
|
368
|
+
def self.post(access_token, id, options={})
|
369
|
+
url = "#{graph_base}#{id}"
|
370
|
+
url << "/#{options[:type]}" if options[:type]
|
371
|
+
params = options[:params] || {}
|
372
|
+
params["access_token"] = "#{(access_token)}"
|
373
|
+
params["metadata"] = "1" if options[:metadata]
|
374
|
+
return fetch(url, :params => params, :method => :post)
|
375
|
+
|
376
|
+
end
|
377
|
+
|
378
|
+
# Executes an FQL query
|
379
|
+
def self.fql(access_token, fql_query, options={})
|
380
|
+
url = "https://api.facebook.com/method/fql.query"
|
381
|
+
params = options[:params] || {}
|
382
|
+
params["access_token"] = "#{(access_token)}"
|
383
|
+
params["metadata"] = "1" if options[:metadata]
|
384
|
+
params["query"] = fql_query
|
385
|
+
params["format"] = "JSON"
|
386
|
+
return fetch(url, :params => params)
|
387
|
+
end
|
388
|
+
|
389
|
+
# Uses new Oauth 2 authentication against old Facebook REST API
|
390
|
+
def self.rest(access_token, api_method, options={})
|
391
|
+
url = "https://api.facebook.com/method/#{api_method}"
|
392
|
+
params = options[:params] || {}
|
393
|
+
params[:access_token] = access_token
|
394
|
+
params[:format] = "JSON"
|
395
|
+
return fetch(url, :params => params, :method => method)
|
396
|
+
end
|
397
|
+
|
398
|
+
|
348
399
|
def self.fetch(url, options={})
|
349
400
|
puts 'url=' + url if @@logging
|
350
401
|
begin
|
@@ -352,7 +403,7 @@ module MiniFB
|
|
352
403
|
resp = RestClient.post url, options[:params]
|
353
404
|
else
|
354
405
|
if options[:params] && options[:params].size > 0
|
355
|
-
url += '?' + options[:params].each.map {|k,v| "%s=%s" % [k,v]}.join('&')
|
406
|
+
url += '?' + options[:params].each.map {|k,v| URI.escape("%s=%s" % [k,v])}.join('&')
|
356
407
|
end
|
357
408
|
resp = RestClient.get url
|
358
409
|
end
|
@@ -381,43 +432,6 @@ module MiniFB
|
|
381
432
|
|
382
433
|
end
|
383
434
|
|
384
|
-
# Posts data to the Facebook Graph API
|
385
|
-
# options:
|
386
|
-
# - type: eg: feed, home, etc
|
387
|
-
# - metadata: to include metadata in response. true/false
|
388
|
-
def self.post(access_token, id, options={})
|
389
|
-
url = "#{graph_base}#{id}"
|
390
|
-
url << "/#{options[:type]}" if options[:type]
|
391
|
-
options.delete(:type)
|
392
|
-
params = {}
|
393
|
-
options.each do |key,value|
|
394
|
-
params[key] = "#{value}"
|
395
|
-
end
|
396
|
-
params["access_token"] = "#{(access_token)}"
|
397
|
-
params["metadata"] = "1" if options[:metadata]
|
398
|
-
return fetch(url, :params => params, :method => :post)
|
399
|
-
|
400
|
-
end
|
401
|
-
|
402
|
-
# Executes an FQL query
|
403
|
-
def self.fql(access_token, fql_query, options={})
|
404
|
-
url = "https://api.facebook.com/method/fql.query"
|
405
|
-
url << "?access_token=#{URI.escape(access_token)}"
|
406
|
-
url << "&query=#{URI.escape(fql_query)}"
|
407
|
-
url << "&format=JSON"
|
408
|
-
return fetch(url)
|
409
|
-
end
|
410
|
-
|
411
|
-
# Uses new Oauth 2 authentication against old Facebook REST API
|
412
|
-
def self.rest(access_token, api_method, options={})
|
413
|
-
url = "https://api.facebook.com/method/#{api_method}"
|
414
|
-
options[:access_token] = access_token
|
415
|
-
options[:format] = "json"
|
416
|
-
method = (options[:method]) ? options[:method] : :get
|
417
|
-
options.delete(:method) if options[:method]
|
418
|
-
return fetch(url, :params => options, :method => method)
|
419
|
-
end
|
420
|
-
|
421
435
|
# Returns all available scopes.
|
422
436
|
def self.scopes
|
423
437
|
all_scopes = []
|
@@ -428,6 +442,7 @@ module MiniFB
|
|
428
442
|
scope_names.each { |x| all_scopes << "user_" + x; all_scopes << "friends_" + x}
|
429
443
|
all_scopes << "read_friendlists"
|
430
444
|
all_scopes << "read_stream"
|
445
|
+
all_scopes << "publish_stream"
|
431
446
|
all_scopes
|
432
447
|
end
|
433
448
|
|
data/test/test_mini_fb.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mini_fb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 5
|
10
|
+
version: 1.0.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Travis Reeder
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-06-
|
19
|
+
date: 2010-06-13 00:00:00 -07:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|