Class: HyperGraph
- Inherits:
-
Object
- Object
- HyperGraph
- Defined in:
- lib/hyper_graph.rb
Overview
HyperGraph acts as a facade for the Facebook Graph API. It handles network calls and JSON response parsing.
Constant Summary collapse
- API_URL =
'graph.facebook.com'
Class Method Summary collapse
-
.authorize_url(client_id, redirect_uri, options = {}) ⇒ Object
Redirect users to this url to get authorization.
-
.delete(requested_object_id, options = {}) ⇒ Object
Send a delete request to the graph.
-
.get(requested_object_id, options = {}) ⇒ Object
Request an object from the social graph.
- .get_access_token(client_id, client_secret, redirect_uri, code) ⇒ Object
-
.post(requested_object_id, options = {}) ⇒ Object
Post an object to the graph.
Instance Method Summary collapse
- #delete(requested_object_id, options = {}) ⇒ Object
- #get(requested_object_id, options = {}) ⇒ Object
-
#initialize(access_token) ⇒ HyperGraph
constructor
Instance methods.
- #post(requested_object_id, options = {}) ⇒ Object
Constructor Details
#initialize(access_token) ⇒ HyperGraph
Instance methods
128 129 130 |
# File 'lib/hyper_graph.rb', line 128 def initialize(access_token) @access_token = access_token end |
Class Method Details
.authorize_url(client_id, redirect_uri, options = {}) ⇒ Object
Redirect users to this url to get authorization
48 49 50 |
# File 'lib/hyper_graph.rb', line 48 def (client_id, redirect_uri, ={}) "https://#{API_URL}/oauth/authorize?#{build_query(options.merge(:client_id => client_id, :redirect_uri => redirect_uri))}" end |
.delete(requested_object_id, options = {}) ⇒ Object
Send a delete request to the graph
43 44 45 |
# File 'lib/hyper_graph.rb', line 43 def delete(requested_object_id, = {}) post(requested_object_id, .merge(:method => 'delete')) end |
.get(requested_object_id, options = {}) ⇒ Object
Request an object from the social graph
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/hyper_graph.rb', line 17 def get(requested_object_id, = {}) http = initialize_http_connection request_path = "/#{requested_object_id}" query = build_query() request_path << "?#{query}" unless query=="" http_response = http.get(request_path) data = extract_data(JSON.parse(http_response.body)) normalize_response(data) end |
.get_access_token(client_id, client_secret, redirect_uri, code) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/hyper_graph.rb', line 52 def get_access_token(client_id, client_secret, redirect_uri, code) http = initialize_http_connection request_path = "/oauth/access_token" request_path << "?#{build_query(:client_id => client_id, :client_secret => client_secret, :redirect_uri => redirect_uri, :code => code)}" http_response = http.get(request_path) http_response.body.split('=')[1] end |
.post(requested_object_id, options = {}) ⇒ Object
Post an object to the graph
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/hyper_graph.rb', line 30 def post(requested_object_id, = {}) http = initialize_http_connection request_path = "/#{requested_object_id}" http_response = http.post(request_path, build_query()) if http_response.body=='true' return true else data = extract_data(JSON.parse(http_response.body)) return normalize_response(data) end end |
Instance Method Details
#delete(requested_object_id, options = {}) ⇒ Object
140 141 142 |
# File 'lib/hyper_graph.rb', line 140 def delete(requested_object_id, = {}) self.class.delete(requested_object_id, .merge(:access_token => @access_token)) end |
#get(requested_object_id, options = {}) ⇒ Object
132 133 134 |
# File 'lib/hyper_graph.rb', line 132 def get(requested_object_id, = {}) self.class.get(requested_object_id, .merge(:access_token => @access_token)) end |
#post(requested_object_id, options = {}) ⇒ Object
136 137 138 |
# File 'lib/hyper_graph.rb', line 136 def post(requested_object_id, = {}) self.class.post(requested_object_id, .merge(:access_token => @access_token)) end |