doesopengraph 0.1.0

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.
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (C) 2011 by Awexome Labs, LLC
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,11 @@
1
+ = DoesOpenGraph
2
+
3
+ The Awexome Labs client library for accessing and manipulating the Facebook
4
+ OpenGraph in ruby
5
+
6
+
7
+ == Copyright
8
+
9
+ Copyright (C) 2011 by Awexome Labs, LLC
10
+ http://awexomelabs.com
11
+
@@ -0,0 +1,115 @@
1
+ # AWEXOME LABS
2
+ # DoesOpenGraph
3
+ #
4
+ # GraphAPI - Class containing get and post mechanism for accessing nodes
5
+ # within the open graph
6
+ #
7
+
8
+ module DoesOpenGraph
9
+ class GraphAPI
10
+
11
+ require "typhoeus"
12
+ require "uri"
13
+ require "json"
14
+
15
+ HTTP_GRAPH_ENDPOINT = "http://graph.facebook.com/"
16
+ HTTPS_GRAPH_ENDPOINT = "https://graph.facebook.com/"
17
+
18
+ attr_reader :access_token
19
+
20
+ def initialize(acctok=nil)
21
+ @access_token = acctok
22
+ end
23
+
24
+
25
+ def node(id, connection=nil, params={})
26
+ # Inject an access_token if we plan to make an authorized request:
27
+ params[:access_token] = @access_token if @access_token
28
+
29
+ # Stringify tokens:
30
+ id = id.to_s
31
+ connection = connection.to_s unless connection.nil?
32
+
33
+ # Smoosh the URL components together:
34
+ base = @access_token.nil? ? HTTP_GRAPH_ENDPOINT : HTTPS_GRAPH_ENDPOINT
35
+ path = connection.nil? ? id : File.join(id, connection)
36
+ href = File.join(base, path)
37
+
38
+ # Make a request and parse JSON result:
39
+ begin
40
+ response = Typhoeus::Request.get(href, :params=>params)
41
+ data = JSON.parse(response.body)
42
+ return GraphNode.new(data, self)
43
+ rescue JSON::ParserError => jsone
44
+ raise "Invalid JSON or poorly formed JSON returned for #{path}" and return nil
45
+ end
46
+ end
47
+ alias_method :get, :node
48
+
49
+
50
+ def update(id, connection, params={})
51
+ # Inject the access token if we have it and err if we don't
52
+ return nil unless @access_token
53
+ params[:access_token] = @access_token
54
+
55
+ # Smoosh the URL components together:
56
+ base = HTTPS_GRAPH_ENDPOINT
57
+ path = File.join(id, connection)
58
+ href = File.join(base, path)
59
+
60
+ # Make our POST request and check the results:
61
+ begin
62
+ response = Typhoeus::Request.post(href, :params=>params)
63
+ data = JSON.parse(response.body)
64
+ return GraphResponse.new(data)
65
+ rescue JSON::ParserError => jsone
66
+ raise "Invalid JSON or poorly formed JSON returned for #{path}" and return nil
67
+ end
68
+ end
69
+ alias_method :post, :update
70
+
71
+
72
+ def delete(id, connection=nil)
73
+ # Inject the access token if we have it and err if we don't
74
+ return nil unless @access_token
75
+ params = Hash.new and params[:access_token] = @access_token
76
+
77
+ # Smoosh the URL components together:
78
+ base = HTTPS_GRAPH_ENDPOINT
79
+ path = connection.nil? ? id : File.join(id, connection)
80
+ href = File.join(base, path)
81
+
82
+ # Make our DELETE request and return the results:
83
+ begin
84
+ response = Typhoeus::Request.delete(href, :params=>params)
85
+ data = JSON.parse(response.body)
86
+ return GraphResponse.new(data)
87
+ rescue JSON::ParserError => jsone
88
+ raise "Invalid JSON or poorly formed JSON returned for #{path}" and return nil
89
+ end
90
+ end
91
+
92
+
93
+ def search(query, type, params={})
94
+ # Inject the access token if we have it and err if we don't
95
+ return nil unless @access_token
96
+ params[:access_token] = @access_token
97
+
98
+ # Build the search query and its target:
99
+ params[:q] = query
100
+ params[:type] = type
101
+ href = File.join(HTTPS_GRAPH_ENDPOINT, "search")
102
+
103
+ # Make the request:
104
+ response = Typhoeus::Request.get(href, :params=>params)
105
+ data = JSON.parse(response.body)
106
+ return GraphResponse.new(data)
107
+ end
108
+
109
+
110
+
111
+ end # GraphAPI
112
+ end # DoesOpenGraph
113
+
114
+
115
+
@@ -0,0 +1,42 @@
1
+ # AWEXOME LABS
2
+ # DoesOpenGraph
3
+ #
4
+ # GraphNode - An instance of an item on the open graph
5
+ #
6
+
7
+ module DoesOpenGraph
8
+ class GraphNode < GraphResponse
9
+
10
+ # Fetch an updated view of this node
11
+ def reload
12
+ up = api.node(self.id)
13
+ @content = up.content
14
+ self
15
+ end
16
+
17
+ # Introspect on the connections available to this node
18
+ def introspect
19
+ api.node(self.id, nil, :metadata=>1)
20
+ end
21
+
22
+ # Delete this node from the graph
23
+ def delete
24
+ api.delete(self.id)
25
+ end
26
+
27
+ # Like this node, if supported
28
+ def like
29
+ api.post(self.id, "likes")
30
+ end
31
+
32
+ # Unlike this node, if supported
33
+ def unlike
34
+ api.delete(self.id, "likes")
35
+ end
36
+
37
+
38
+ end # GraphNode
39
+ end # DoesOpenGraph
40
+
41
+
42
+
@@ -0,0 +1,27 @@
1
+ # AWEXOME LABS
2
+ # DoesOpenGraph
3
+ #
4
+ # GraphResponse - A very simple wrapper for data returned by the OpenGraph API
5
+ #
6
+
7
+ module DoesOpenGraph
8
+ class GraphResponse
9
+
10
+ attr_reader :content, :api
11
+
12
+ # Build a Response object from request content and store the api
13
+ def initialize(content, api=nil)
14
+ @content = content.is_a?(Hash) ? content : Hash.new
15
+ @api = api
16
+ end
17
+
18
+ # Use secret patching to provide accessors to connections within node
19
+ def method_missing(m, *args, &block)
20
+ content.include?(m.to_s) ? content[m.to_s] : nil
21
+ end
22
+
23
+ end # GraphResponse
24
+ end # DoesOpenGraph
25
+
26
+
27
+
@@ -0,0 +1,12 @@
1
+ # AWEXOME
2
+ # DoesOpenGraph
3
+ #
4
+ # DoesOpenGraph - Module definition and loader
5
+
6
+ require "doesopengraph"
7
+ require "doesopengraph/graph_api"
8
+ require "doesopengraph/graph_response"
9
+ require "doesopengraph/graph_node"
10
+
11
+ module DoesOpenGraph
12
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: doesopengraph
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - mccolin
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-02-09 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: typhoeus
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 2
30
+ - 0
31
+ version: 0.2.0
32
+ type: :runtime
33
+ prerelease: false
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: bundler
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 1
44
+ - 0
45
+ - 0
46
+ version: 1.0.0
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: jeweler
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 1
59
+ - 5
60
+ - 1
61
+ version: 1.5.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: typhoeus
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 0
74
+ - 2
75
+ - 0
76
+ version: 0.2.0
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: *id004
80
+ description: The Awexome Labs library for accessing and manipulating the Facebook OpenGraph
81
+ email: info@awexomelabs.com
82
+ executables: []
83
+
84
+ extensions: []
85
+
86
+ extra_rdoc_files:
87
+ - LICENSE
88
+ - README.rdoc
89
+ files:
90
+ - lib/doesopengraph.rb
91
+ - lib/doesopengraph/graph_api.rb
92
+ - lib/doesopengraph/graph_node.rb
93
+ - lib/doesopengraph/graph_response.rb
94
+ - LICENSE
95
+ - README.rdoc
96
+ has_rdoc: true
97
+ homepage: http://awexomelabs.com/
98
+ licenses: []
99
+
100
+ post_install_message:
101
+ rdoc_options: []
102
+
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ segments:
111
+ - 0
112
+ version: "0"
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ segments:
119
+ - 0
120
+ version: "0"
121
+ requirements: []
122
+
123
+ rubyforge_project:
124
+ rubygems_version: 1.3.7
125
+ signing_key:
126
+ specification_version: 3
127
+ summary: The Awexome Labs library for accessing and manipulating the Facebook OpenGraph
128
+ test_files: []
129
+