Skip to content
Browse files

Since Facebook will in the future require access tokens with all API …

…requests, prepping that code.
  • Loading branch information...
1 parent 2171c86 commit f242bcfbd8654f31315983ef986686062a7e6155 @arsduo committed
View
2 lib/koala.rb
@@ -33,7 +33,7 @@ module Facebook
class API
# initialize with an access token
- def initialize(access_token = nil)
+ def initialize(access_token)
@access_token = access_token
end
attr_reader :access_token
View
23 spec/cases/api_base_spec.rb
@@ -2,13 +2,14 @@
describe "Koala::Facebook::API" do
before(:each) do
- @service = Koala::Facebook::API.new
+ @token = "adfadf"
+ @service = Koala::Facebook::API.new(@token)
end
- it "should not include an access token if none was given" do
+ it "includes an access token in requests" do
Koala.should_receive(:make_request).with(
anything,
- hash_not_including('access_token' => 1),
+ hash_including('access_token' => @token),
anything,
anything
).and_return(Koala::Response.new(200, "", ""))
@@ -16,21 +17,7 @@
@service.api('anything')
end
- it "should include an access token if given" do
- token = 'adfadf'
- service = Koala::Facebook::API.new token
-
- Koala.should_receive(:make_request).with(
- anything,
- hash_including('access_token' => token),
- anything,
- anything
- ).and_return(Koala::Response.new(200, "", ""))
-
- service.api('anything')
- end
-
- it "should have an attr_reader for access token" do
+ it "has an attr_reader for access token" do
token = 'adfadf'
service = Koala::Facebook::API.new token
service.access_token.should == token
View
15 spec/cases/graph_and_rest_api_spec.rb
@@ -7,23 +7,8 @@
end
it_should_behave_like "Koala RestAPI"
- it_should_behave_like "Koala RestAPI with an access token"
it_should_behave_like "Koala GraphAPI"
- it_should_behave_like "Koala GraphAPI with an access token"
- it_should_behave_like "Koala GraphAPI with GraphCollection"
- end
-
- describe "without an access token" do
- before(:each) do
- @api = Koala::Facebook::GraphAndRestAPI.new
- end
-
- it_should_behave_like "Koala RestAPI"
- it_should_behave_like "Koala RestAPI without an access token"
-
- it_should_behave_like "Koala GraphAPI"
- it_should_behave_like "Koala GraphAPI without an access token"
it_should_behave_like "Koala GraphAPI with GraphCollection"
end
end
View
11 spec/cases/graph_api_spec.rb
@@ -7,17 +7,6 @@
end
it_should_behave_like "Koala GraphAPI"
- it_should_behave_like "Koala GraphAPI with an access token"
- it_should_behave_like "Koala GraphAPI with GraphCollection"
- end
-
- context "without an access token" do
- before :each do
- @api = Koala::Facebook::GraphAPI.new
- end
-
- it_should_behave_like "Koala GraphAPI"
- it_should_behave_like "Koala GraphAPI without an access token"
it_should_behave_like "Koala GraphAPI with GraphCollection"
end
end
View
12 spec/cases/rest_api_spec.rb
@@ -1,23 +1,13 @@
require 'spec_helper'
describe "Koala::Facebook::RestAPI" do
-
- context "without an access token" do
- before :each do
- @api = Koala::Facebook::RestAPI.new
- end
-
- it_should_behave_like "Koala RestAPI"
- it_should_behave_like "Koala RestAPI without an access token"
- end
-
+
context "with an access token" do
before :each do
@api = Koala::Facebook::RestAPI.new(@token)
end
it_should_behave_like "Koala RestAPI"
- it_should_behave_like "Koala RestAPI with an access token"
end
end
View
61 spec/support/graph_api_shared_examples.rb
@@ -102,10 +102,8 @@
@api.should_receive(:graph_call).with(*query)
@api.get_page(query)
end
-end
-
-shared_examples_for "Koala GraphAPI with an access token" do
+ # Access token tests
it "should get private data about a user" do
result = @api.get_object(KoalaTest.user1)
# updated_time should be a pretty fixed test case
@@ -121,6 +119,7 @@
result = @api.get_objects([KoalaTest.page, KoalaTest.user1])
result.length.should == 2
end
+
it "should be able to access connections from users" do
result = @api.get_connections(KoalaTest.user2, "likes")
result.length.should > 0
@@ -410,7 +409,7 @@
describe "when parsing page paramters" do
before(:each) do
- @graph_collection = Koala::Facebook::GraphCollection.new({"data" => []}, Koala::Facebook::GraphAPI.new)
+ @graph_collection = Koala::Facebook::GraphCollection.new({"data" => []}, Koala::Facebook::GraphAPI.new("bar"))
end
it "should return the base as the first array entry" do
@@ -425,56 +424,4 @@
end
end
end
-end
-
-
-shared_examples_for "Koala GraphAPI without an access token" do
-
- it "should not get private data about a user" do
- result = @api.get_object("koppel")
- # updated_time should be a pretty fixed test case
- result["updated_time"].should be_nil
- end
-
- it "should not be able to get data about 'me'" do
- lambda { @api.get_object("me") }.should raise_error(Koala::Facebook::APIError)
- end
-
- it "shouldn't be able to access connections from users" do
- lambda { @api.get_connections("lukeshepard", "likes") }.should raise_error(Koala::Facebook::APIError)
- end
-
- it "should not be able to put an object" do
- lambda { @result = @api.put_object("lukeshepard", "feed", :message => "Hello, world") }.should raise_error(Koala::Facebook::APIError)
- puts "Error! Object #{@result.inspect} somehow put onto Luke Shepard's wall!" if @result
- end
-
- # these are not strictly necessary as the other put methods resolve to put_object, but are here for completeness
- it "should not be able to post to a feed" do
- (lambda do
- attachment = {:name => "OAuth Playground", :link => "http://oauth.twoalex.com/"}
- @result = @api.put_wall_post("Hello, world", attachment, "contextoptional")
- end).should raise_error(Koala::Facebook::APIError)
- puts "Error! Object #{@result.inspect} somehow put onto Context Optional's wall!" if @result
- end
-
- it "should not be able to comment on an object" do
- # random public post on the ContextOptional wall
- lambda { @result = @api.put_comment("7204941866_119776748033392", "The hackathon was great!") }.should raise_error(Koala::Facebook::APIError)
- puts "Error! Object #{@result.inspect} somehow commented on post 7204941866_119776748033392!" if @result
- end
-
- it "should not be able to like an object" do
- lambda { @api.put_like("7204941866_119776748033392") }.should raise_error(Koala::Facebook::APIError)
- end
-
- # DELETE
- it "should not be able to delete posts" do
- # test post on the Ruby SDK Test application
- lambda { @result = @api.delete_object("115349521819193_113815981982767") }.should raise_error(Koala::Facebook::APIError)
- end
-
- it "should not be able to delete a like" do
- lambda { @api.delete_like("7204941866_119776748033392") }.should raise_error(Koala::Facebook::APIError)
- end
-end
+end
View
39 spec/support/rest_api_shared_examples.rb
@@ -199,9 +199,7 @@
end
end
end
-end
-shared_examples_for "Koala RestAPI with an access token" do
# FQL
it "should be able to access public information via FQL" do
result = @api.fql_query('select first_name from user where uid = 216743')
@@ -245,41 +243,4 @@
result.size.should == 3
result.keys.should include("query1", "query2", "query3")
end
-
-end
-
-
-shared_examples_for "Koala RestAPI without an access token" do
- # FQL_QUERY
- describe "when making a FQL request" do
- it "should be able to access public information via FQL" do
- @result = @api.fql_query("select first_name from user where uid = 216743")
- @result.size.should == 1
- @result.first["first_name"].should == "Chris"
- end
-
- it "should be able to access public information via FQL.multiquery" do
- result = @api.fql_multiquery(
- :query1 => 'select first_name from user where uid = 216743',
- :query2 => 'select first_name from user where uid = 2905623'
- )
- result.size.should == 2
- result["query1"].first['first_name'].should == 'Chris'
- result["query2"].first['first_name'].should == 'Alex'
- end
-
- it "should not be able to access protected information via FQL" do
- lambda { @api.fql_query("select read_stream from permissions where uid = 216743") }.should raise_error(Koala::Facebook::APIError)
- end
-
- it "should not be able to access protected information via FQL.multiquery" do
- lambda {
- @api.fql_multiquery(
- :query1 => "select post_id from stream where source_id = me()",
- :query2 => "select fromid from comment where post_id in (select post_id from #query1)",
- :query3 => "select uid, name from user where uid in (select fromid from #query2)"
- )
- }.should raise_error(Koala::Facebook::APIError)
- end
- end
end

0 comments on commit f242bcf

Please sign in to comment.
Something went wrong with that request. Please try again.