Browse files

Added the ability to pass a scope to configuration for use when autho…

…rizing
  • Loading branch information...
1 parent c3ccbd0 commit 03ba5e7277fa4a56cfad25d6e9a87802609d5af6 @dentafrice dentafrice committed Mar 2, 2013
Showing with 25 additions and 0 deletions.
  1. +5 −0 lib/instagram/configuration.rb
  2. +1 −0 lib/instagram/oauth.rb
  3. +19 −0 spec/instagram/api_spec.rb
View
5 lib/instagram/configuration.rb
@@ -9,6 +9,7 @@ module Configuration
:adapter,
:client_id,
:client_secret,
+ :scope,
:access_token,
:endpoint,
:format,
@@ -39,6 +40,9 @@ module Configuration
# By default, don't set a user access token
DEFAULT_ACCESS_TOKEN = nil
+ # By default, don't set a user scope
+ DEFAULT_SCOPE = nil
+
# The endpoint that will be used to connect if none is set
#
# @note There is no reason to use any other endpoint at this time
@@ -80,6 +84,7 @@ def reset
self.adapter = DEFAULT_ADAPTER
self.client_id = DEFAULT_CLIENT_ID
self.client_secret = DEFAULT_CLIENT_SECRET
+ self.scope = DEFAULT_SCOPE
self.access_token = DEFAULT_ACCESS_TOKEN
self.endpoint = DEFAULT_ENDPOINT
self.format = DEFAULT_FORMAT
View
1 lib/instagram/oauth.rb
@@ -4,6 +4,7 @@ module OAuth
# Return URL for OAuth authorization
def authorize_url(options={})
options[:response_type] ||= "code"
+ options[:scope] ||= scope if !scope.nil? && !scope.empty?
params = authorization_params.merge(options)
connection.build_url("/oauth/authorize/", params).to_s
end
View
19 spec/instagram/api_spec.rb
@@ -32,6 +32,7 @@
@configuration = {
:client_id => 'CID',
:client_secret => 'CS',
+ :scope => 'comments relationships',
:access_token => 'AT',
:adapter => :typhoeus,
:endpoint => 'http://tumblr.com/',
@@ -93,6 +94,24 @@
url = client.authorize_url(:redirect_uri => redirect_uri)
url.should_not include("client_secret")
end
+
+ describe "scope param" do
+ it "should include the scope if there is one set" do
+ params = { :scope => "comments likes" }
+ client = Instagram::Client.new(params)
+ redirect_uri = 'http://localhost:4567/oauth/callback'
+ url = client.authorize_url(:redirect_uri => redirect_uri)
+ url.should include("scope")
+ end
+
+ it "should not include the scope if the scope is blank" do
+ params = { :scope => "" }
+ client = Instagram::Client.new(params)
+ redirect_uri = 'http://localhost:4567/oauth/callback'
+ url = client.authorize_url(:redirect_uri => redirect_uri)
+ url.should_not include("scope")
+ end
+ end
end
describe ".get_access_token" do

0 comments on commit 03ba5e7

Please sign in to comment.