doesopengraph 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.rdoc +118 -1
  2. data/lib/doesopengraph/graph_api.rb +4 -2
  3. metadata +4 -28
data/README.rdoc CHANGED
@@ -1,7 +1,124 @@
1
1
  = DoesOpenGraph
2
2
 
3
3
  The Awexome Labs client library for accessing and manipulating the Facebook
4
- OpenGraph in ruby
4
+ OpenGraph in ruby.
5
+
6
+ DoesOpenGraph is designed to be a paper-thin library for accessing and manipulating
7
+ data on the Facebook Open Graph. It does not provide a high number of task or object-
8
+ specific integration points, instead relying on your application to discern the
9
+ type and content of each Node you access.
10
+
11
+ Likewise, the library is not configured with a YAML file, but is instead initialized
12
+ when you instantiate an object of the GraphAPI. This makes the library ideal for use
13
+ in ruby applications and scripts of all types, not just in rails.
14
+
15
+ If you are interested in full configuration for, say, a rails app, you can pair up
16
+ with DoesFacebook, or library for parsing signed requests from Facebook and providing
17
+ convenience methods to controllers and views.
18
+
19
+ == Installation
20
+
21
+ To install the gem, do the usual:
22
+
23
+ gem install doesopengraph
24
+
25
+ If you plan on using DoesOpenGraph in a project with a Gemfile:
26
+
27
+ gem "doesopengraph", ">=0.1.0"
28
+
29
+ You can live on the edge, too, if you like:
30
+
31
+ gem "doesopengraph", ">=0.1.0", :git=>"git://github.com/awexome/doesopengraph.git"
32
+
33
+
34
+ == Example Usage
35
+
36
+ Using DoesOpenGraph is easy. You can access public content without an access token. To
37
+ do so, just spin up a non-private API instance and go:
38
+
39
+ include DoesOpenGraph
40
+ api = GraphAPI.new()
41
+ => #<DoesOpenGraph::GraphAPI:0x00000100a13320 @access_token=nil>
42
+
43
+ node = api.node("philadelphiaflyers")
44
+ => #<DoesOpenGraph::GraphNode:0x00000100a055e0 @content={"id"=>"87169796810", "name"=>"Philadelphia Flyers", "picture"=>"http://profile.ak.fbcdn.net/hprofile-ak-snc4/71177_87169796810_7868331_s.jpg", "link"=>"http://www.facebook.com/philadelphiaflyers", "category"=>"Professional sports team", "website"=>"http://philadelphiaflyers.com\nhttp://www.youtube.com/flyersorganization\nhttp://twitter.com/NHLFLYERS\nhttp://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendid=154192480&MyToken=aea080cc-eb98-4a80-ad56-2cc34210c0aa", "username"=>"philadelphiaflyers", "location"=>{"street"=>"Wells Fargo Center, 3601 South Broad St.", "city"=>"Philadelphia", "state"=>"PA", "country"=>"United States", "zip"=>"19148"}, "phone"=>"215.218.PUCK (7825)", "affiliation"=>"NHL", "likes"=>446371}, @api=#<DoesOpenGraph::GraphAPI:0x00000100a13320 @access_token=nil>>
45
+
46
+ You'll see that accessing a public page via the GraphAPI will return a GraphNode object
47
+ containing attributes from the graph document. You can access these attributes directly:
48
+
49
+ node.likes
50
+ => 446374
51
+ node.affiliation
52
+ => "NHL"
53
+ node.phone
54
+ => "215.218.PUCK (7825)"
55
+ node.category
56
+ => "Professional sports team"
57
+ node.picture
58
+ => "http://profile.ak.fbcdn.net/hprofile-ak-snc4/71177_87169796810_7868331_s.jpg"
59
+
60
+ Not bad. You may also notice that the returned GraphNode object contains a reference to
61
+ the GraphAPI object that was used to access it. This allows you to run a reload on the
62
+ node just as if it were an ActiveRecord object. Reloading will pull the latest content
63
+ from the Open Graph and update your local object. So if someone had come along and liked
64
+ or unliked the page in the time we'd been playing around, we'd see the increase or decrease:
65
+
66
+ node.reload
67
+ => [updated GraphNode object returned]
68
+ node.likes
69
+ => 446373 # Whoops! One less fan! :-(
70
+
71
+
72
+ == Load Node Metadata and Connections
73
+
74
+ For any node object you've pulled from the graph, you can ask it what it's capable of
75
+ providing. This allows you to see all of the fancy bits that may extend or be attached to
76
+ the user, page, or object you're looking at. These are called "connections" in the graph.
77
+
78
+ Not sure what connections are at your disposal? Ask!
79
+
80
+ node.introspect
81
+ => #<DoesOpenGraph::GraphNode:0x000001009a49c0 @content={"id"=>"87169796810", "name"=>"Philadelphia Flyers", "picture"=>"http://profile.ak.fbcdn.net/hprofile-ak-snc4/71177_87169796810_7868331_s.jpg", "link"=>"http://www.facebook.com/philadelphiaflyers", "category"=>"Professional sports team", "website"=>"http://philadelphiaflyers.com\nhttp://www.youtube.com/flyersorganization\nhttp://twitter.com/NHLFLYERS\nhttp://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendid=154192480&MyToken=aea080cc-eb98-4a80-ad56-2cc34210c0aa", "username"=>"philadelphiaflyers", "location"=>{"street"=>"Wells Fargo Center, 3601 South Broad St.", "city"=>"Philadelphia", "state"=>"PA", "country"=>"United States", "zip"=>"19148"}, "phone"=>"215.218.PUCK (7825)", "affiliation"=>"NHL", "likes"=>446373, "metadata"=>{"connections"=>{"feed"=>"http://graph.facebook.com/87169796810/feed", "posts"=>"http://graph.facebook.com/87169796810/posts", "tagged"=>"http://graph.facebook.com/87169796810/tagged", "statuses"=>"http://graph.facebook.com/87169796810/statuses", "links"=>"http://graph.facebook.com/87169796810/links", "notes"=>"http://graph.facebook.com/87169796810/notes", "photos"=>"http://graph.facebook.com/87169796810/photos", "albums"=>"http://graph.facebook.com/87169796810/albums", "events"=>"http://graph.facebook.com/87169796810/events", "videos"=>"http://graph.facebook.com/87169796810/videos"}, "fields"=>[{"name"=>"id", "description"=>"The Page's ID. Publicly available. A JSON string."}, {"name"=>"name", "description"=>"The Page's name. Publicly available. A JSON string."}, {"name"=>"category", "description"=>"The Page's category. Publicly available. A JSON string."}, {"name"=>"likes", "description"=>"\\* The number of users who like the Page. Publicly available. A JSON number."}]}, "type"=>"page"}, @api=#<DoesOpenGraph::GraphAPI:0x00000100a13320 @access_token=nil>>
82
+
83
+ Perhaps that's too much to read through, but the key point is that introspecting a node
84
+ returns the very same node, but includes the all-important metadata attribute, which you
85
+ can pull available connections from:
86
+
87
+ node.introspect.metadata["connections"]
88
+ => {"feed"=>"http://graph.facebook.com/87169796810/feed", "posts"=>"http://graph.facebook.com/87169796810/posts", "tagged"=>"http://graph.facebook.com/87169796810/tagged", "statuses"=>"http://graph.facebook.com/87169796810/statuses", "links"=>"http://graph.facebook.com/87169796810/links", "notes"=>"http://graph.facebook.com/87169796810/notes", "photos"=>"http://graph.facebook.com/87169796810/photos", "albums"=>"http://graph.facebook.com/87169796810/albums", "events"=>"http://graph.facebook.com/87169796810/events", "videos"=>"http://graph.facebook.com/87169796810/videos"}
89
+
90
+ Curious as to the public feed of the node object? Grab it like so:
91
+
92
+ node = api.node("philadelphiaflyers", "feed")
93
+ => # A huge list of feed posts you can play with
94
+ node = api.node("philadelphiaflyers", "photos")
95
+ => # Likewise huge list of photos to do fun things with
96
+
97
+ And that's pretty much it.
98
+
99
+
100
+ == Private and Privileged Usage
101
+
102
+ You can do more than read and reload objects on the graph, however. It's easy to post new
103
+ connection pieces, remove content from the graph, and remove and alter connections to
104
+ specific nodes on the Open Graph.
105
+
106
+ To do it, you'll need an OAuth access token. Your application can handle this by following
107
+ any of the Facebook methods documented at http://developers.facebook.com/docs/authentication
108
+
109
+ Once you have an access token for a particular user, page, or node, instantiate a special
110
+ GraphAPI object with it for easy-access:
111
+
112
+ api = GraphAPI.new("__YOUR_ACCESS_TOKEN_HERE__")
113
+
114
+ With a privileged API client, you can now expose the following methods of the API:
115
+
116
+ api.node() # just like before, but with more info; also known as api.get()
117
+ api.update() # alter and add data; also known as api.post()
118
+ api.delete() # delete something from the graph (a post, connection, or node)
119
+ api.search() # search the entire open graph
120
+
121
+ Explore and enjoy!
5
122
 
6
123
 
7
124
  == Copyright
@@ -63,7 +63,8 @@ module DoesOpenGraph
63
63
  data = JSON.parse(response.body)
64
64
  return GraphResponse.new(data)
65
65
  rescue JSON::ParserError => jsone
66
- raise "Invalid JSON or poorly formed JSON returned for #{path}" and return nil
66
+ # A JSON.parse on "true" triggers an error, so let's build it straight from body:
67
+ return GraphResponse.new(response.body)
67
68
  end
68
69
  end
69
70
  alias_method :post, :update
@@ -85,7 +86,8 @@ module DoesOpenGraph
85
86
  data = JSON.parse(response.body)
86
87
  return GraphResponse.new(data)
87
88
  rescue JSON::ParserError => jsone
88
- raise "Invalid JSON or poorly formed JSON returned for #{path}" and return nil
89
+ # A JSON.parse on "true" triggers an error, so let's build it straight from body:
90
+ return GraphResponse.new(response.body)
89
91
  end
90
92
  end
91
93
 
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doesopengraph
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 0
9
- version: 0.1.0
4
+ prerelease:
5
+ version: 0.1.1
10
6
  platform: ruby
11
7
  authors:
12
8
  - mccolin
@@ -14,7 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2011-02-09 00:00:00 -05:00
13
+ date: 2011-03-25 00:00:00 -04:00
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
@@ -24,10 +20,6 @@ dependencies:
24
20
  requirements:
25
21
  - - ">="
26
22
  - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- - 2
30
- - 0
31
23
  version: 0.2.0
32
24
  type: :runtime
33
25
  prerelease: false
@@ -39,10 +31,6 @@ dependencies:
39
31
  requirements:
40
32
  - - ~>
41
33
  - !ruby/object:Gem::Version
42
- segments:
43
- - 1
44
- - 0
45
- - 0
46
34
  version: 1.0.0
47
35
  type: :development
48
36
  prerelease: false
@@ -54,10 +42,6 @@ dependencies:
54
42
  requirements:
55
43
  - - ~>
56
44
  - !ruby/object:Gem::Version
57
- segments:
58
- - 1
59
- - 5
60
- - 1
61
45
  version: 1.5.1
62
46
  type: :development
63
47
  prerelease: false
@@ -69,10 +53,6 @@ dependencies:
69
53
  requirements:
70
54
  - - ">="
71
55
  - !ruby/object:Gem::Version
72
- segments:
73
- - 0
74
- - 2
75
- - 0
76
56
  version: 0.2.0
77
57
  type: :runtime
78
58
  prerelease: false
@@ -107,21 +87,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
107
87
  requirements:
108
88
  - - ">="
109
89
  - !ruby/object:Gem::Version
110
- segments:
111
- - 0
112
90
  version: "0"
113
91
  required_rubygems_version: !ruby/object:Gem::Requirement
114
92
  none: false
115
93
  requirements:
116
94
  - - ">="
117
95
  - !ruby/object:Gem::Version
118
- segments:
119
- - 0
120
96
  version: "0"
121
97
  requirements: []
122
98
 
123
99
  rubyforge_project:
124
- rubygems_version: 1.3.7
100
+ rubygems_version: 1.5.2
125
101
  signing_key:
126
102
  specification_version: 3
127
103
  summary: The Awexome Labs library for accessing and manipulating the Facebook OpenGraph