Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Adopted the name Koala; fixed bug with infinite sessions (thanks, san…
…dervdv!). Updated readme, tests, etc. First version, ready to release!
  • Loading branch information
arsduo committed May 1, 2010
1 parent cebe42b commit f4427ee
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 81 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
@@ -1,3 +1,8 @@
v0.4.0
-- Adopted the Koala name
-- Updated readme and tests
-- Fixed cookie verification bug for non-expiring OAuth tokens

v0.3.1
-- Bug fixes.

Expand Down
23 changes: 5 additions & 18 deletions Manifest
Expand Up @@ -2,24 +2,11 @@ CHANGELOG
Manifest
Rakefile
init.rb
lib/facebook_graph.rb
koala.gemspec
lib/http_services.rb
pkg/facebook_graph-0.3.0.gem
pkg/facebook_graph-0.3.0.tar.gz
pkg/facebook_graph-0.3.0/CHANGELOG
pkg/facebook_graph-0.3.0/Manifest
pkg/facebook_graph-0.3.0/Rakefile
pkg/facebook_graph-0.3.0/facebook_graph.gemspec
pkg/facebook_graph-0.3.0/init.rb
pkg/facebook_graph-0.3.0/lib/facebook_graph.rb
pkg/facebook_graph-0.3.0/lib/http_services.rb
pkg/facebook_graph-0.3.0/readme.md
pkg/facebook_graph-0.3.0/test/facebook_data.yml
pkg/facebook_graph-0.3.0/test/facebook_graph/facebook_no_access_token_tests.rb
pkg/facebook_graph-0.3.0/test/facebook_graph/facebook_with_access_token_tests.rb
pkg/facebook_graph-0.3.0/test/facebook_tests.rb
lib/koala.rb
readme.md
test/facebook_data.yml
test/facebook_graph/facebook_no_access_token_tests.rb
test/facebook_graph/facebook_with_access_token_tests.rb
test/facebook_tests.rb
test/koala/facebook_no_access_token_tests.rb
test/koala/facebook_with_access_token_tests.rb
test/koala_tests.rb
4 changes: 2 additions & 2 deletions Rakefile
Expand Up @@ -4,9 +4,9 @@ require 'rake'
require 'echoe'

# gem management
Echoe.new('facebook_graph', '0.3.1') do |p|
Echoe.new('koala', '0.4') do |p|
p.summary = "A lightweight, flexible library for Facebook's new Graph API"
p.description = "A Ruby SDK that wraps Facebook's new Graph API. Allows read/write access to the API and provides cookie validation for Facebook Connect sites. Supports Net::HTTP and Typhoeus connections out of the box and accepts custom modules for other services."
p.description = "Koala is a lightweight, flexible Ruby SDK for Facebook's new Graph API. It allows read/write access to the Facebook Graph and provides OAuth URLs and cookie validation for Facebook Connect sites. Koala supports Net::HTTP and Typhoeus connections out of the box and can accept custom modules for other services."
p.url = "http://github.com/arsduo/ruby-sdk"
p.author = ["Alex Koppel", "Rafi Jacoby", "Context Optional"]
p.email = "alex@alexkoppel.com"
Expand Down
30 changes: 0 additions & 30 deletions facebook_graph.gemspec

This file was deleted.

4 changes: 2 additions & 2 deletions lib/http_services.rb
@@ -1,5 +1,5 @@
module FacebookGraph
class API
module Koala
class GraphAPI
module NetHTTPService
# this service uses Net::HTTP to send requests to the graph
def self.included(base)
Expand Down
16 changes: 8 additions & 8 deletions lib/facebook_graph.rb → lib/koala.rb
Expand Up @@ -8,7 +8,7 @@
# include default http services
require 'http_services'

module FacebookGraph
module Koala
# Ruby client library for the Facebook Platform.
# Copyright 2010 Facebook
# Adapted from the Python library by Alex Koppel, Rafi Jacoby, and the team at Context Optional
Expand All @@ -32,7 +32,7 @@ module FacebookGraph

FACEBOOK_GRAPH_SERVER = "graph.facebook.com"

class API
class GraphAPI
# A client for the Facebook Graph API.
#
# See http://developers.facebook.com/docs/api for complete documentation
Expand All @@ -45,7 +45,7 @@ class API
# token, this will fetch the profile of the active user and the list
# of the user's friends:
#
# graph = Facebook::GraphAPI.new(access_token)
# graph = Koala::GraphAPI.new(access_token)
# user = graph.get_object("me")
# friends = graph.get_connections(user["id"], "friends")
#
Expand All @@ -57,7 +57,7 @@ class API
# for details.
#
# If you are using the JavaScript SDK, you can use the
# Facebook::get_user_from_cookie() method below to get the OAuth access token
# Koala::OAuth.get_user_from_cookie() method below to get the OAuth access token
# for the active user from the cookie saved by the SDK.

# initialize with an access token
Expand Down Expand Up @@ -167,17 +167,17 @@ def request(path, args = {}, verb = "get")
end

# set up the http service used to make requests
# you can use your own (for HTTParty, etc.) by calling FacebookGraph::API.http_service = YourModule
# you can use your own (for HTTParty, etc.) by calling Koala::GraphAPI.http_service = YourModule
def self.http_service=(service)
self.send(:include, service)
end

# by default, try requiring Typhoeus -- if that works, use it
begin
require 'typhoeus'
FacebookGraph::API.http_service = TyphoeusService
Koala::GraphAPI.http_service = TyphoeusService
rescue LoadError
FacebookGraph::API.http_service = NetHTTPService
Koala::GraphAPI.http_service = NetHTTPService
end
end

Expand Down Expand Up @@ -222,7 +222,7 @@ def get_user_from_cookie(cookie_hash)
auth_string = components.keys.sort.collect {|a| a == "sig" ? nil : "#{a}=#{components[a]}"}.reject {|a| a.nil?}.join("")
sig = Digest::MD5.hexdigest(auth_string + @app_secret)

sig == components["sig"] && Time.now.to_i < components["expires"].to_i ? components : nil
sig == components["sig"] && (components["expires"].to_i == 0 || Time.now.to_i < components["expires"].to_i) ? components : nil
end
end

Expand Down
7 changes: 3 additions & 4 deletions readme.md
@@ -1,4 +1,4 @@
Facebook Graph
Koala
====

This Ruby client library is designed to support the
Expand All @@ -9,7 +9,7 @@ about the Graph API at [http://developers.facebook.com/docs/api](http://develope

Basic usage:

graph = Facebook::GraphAPI.new(oauth_access_token)
graph = Koala::GraphAPI.new(oauth_access_token)
profile = graph.get_object("me")
friends = graph.get_connections("me", "friends")
graph.put_object("me", "feed", :message => "I am writing on my wall!")
Expand All @@ -25,5 +25,4 @@ Testing
Unit tests are provided for Graph API methods. However, because the Graph API uses access tokens, which expire, you have to provide your own token with stream publishing permissions for the tests. Insert the token value into the file test/facebook_data.yml, then run the test as follows:
spec facebook_tests.rb

Unit tests for cookie validation will be provided shortly. (You'll also need to add that information into the yml.)

Unit tests for cookie validation and other methods in the OAuth class will be provided shortly. (You'll also need to add that information into the yml.)
@@ -1,7 +1,7 @@
class FacebookNoAccessTokenTests < Test::Unit::TestCase
describe "Facebook SDK without an access token" do
describe "Koala GraphAPI without an access token" do
before :each do
@graph = FacebookGraph::API.new
@graph = Koala::GraphAPI.new
end

it "should get public data about a user" do
Expand All @@ -26,7 +26,7 @@ class FacebookNoAccessTokenTests < Test::Unit::TestCase
it "should not be able to get data about 'me'" do
begin
@graph.get_object("me")
rescue FacebookGraph::GraphAPIError => @right_err
rescue Koala::GraphAPIError => @right_err
rescue Exception => wrong_err
end
@right_err.should_not be_nil
Expand All @@ -40,7 +40,7 @@ class FacebookNoAccessTokenTests < Test::Unit::TestCase
it "shouldn't be able to access connections from users" do
begin
@graph.get_connections("lukeshepard", "likes")
rescue FacebookGraph::GraphAPIError => @right_err
rescue Koala::GraphAPIError => @right_err
rescue Exception => wrong_err
end
@right_err.should_not be_nil
Expand All @@ -54,7 +54,7 @@ class FacebookNoAccessTokenTests < Test::Unit::TestCase
it "should not be able to put an object" do
begin
@result = @graph.put_object("lukeshepard", "feed", :message => "Hello, world")
rescue FacebookGraph::GraphAPIError => @right_err
rescue Koala::GraphAPIError => @right_err
rescue Exception => wrong_err
end
@right_err.should_not be_nil
Expand All @@ -64,7 +64,7 @@ class FacebookNoAccessTokenTests < Test::Unit::TestCase
it "should not be able to post to a feed" do
begin
@result = @graph.put_wall_post("Hello, world", {:name => "Context Optional", :link => "http://www.contextoptional.com/"}, "contextoptional")
rescue FacebookGraph::GraphAPIError => @right_err
rescue Koala::GraphAPIError => @right_err
rescue Exception => wrong_err
end
@right_err.should_not be_nil
Expand All @@ -74,7 +74,7 @@ class FacebookNoAccessTokenTests < Test::Unit::TestCase
begin
# random public post on the ContextOptional wall
@result = @graph.put_comment("7204941866_119776748033392", "The hackathon was great!")
rescue FacebookGraph::GraphAPIError => @right_err
rescue Koala::GraphAPIError => @right_err
rescue Exception => wrong_err
end
@right_err.should_not be_nil
Expand All @@ -83,7 +83,7 @@ class FacebookNoAccessTokenTests < Test::Unit::TestCase
it "should not be able to like an object" do
begin
@result = @graph.put_like("7204941866_119776748033392")
rescue FacebookGraph::GraphAPIError => @right_err
rescue Koala::GraphAPIError => @right_err
rescue Exception => wrong_err
end
@right_err.should_not be_nil
Expand All @@ -95,7 +95,7 @@ class FacebookNoAccessTokenTests < Test::Unit::TestCase
begin
# test post on the Ruby SDK Test application
@result = @graph.delete_object("115349521819193_113815981982767")
rescue FacebookGraph::GraphAPIError => @right_err
rescue Koala::GraphAPIError => @right_err
rescue Exception => wrong_err
end
@right_err.should_not be_nil
Expand Down
@@ -1,9 +1,9 @@
class FacebookWithAccessTokenTests < Test::Unit::TestCase
describe "Facebook SDK with an access token" do
describe "Koala GraphAPI with an access token" do
before :each do
token = $testing_data["oauth_token"]
raise Exception, "Must supply access token to run FacebookWithAccessTokenTests!" unless token
@graph = FacebookGraph::API.new(token)
@graph = Koala::GraphAPI.new(token)
end

after :each do
Expand Down
14 changes: 8 additions & 6 deletions test/facebook_tests.rb → test/koala_tests.rb
Expand Up @@ -2,9 +2,9 @@
require 'rubygems'
require 'spec/test/unit'

require '../lib/facebook_graph.rb'
require 'facebook_graph/facebook_no_access_token_tests'
require 'facebook_graph/facebook_with_access_token_tests'
require 'koala'
require 'koala/facebook_no_access_token_tests'
require 'koala/facebook_with_access_token_tests'

class FacebookTestSuite
def self.suite
Expand All @@ -24,6 +24,8 @@ def self.suite
unless $testing_data["oauth_token"]
puts "Access token tests will fail until you store a valid token in facebook_data.yml"
end
unless cookies = $testing_data["cookie_hash"]
puts "Cookie tests will fail until you store a valid token in facebook_data.yml"
end

# TODO finish tests for OAuth class
# unless $testing_data["cookie_hash"] && $testing_data["app_id"] && $testing_data["secret"]
# puts "Cookie tests will fail until you store valid data for the cookie hash, app_id, and app secret in facebook_data.yml"
# end

0 comments on commit f4427ee

Please sign in to comment.