mini_fb 1.0.0 → 1.0.1

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.
Files changed (3) hide show
  1. data/README.markdown +11 -1
  2. data/lib/mini_fb.rb +28 -18
  3. metadata +3 -3
data/README.markdown CHANGED
@@ -3,10 +3,17 @@ MiniFB - the simple miniature facebook library
3
3
 
4
4
  MiniFB is a small, lightweight Ruby library for interacting with the [Facebook API](http://wiki.developers.facebook.com/index.php/API).
5
5
 
6
+ Brought to you by: [![Appoxy](http://www.simpledeployr.com/images/global/appoxy-small.png)](http://www.appoxy.com)
7
+
6
8
  Support
7
9
  --------
8
10
 
9
- Join our Discussion Group at: http://groups.google.com/group/mini_fb
11
+ Join our Discussion Group at: <http://groups.google.com/group/mini_fb>
12
+
13
+ Demo Rails Application
14
+ -------------------
15
+
16
+ There is a demo Rails app that uses mini_fb graph api at: [http://github.com/appoxy/mini_fb_demo](http://github.com/appoxy/mini_fb_demo)
10
17
 
11
18
  Installation
12
19
  -------------
@@ -48,6 +55,9 @@ It's very simple:
48
55
  @id = {some ID of something in facebook} || "me"
49
56
  @type = {some facebook type like feed, friends, or photos} # (optional) nil will just return the object data directly
50
57
  @response_hash = MiniFB.get(@access_token, @id, :type=>@type)
58
+ # @response_hash is a hash, but also allows object like syntax for instance, the following is true:
59
+ @response_hash["user"] == @response_hash.user
60
+
51
61
 
52
62
  Posting Data to Facebook
53
63
  ------------------------
data/lib/mini_fb.rb CHANGED
@@ -339,19 +339,32 @@ module MiniFB
339
339
  url << "/#{options[:type]}" if options[:type]
340
340
  url << "?access_token=#{URI.escape(access_token)}"
341
341
  url << "&metadata=1" if options[:metadata]
342
+ return fetch url
343
+ end
344
+
345
+ def self.fetch(url, options={})
342
346
  puts 'url=' + url if @@logging
343
347
  begin
344
- resp = RestClient.get url
348
+ if options[:type] == :post
349
+ resp = RestClient.post url, options[:params]
350
+ else
351
+ resp = RestClient.get url
352
+ end
353
+ puts 'resp=' + resp.body.to_s if @@logging
354
+ res_hash = JSON.parse(resp.body)
355
+ if res_hash.is_a? Array # fql queries return this
356
+ res_hash.collect! {|x| Hashie::Mash.new(x) }
357
+ else
358
+ res_hash = Hashie::Mash.new(res_hash)
359
+ end
360
+ return res_hash
345
361
  rescue RestClient::Exception => ex
346
362
  puts ex.http_code.to_s
347
363
  puts 'ex.http_body=' + ex.http_body if @@logging
348
364
  res_hash = JSON.parse(ex.http_body) # probably should ensure it has a good response
349
365
  raise MiniFB::FaceBookError.new(ex.http_code, "#{res_hash["error"]["type"]}: #{res_hash["error"]["message"]}")
350
366
  end
351
- puts 'resp=' + resp.body.to_s if @@logging
352
- res_hash = JSON.parse(resp.body)
353
- res_hash = Hashie::Mash.new(res_hash)
354
- return res_hash
367
+
355
368
  end
356
369
 
357
370
  # options:
@@ -363,19 +376,16 @@ module MiniFB
363
376
  params = {}
364
377
  params["access_token"] = "#{(access_token)}"
365
378
  params["metadata"] = "1" if options[:metadata]
366
- puts 'url=' + url if @@logging
367
- begin
368
- resp = RestClient.post url, params
369
- rescue RestClient::Exception => ex
370
- puts ex.http_code.to_s
371
- puts 'ex.http_body=' + ex.http_body if @@logging
372
- res_hash = JSON.parse(ex.http_body) # probably should ensure it has a good json response
373
- raise MiniFB::FaceBookError.new(ex.http_code, "#{res_hash["error"]["type"]}: #{res_hash["error"]["message"]}")
374
- end
375
- puts 'resp=' + resp.body.to_s if @@logging
376
- res_hash = JSON.parse(resp.body)
377
- res_hash = Hashie::Mash.new(res_hash)
378
- return res_hash
379
+ return fetch url, :params=>params, :method=>:post
380
+
381
+ end
382
+
383
+ def self.fql(access_token, fql_query, options={})
384
+ url = "https://api.facebook.com/method/fql.query"
385
+ url << "?access_token=#{URI.escape(access_token)}"
386
+ url << "&query=#{URI.escape(fql_query)}"
387
+ url << "&format=JSON"
388
+ return fetch url
379
389
  end
380
390
 
381
391
  # 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
- - 0
9
- version: 1.0.0
8
+ - 1
9
+ version: 1.0.1
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-04-29 00:00:00 -07:00
18
+ date: 2010-04-30 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency