Skip to content

Commit

Permalink
Adds return url to configuration to make it easier to config.
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Coutu authored and Julian Coutu committed Mar 21, 2011
1 parent c229acb commit 201bf49
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/contacts/oauth_consumer.rb
Expand Up @@ -4,6 +4,7 @@ module Contacts
class OAuthConsumer < Consumer
configuration_attribute :consumer_key
configuration_attribute :consumer_secret
configuration_attribute :return_url

def initialize(consumer_options, request_token_params)
@consumer_options = consumer_options
Expand All @@ -27,7 +28,7 @@ def serializable_data
attr_accessor :request_token
attr_accessor :access_token

def authentication_url(target)
def authentication_url(target = self.return_url)
@request_token = consumer.get_request_token({:oauth_callback => target}, @request_token_params)
@request_token.authorize_url
end
Expand Down
3 changes: 2 additions & 1 deletion lib/contacts/windows_live.rb
Expand Up @@ -6,6 +6,7 @@ class WindowsLive < Consumer
configuration_attribute :application_id
configuration_attribute :secret_key
configuration_attribute :privacy_policy_url
configuration_attribute :return_url

#
# If this is set, then #authentication_url will force the given
Expand Down Expand Up @@ -69,7 +70,7 @@ def serializable_data
data
end

def authentication_url(target, options={})
def authentication_url(target=self.return_url, options={})
if force_origin
context = target
target = force_origin + URI.parse(target).path
Expand Down
8 changes: 5 additions & 3 deletions spec/config/contacts.yml
Expand Up @@ -3,11 +3,13 @@ test:
application_id: app_id
secret_key: your_secret
privacy_policy_url: http://yourserver.com/you_policy_url

return_url: 'http://phaseiii.mine.nu:3000/friends/load_contacts'
yahoo:
consumer_key: your_key
consumer_secret: your_secret_key

return_url: 'http://phaseiii.mine.nu:3000/friends/load_contacts'
google:
consumer_key: your_key
consumer_secret: your_secret_key
consumer_secret: your_secret_key
return_url: 'http://phaseiii.mine.nu:3000/friends/load_contacts'

10 changes: 10 additions & 0 deletions spec/gmail/google_spec.rb
Expand Up @@ -9,11 +9,21 @@
@google = Contacts::Google.new
fake_responses
end

context "return_url" do
it "should allow the return url to be set in the config" do
@google.return_url.should_not == nil
end
end

context "authentication_url" do
it "should return an authentication url" do
@google.authentication_url("http://browser.zen.turingstudio.com/test").length.should_not == 0
end

it "should return the return url from configuration if the return url is not set" do
@google.authentication_url().length.should_not == 0
end
end

context "authorize" do
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Expand Up @@ -8,7 +8,7 @@
def fake_responses
FakeWeb.register_uri(:post, 'https://www.google.com/accounts/OAuthGetRequestToken', :body => 'oauth_token=faketoken&oauth_token_secret=faketokensecret')
FakeWeb.register_uri(:post, 'https://www.google.com/accounts/OAuthGetAccessToken', :body => 'oauth_token=fake&oauth_token_secret=fake')
FakeWeb.register_uri(:get, 'http://www.google.com/m8/feeds/contacts/default/thin?max-results=200', :body => feeds('google-many.xml'))
FakeWeb.register_uri(:get, 'https://www.google.com/m8/feeds/contacts/default/thin?max-results=200', :body => feeds('google-many.xml'))
FakeWeb.register_uri(:post, 'https://api.login.yahoo.com/oauth/v2/get_request_token', :body => 'oauth_token=faketoken&oauth_token_secret=faketokensecret')
FakeWeb.register_uri(:post, 'https://api.login.yahoo.com/oauth/v2/get_token', :body => 'oauth_token=fake&oauth_token_secret=fake&xoauth_yahoo_guid=tester')
FakeWeb.register_uri(:get, 'http://social.yahooapis.com/v1/user/tester/contacts?count=200&sort=asc&sort-fields=email&format=json', :body => feeds('yh_contacts.txt'))
Expand Down
17 changes: 17 additions & 0 deletions spec/windows_live/windows_live_spec.rb
Expand Up @@ -11,6 +11,18 @@
@wl.token_expires_at = Time.now+1
end


context "return_url" do
it "should allow the return url to be set in the config" do
@wl.return_url.should_not == nil
end

it "should return the return url from configuration if the return url is not set" do
@wl.authentication_url().length.should_not == 0
end

end

context "authentication_url" do
it "should return an authentication url" do
@wl.authentication_url("http://browser.zen.turingstudio.com/test").length.should_not == 0
Expand All @@ -23,5 +35,10 @@
contacts.should_not == nil
contacts.length.should == 3
end

it "should contain a single name which is a join of the first and last name fields" do
contacts = @wl.contacts
contacts[1].name.should == "Rafael Timbo"
end
end
end
10 changes: 10 additions & 0 deletions spec/yahoo/yahoo_spec.rb
Expand Up @@ -9,10 +9,20 @@
fake_responses
end

context "return_url" do
it "should allow the return url to be set in the config" do
@yahoo.return_url.should_not == nil
end
end

context "authentication_url" do
it "should return an authentication url" do
@yahoo.authentication_url("http://browser.zen.turingstudio.com/test").length.should_not == 0
end

it "should return the return url from configuration if the return url is not set" do
@yahoo.authentication_url().length.should_not == 0
end
end

context "authorize" do
Expand Down

0 comments on commit 201bf49

Please sign in to comment.