New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the requirement to authenticate before calling a service object #112

Merged
merged 1 commit into from Sep 5, 2014
File filter...
Filter file types
Jump to file or symbol
Failed to load files and symbols.
+18 −13
Diff settings

Always

Just for now

Copy path View file
@@ -21,9 +21,17 @@ def initialize
end

class SessionDataNotProvidedError < StandardError
def initialize
super "default_session_data is not initialized and no session data was "\
"provided in the method call."
def initialize(service_name, request_name)
super "\n\nERROR: default_session_data is not initialized and no session data was provided in\n"\
"the method call. You have two ways to fix this:\n\n"\
" 1) Call Session#authenticate before calling Session##{service_name}_service, or\n\n"\
" 2) If you're really sure you don't want to authenticate beforehand,\n"\
" construct the method call this way:\n\n"\
" service = session.#{service_name}_service\n"\
" service.request :#{request_name}, :api_version => :v2, :session_data => sessiondatavar\n\n"\
" Replace :v2 with whatever available version you want to use and make sure sessiondatavar\n"\
" is a hash that contains, at least, the :base_url key. Other keys, such as :service_token may\n"\
" be needed depending on what the request class you are calling requires.\n\n"
end
end

@@ -75,7 +83,7 @@ def request(request_name, options={}, &params)

session_data = options[:session_data] || default_session_data

raise SessionDataNotProvidedError.new unless session_data
raise SessionDataNotProvidedError.new(@service, request_name) unless session_data

[:base_url].each do |k|
session_data[k] = options[k] if options[k]
Copy path View file
@@ -152,8 +152,6 @@ def environment


def get_service_obj(service_name)
raise NotAuthenticatedError.new unless self.authenticated?

@services ||= {}

if @services[service_name].nil?
@@ -261,20 +261,19 @@ def new_session

describe '#xxx_service' do

it 'raises a NotAuthenticatedError if called without authenticating first' do
the_method = lambda { new_session.identity_service }

the_method.must_raise Aviator::Session::NotAuthenticatedError
end


it 'returns an instance of the indicated service' do
session = new_session
session.authenticate

session.identity_service.wont_be_nil
end

it 'returns an instance of the indicated service even if not authenticated' do
session = new_session
session.compute_service.wont_be_nil
session.authenticated?.must_equal false
end

end

end # describe 'aviator/core/service'
ProTip! Use n and p to navigate between commits in a pull request.