Class: Motion::OAuth2::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_response) ⇒ Response

Returns a new instance of Response.



6
7
8
# File 'lib/motion/oauth2/response.rb', line 6

def initialize(raw_response)
  self.raw_response = raw_response
end

Instance Attribute Details

#raw_responseObject

Returns the value of attribute raw_response.



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

def raw_response
  @raw_response
end

Instance Method Details

#bad_request?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/motion/oauth2/response.rb', line 30

def bad_request?
  status_code = 400
end

#bodyObject



54
55
56
# File 'lib/motion/oauth2/response.rb', line 54

def body
  raw_response.body.to_str
end

#client_error?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/motion/oauth2/response.rb', line 18

def client_error?
  (400..499).include? status_code
end

#errorObject



75
76
77
78
79
# File 'lib/motion/oauth2/response.rb', line 75

def error
  if error?
    Error.new body, raw_response.headers['WWW-Authenticate']
  end
end

#error?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/motion/oauth2/response.rb', line 26

def error?
  client_error? || server_error?
end

#forbidden?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/motion/oauth2/response.rb', line 38

def forbidden?
  status_code == 402
end

#jsonObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/motion/oauth2/response.rb', line 58

def json
  @json ||= case raw_response.headers['Content-Type']
  when /^application\/json/
    BubbleWrap::JSON.parse body
  when /^text\/javascript/
    # NOTE: FB Graph API uses text/javasctipt Content-Type for JSON response
    case body
    when /^(\[|\{)/
      BubbleWrap::JSON.parse body
    else
      body
    end
  else
    nil
  end
end

#json?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/motion/oauth2/response.rb', line 46

def json?
  !!json
end

#not_found?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/motion/oauth2/response.rb', line 42

def not_found?
  status_code == 400
end

#redirect?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/motion/oauth2/response.rb', line 14

def redirect?
  (300..399).include? status_code
end

#server_error?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/motion/oauth2/response.rb', line 22

def server_error?
  (500..599).include? status_code
end

#status_codeObject



50
51
52
# File 'lib/motion/oauth2/response.rb', line 50

def status_code
  raw_response.status_code
end

#success?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/motion/oauth2/response.rb', line 10

def success?
  (200..299).include? status_code
end

#unauthorized?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/motion/oauth2/response.rb', line 34

def unauthorized?
  status_code == 401
end