lib/metrika/helpers/authorization.rb in metrika-0.1.1 vs lib/metrika/helpers/authorization.rb in metrika-0.1.2

- old
+ new

@@ -1,31 +1,35 @@ module Metrika module Helpers module Authorization - attr_reader :token - DEFAULT_OAUTH_OPTIONS = { :site => 'http://api-metrika.yandex.ru', :authorize_url => 'https://oauth.yandex.ru/authorize', :token_url => 'https://oauth.yandex.ru/token' } - def authorize_token(authorization_code) - @token = (self.client.auth_code.get_token(authorization_code) rescue nil) + def authorize_token(auth_code) + @token = (self.client.auth_code.get_token(auth_code) rescue nil) end def authorization_url self.client.auth_code.authorize_url end - def restore_token(token_code) - @token = OAuth2::AccessToken.new(self.client, token_code) + def restore_token(access_token) + @token = OAuth2::AccessToken.new(self.client, access_token) end protected def client - @client ||= OAuth2::Client.new(@application_id, @application_password, DEFAULT_OAUTH_OPTIONS) + @client ||= OAuth2::Client.new(@application_id, @application_password, DEFAULT_OAUTH_OPTIONS.dup) + end + + def token + raise Metrika::Errors::UnauthorizedError.new("Access token is not initialized") if @token.nil? + + @token end end end end \ No newline at end of file