Class: Motion::OAuth2::Error

Inherits:
Object
  • Object
show all
Defined in:
lib/motion/oauth2/error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, www_authenticate_header = nil) ⇒ Error

Returns a new instance of Error.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/motion/oauth2/error.rb', line 6

def initialize(body, www_authenticate_header = nil)
  self.raw = body
  self.www_authenticate = www_authenticate_header
  if oauth2_error?
    self.code = body['error'].to_sym
    self.description = body['description']
    self.url = body['error_url']
  else
    self.code = :unknown
  end
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



4
5
6
# File 'lib/motion/oauth2/error.rb', line 4

def code
  @code
end

#descriptionObject

Returns the value of attribute description.



4
5
6
# File 'lib/motion/oauth2/error.rb', line 4

def description
  @description
end

#rawObject

Returns the value of attribute raw.



4
5
6
# File 'lib/motion/oauth2/error.rb', line 4

def raw
  @raw
end

#urlObject

Returns the value of attribute url.



4
5
6
# File 'lib/motion/oauth2/error.rb', line 4

def url
  @url
end

#www_authenticateObject

Returns the value of attribute www_authenticate.



4
5
6
# File 'lib/motion/oauth2/error.rb', line 4

def www_authenticate
  @www_authenticate
end

Instance Method Details

#oauth2_error?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
# File 'lib/motion/oauth2/error.rb', line 18

def oauth2_error?
  @body.is_a?(Hash) &&
  [
    'invalid_request',
    'invalid_token',
    'insufficient_scope'
  ].include?(body[:error])
end