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.
- #object(id) ⇒ Object
- #post(requested_object_id, options = {}) ⇒ Object
Constructor Details
#initialize(access_token) ⇒ HyperGraph
Instance methods
133 134 135 |
# File 'lib/hyper_graph.rb', line 133 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
49 50 51 |
# File 'lib/hyper_graph.rb', line 49 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
44 45 46 |
# File 'lib/hyper_graph.rb', line 44 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
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/hyper_graph.rb', line 18 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
53 54 55 56 57 58 59 |
# File 'lib/hyper_graph.rb', line 53 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
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/hyper_graph.rb', line 31 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
149 150 151 |
# File 'lib/hyper_graph.rb', line 149 def delete(requested_object_id, = {}) self.class.delete(requested_object_id, .merge(:access_token => @access_token)) end |
#get(requested_object_id, options = {}) ⇒ Object
141 142 143 |
# File 'lib/hyper_graph.rb', line 141 def get(requested_object_id, = {}) self.class.get(requested_object_id, .merge(:access_token => @access_token)) end |
#object(id) ⇒ Object
137 138 139 |
# File 'lib/hyper_graph.rb', line 137 def object(id) HyperGraphObject.new(self, id) end |
#post(requested_object_id, options = {}) ⇒ Object
145 146 147 |
# File 'lib/hyper_graph.rb', line 145 def post(requested_object_id, = {}) self.class.post(requested_object_id, .merge(:access_token => @access_token)) end |