-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove GraphNode (replaced by GraphResponse); wholesale changes and b…
…ig feature-adds to GraphResponse
- Loading branch information
Showing
5 changed files
with
177 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# AWEXOME LABS | ||
# DoesOpenGraph | ||
# | ||
# GraphRequest - A request to the OpenGraph API. | ||
# | ||
|
||
module DoesOpenGraph | ||
class GraphRequest | ||
|
||
attr_reader :api, :method, :path, :params | ||
|
||
# Build a Request object from its component parts | ||
def initialize(api, method, path, params={}) | ||
@api = api | ||
@method = method | ||
@path = path | ||
@params = params | ||
end | ||
|
||
|
||
# Perform the request | ||
def request | ||
base = @api.access_token ? GraphAPI::HTTPS_GRAPH_ENDPOINT : GraphAPI::HTTP_GRAPH_ENDPOINT | ||
href = File.join(base, @path) | ||
|
||
if !%w(get post delete).include?(@method.to_s) | ||
raise InvalidRequestMethod.new("Invalid HTTP method #{@method} passed to request") and return nil | ||
end | ||
|
||
params[:access_token] = @api.access_token if @api.access_token | ||
|
||
begin | ||
response = Typhoeus::Request.send(@method, href, :params=>@params) | ||
puts "RESPONSE RECEIVED FROM FACEBOOK ON REQUEST TO PATH #{@path}:\n#{response.body}\n\n" | ||
|
||
return GraphResponse.new(response.body, self) | ||
|
||
# TODO: Parse known error responses from Facebook, such as: | ||
# TODO: {"error":{"message":"Unknown path components: \/status","type":"OAuthException"}} | ||
|
||
rescue Exception => e | ||
raise OpenGraphException.new("Error in OpenGraph response: #{e}") and return nil | ||
end | ||
end | ||
|
||
|
||
# Repeat the same request with optionally different parameters | ||
def repeat(params={}) | ||
@params.merge(params) | ||
request() | ||
end | ||
|
||
|
||
end # GraphRequest | ||
end # DoesOpenGraph | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters