hyper-graph 0.3.1 → 0.3.2
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/README.md +8 -2
- data/lib/hyper_graph.rb +11 -3
- data/test/hyper_graph_test.rb +27 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -54,7 +54,7 @@ You can make connection requests, too:
|
|
54
54
|
=> true
|
55
55
|
irb > graph.object('514569082_115714061789461').delete(:likes)
|
56
56
|
=> true
|
57
|
-
|
57
|
+
|
58
58
|
Or, you can request from the graph directly:
|
59
59
|
irb > graph.get('me')
|
60
60
|
=> {:updated_time=>Wed Mar 17 16:19:03 -0400 2010, :first_name=>"Chris", :last_name=>"Dinn", ...
|
@@ -68,7 +68,13 @@ Similarly, make a post or delete request directly from the graph:
|
|
68
68
|
=> true
|
69
69
|
irb > graph.delete('514569082_115714061789461/likes')
|
70
70
|
=> true
|
71
|
-
|
71
|
+
|
72
|
+
You can search, using the search function:
|
73
|
+
irb > graph.search('big band')
|
74
|
+
=> [{ :id => '113412341299949562_134212343177', :from => { :name => "Big Band Ballroom"...
|
75
|
+
irb > HyperGraph.search('big band')
|
76
|
+
=> [{ :id => '113412341299949562_134212343177', :from => { :name => "Big Band Ballroom"...
|
77
|
+
|
72
78
|
As well, you can make requests directly from HyperGraph, with or without an access token (though you'll need an access token for most requests):
|
73
79
|
irb > HyperGraph.get('518018845')
|
74
80
|
=> {:first_name=>"Chris", :last_name=>"Dinn", :name=>"Chris Dinn", ...
|
data/lib/hyper_graph.rb
CHANGED
@@ -20,7 +20,7 @@ class HyperGraph
|
|
20
20
|
request_path = "/#{requested_object_id}"
|
21
21
|
|
22
22
|
query = build_query(options)
|
23
|
-
request_path << "?#{query}" unless query==""
|
23
|
+
request_path << "?#{URI.escape(query)}" unless query==""
|
24
24
|
|
25
25
|
http_response = http.get(request_path)
|
26
26
|
data = extract_data(JSON.parse(http_response.body))
|
@@ -55,7 +55,11 @@ class HyperGraph
|
|
55
55
|
request_path = "/oauth/access_token"
|
56
56
|
request_path << "?#{build_query(:client_id => client_id, :client_secret => client_secret, :redirect_uri => redirect_uri, :code => code)}"
|
57
57
|
http_response = http.get(request_path)
|
58
|
-
http_response.body.split(
|
58
|
+
http_response.body.split(/\=|&/)[1]
|
59
|
+
end
|
60
|
+
|
61
|
+
def search(query, options = {})
|
62
|
+
get('search', options.merge(:q => query))
|
59
63
|
end
|
60
64
|
|
61
65
|
protected
|
@@ -93,7 +97,7 @@ class HyperGraph
|
|
93
97
|
when "error"
|
94
98
|
raise FacebookError.new("#{v['type']} - #{v['message']}")
|
95
99
|
when "id"
|
96
|
-
if (v
|
100
|
+
if (v == v.to_i.to_s)
|
97
101
|
normalized_hash[k.to_sym] = v.to_i
|
98
102
|
else
|
99
103
|
normalized_hash[k.to_sym] = v
|
@@ -149,4 +153,8 @@ class HyperGraph
|
|
149
153
|
def delete(requested_object_id, options = {})
|
150
154
|
self.class.delete(requested_object_id, options.merge(:access_token => @access_token))
|
151
155
|
end
|
156
|
+
|
157
|
+
def search(query, options = {})
|
158
|
+
self.class.get('search', options.merge(:access_token => @access_token, :q => query))
|
159
|
+
end
|
152
160
|
end
|
data/test/hyper_graph_test.rb
CHANGED
@@ -162,6 +162,32 @@ class HyperGraphTest < Test::Unit::TestCase
|
|
162
162
|
graph = HyperGraph.new(access_token)
|
163
163
|
assert_equal true, graph.delete('514569082_115714061789461/likes')
|
164
164
|
end
|
165
|
+
|
166
|
+
def test_graph_search
|
167
|
+
json_api_response = %'{"data": [
|
168
|
+
{"id": "113412341299949562_134212343177", "from": {"name": "Big Band Ballroom", "category": "Local_business", "id": "1334523899949562"}, "message": "Big band at our ballroom", "link": "http://www.facebook.com/", "type": "link" },
|
169
|
+
{"id": "100123706392497_142067305819279", "from": {"name": "Big Band Guy", "id": "100000706392497"},"message": "What a band", "type": "status" }
|
170
|
+
]}'
|
171
|
+
expected_parsed_response = [ { :id => '113412341299949562_134212343177',
|
172
|
+
:from => { :name => "Big Band Ballroom", :category=> "Local_business", :id => 1334523899949562 },
|
173
|
+
:message => "Big band at our ballroom",
|
174
|
+
:link => "http://www.facebook.com/",
|
175
|
+
:type => "link"},
|
176
|
+
{ :id => "100123706392497_142067305819279",
|
177
|
+
:from => { :name => "Big Band Guy", :id => 100000706392497 },
|
178
|
+
:message => "What a band",
|
179
|
+
:type => "status" }
|
180
|
+
]
|
181
|
+
access_token = "test-access-token"
|
182
|
+
mock_response = stub(:body => json_api_response)
|
183
|
+
@mock_connection.stubs(:use_ssl=).with(true)
|
184
|
+
@mock_connection.stubs(:get).with("/search?access_token=#{access_token}&q=big%20band").returns(mock_response)
|
185
|
+
|
186
|
+
assert_equal expected_parsed_response, HyperGraph.search('big band', :access_token => access_token)
|
187
|
+
|
188
|
+
graph = HyperGraph.new('test-access-token')
|
189
|
+
assert_equal expected_parsed_response, graph.search('big band', :access_token => access_token)
|
190
|
+
end
|
165
191
|
|
166
192
|
def test_authorize_url
|
167
193
|
client_id = "your-client-id"
|
@@ -187,7 +213,7 @@ class HyperGraphTest < Test::Unit::TestCase
|
|
187
213
|
client_secret = "your-client-secret"
|
188
214
|
code = "facebook-oauth-code"
|
189
215
|
callback_url = "http://yoursite.com/callback"
|
190
|
-
api_response = "access_token=#{access_token}"
|
216
|
+
api_response = "access_token=#{access_token}&expires=5008"
|
191
217
|
|
192
218
|
mock_response = stub(:body => api_response)
|
193
219
|
@mock_connection.expects(:use_ssl=).with(true)
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 2
|
9
|
+
version: 0.3.2
|
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-
|
17
|
+
date: 2010-07-22 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|