hyper-graph 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +29 -8
  2. data/lib/hyper_graph.rb +7 -2
  3. metadata +3 -3
data/README.md CHANGED
@@ -3,28 +3,45 @@ HyperGraph
3
3
 
4
4
  HyperGraph is a simple Ruby library for accessing [Facebook's Graph API](http://developers.facebook.com/docs/api)
5
5
 
6
+ Installation
7
+ -----
8
+
9
+ Install it with:
10
+
11
+ gem install hyper-graph
12
+
13
+ Be sure to require it properly, with an underscore not a hyphen:
14
+
15
+ require 'hyper_graph'
16
+
6
17
  Usage
7
18
  -----
8
19
 
9
- Supports id and connection get and post requests, parsing the response into a Ruby-friendly format. [Read up on the API](http://developers.facebook.com/docs/api) to learn how it works.
20
+ Supports 'ID' and 'ID/CONNECTION_TYPE' API requests using GET, POST and DELETE. HyperGraph parses the API's JSON response into a Ruby-friendly format.
21
+ [Read up on the API](http://developers.facebook.com/docs/api) to learn what that means.
10
22
 
11
23
  Create a graph to store the session key:
12
24
  irb > graph = HyperGraph.new('my-access-token')
13
25
  => #<HyperGraph:0x1943b98 @access_token="my-access-token">
14
26
  irb > graph.get('me')
15
- => {:updated_time=>Wed Mar 17 16:19:03 -0400 2010, :first_name=>"Chris", :last_name=>"Dinn", :name=>"Chris Dinn", :link=>"http://www.facebook.com/chrisdinn", :timezone=>-4, :birthday=>"05/28/1983", :id=>518018845, :verified=>true}
27
+ => {:updated_time=>Wed Mar 17 16:19:03 -0400 2010, :first_name=>"Chris", :last_name=>"Dinn", :name=>"Chris Dinn",
28
+ :link=>"http://www.facebook.com/chrisdinn", :timezone=>-4, :birthday=>"05/28/1983", :id=>518018845, :verified=>true}
16
29
 
17
30
  Or, make requests directly from HyperGraph, though you'll need an access token for most requests:
18
31
  irb > HyperGraph.get('518018845')
19
32
  => {:first_name=>"Chris", :last_name=>"Dinn", :name=>"Chris Dinn", :link=>"http://www.facebook.com/chrisdinn", :id=>518018845}
20
33
  irb > HyperGraph.get('518018845', :access_token => 'my-access-token')
21
- => {:updated_time=>Wed Mar 17 16:19:03 -0400 2010, :first_name=>"Chris", :last_name=>"Dinn", :name=>"Chris Dinn", :link=>"http://www.facebook.com/chrisdinn", :timezone=>-4, :birthday=>"05/28/1983", :id=>518018845, :verified=>true}
34
+ => {:updated_time=>Wed Mar 17 16:19:03 -0400 2010, :first_name=>"Chris", :last_name=>"Dinn", :name=>"Chris Dinn",
35
+ :link=>"http://www.facebook.com/chrisdinn", :timezone=>-4, :birthday=>"05/28/1983", :id=>518018845, :verified=>true}
22
36
 
23
37
  You can also request connections:
24
38
  irb > graph.get('me/photos', :limit => 1)
25
- => [{:source=>"http://sphotos.ak.fbcdn.net/hphotos-ak-snc3/hs239.snc3/22675_248026512444_511872444_3217612_4249159_n.jpg", :picture=>"http://photos-b.ak.fbcdn.net/hphotos-ak-snc3/hs239.snc3/22675_248026512444_511872444_3217612_4249159_s.jpg",
26
- :updated_time=>Sun Jan 10 18:06:36 -0500 2010, :from=>{:name=>"Jennifer Byrne", :id=>511872444}, :name=>"Finally a day off....xmas dinner, a few days late", :link=>"http://www.facebook.com/photo.php?pid=3217612&id=511872444",
27
- :icon=>"http://static.ak.fbcdn.net/rsrc.php/z2E5Y/hash/8as8iqdm.gif", :tags=>[{:name=>"Chris Dinn", :y=>15.3846, :created_time=>Sun Jan 10 18:06:41 -0500 2010, :id=>518018845, :x=>83.8889}], :created_time=>Sun Jan 10 18:00:10 -0500 2010,
39
+ => [{:source=>"http://sphotos.ak.fbcdn.net/hphotos-ak-snc3/hs239.snc3/22675_248026512444_511872444_3217612_4249159_n.jpg",
40
+ :picture=>"http://photos-b.ak.fbcdn.net/hphotos-ak-snc3/hs239.snc3/22675_248026512444_511872444_3217612_4249159_s.jpg",
41
+ :updated_time=>Sun Jan 10 18:06:36 -0500 2010, :from=>{:name=>"Jennifer Byrne", :id=>511872444},
42
+ :name=>"Finally a day off....xmas dinner, a few days late", :link=>"http://www.facebook.com/photo.php?pid=3217612&id=511872444",
43
+ :icon=>"http://static.ak.fbcdn.net/rsrc.php/z2E5Y/hash/8as8iqdm.gif", :tags=>[{:name=>"Chris Dinn", :y=>15.3846,
44
+ :created_time=>Sun Jan 10 18:06:41 -0500 2010, :id=>518018845, :x=>83.8889}], :created_time=>Sun Jan 10 18:00:10 -0500 2010,
28
45
  :id=>248026512444, :width=>604, :height=>483}]
29
46
 
30
47
  Similarly, make a post or delete request:
@@ -35,8 +52,12 @@ Similarly, make a post or delete request:
35
52
  irb > graph.delete('514569082_115714061789461/likes')
36
53
  => true
37
54
 
38
- Time variables are converted into Time objects, IDs are converted to integers. Paging information is discarded from requests that return an array, so be sure to managed paging manually.
39
-
55
+ When parsing the response, time variables are converted into Time objects and IDs are converted to integers. Note that paging information is discarded from requests that return an array, so be sure to manage paging manually.
56
+
57
+ Problems/Bugs/Requests
58
+ -----------------------------
59
+
60
+ Please, file an issue.
40
61
 
41
62
  Note on Patches/Pull Requests
42
63
  -----------------------------
data/lib/hyper_graph.rb CHANGED
@@ -2,14 +2,17 @@ require 'net/http'
2
2
  require 'time'
3
3
  require 'json'
4
4
 
5
+ # Wrapper for errors generated by the Facebook Graph API server
5
6
  class FacebookError<StandardError;end
6
7
 
8
+ # HyperGraph acts as a facade for the Facebook Graph API.
9
+ # It handles network calls and JSON response parsing.
7
10
  class HyperGraph
8
11
  API_URL = 'graph.facebook.com'
9
12
 
10
13
  # Class methods
11
14
  class << self
12
- #Request an object from the social graph
15
+ # Request an object from the social graph
13
16
  def get(requested_object_id, options = {})
14
17
  http = Net::HTTP.new(API_URL)
15
18
  request_path = "/#{requested_object_id}"
@@ -22,6 +25,7 @@ class HyperGraph
22
25
  normalize_response(data)
23
26
  end
24
27
 
28
+ # Post an object to the graph
25
29
  def post(requested_object_id, options = {})
26
30
  http = Net::HTTP.new(API_URL)
27
31
  request_path = "/#{requested_object_id}"
@@ -34,6 +38,7 @@ class HyperGraph
34
38
  end
35
39
  end
36
40
 
41
+ # Send a delete request to the graph
37
42
  def delete(requested_object_id, options = {})
38
43
  post(requested_object_id, options.merge(:method => 'delete'))
39
44
  end
@@ -64,7 +69,7 @@ class HyperGraph
64
69
  hash.each do |k, v|
65
70
  case k
66
71
  when "error"
67
- raise FacebookError.new("#{hash['error']} - #{hash['message']}")
72
+ raise FacebookError.new("#{v['type']} - #{v['message']}")
68
73
  when "id"
69
74
  normalized_hash[k.to_sym] = v.to_i
70
75
  when /_time$/
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Chris Dinn
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-23 00:00:00 -04:00
17
+ date: 2010-04-24 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency