Permalink
Browse files

safer checks around auth_token parsing

  • Loading branch information...
theganyo committed Oct 11, 2012
1 parent 6e158cb commit 4dabd15cb3e9cabfe5e9a6cf82efc11ae2541324
Showing with 18 additions and 11 deletions.
  1. +18 −11 lib/usergrid/core/resource.rb
@@ -6,7 +6,7 @@ class Resource < RestClient::Resource
DEFAULT_API_URL = 'https://api.usergrid.com'
TYPE_HEADERS = { :content_type => :json, :accept => :json }
attr_reader :current_user, :auth_token, :api_url
attr_reader :current_user, :api_url
def initialize(resource_url=DEFAULT_API_URL, api_url=nil, options={}, response=nil)
options[:headers] = TYPE_HEADERS.merge options[:headers] || {}
@@ -34,7 +34,7 @@ def logout
end
def logged_in?
!!@auth_token
!!auth_token
end
def management
@@ -87,23 +87,30 @@ def put(payload, additional_headers={}, &block)
self.response = super payload, additional_headers, &block
end
protected
attr_reader :response
def response=(response)
@response = response
end
def auth_token=(auth_token)
@auth_token = auth_token
if auth_token
@options[:headers].merge!({ Authorization: "Bearer #{auth_token}" })
else
@options[:headers].delete :Authorization if @options
end
end
def auth_token
begin
@options[:headers][:Authorization].gsub 'Bearer ', ''
rescue
nil
end
end
protected
attr_reader :response
def response=(response)
@response = response
end
# add verbose debugging of response body
def handle_response(response, request, result, &block)
LOG.debug "response.body = #{response}"

0 comments on commit 4dabd15

Please sign in to comment.