Class: Motion::OAuth2::Response
- Inherits:
-
Object
- Object
- Motion::OAuth2::Response
- Defined in:
- lib/motion/oauth2/response.rb
Instance Attribute Summary collapse
-
#raw_response ⇒ Object
Returns the value of attribute raw_response.
Instance Method Summary collapse
- #bad_request? ⇒ Boolean
- #body ⇒ Object
- #client_error? ⇒ Boolean
- #error ⇒ Object
- #error? ⇒ Boolean
- #forbidden? ⇒ Boolean
-
#initialize(raw_response) ⇒ Response
constructor
A new instance of Response.
- #json ⇒ Object
- #json? ⇒ Boolean
- #not_found? ⇒ Boolean
- #redirect? ⇒ Boolean
- #server_error? ⇒ Boolean
- #status_code ⇒ Object
- #success? ⇒ Boolean
- #unauthorized? ⇒ Boolean
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_response ⇒ Object
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
30 31 32 |
# File 'lib/motion/oauth2/response.rb', line 30 def bad_request? status_code = 400 end |
#body ⇒ Object
54 55 56 |
# File 'lib/motion/oauth2/response.rb', line 54 def body raw_response.body.to_str end |
#client_error? ⇒ Boolean
18 19 20 |
# File 'lib/motion/oauth2/response.rb', line 18 def client_error? (400..499).include? status_code end |
#error ⇒ Object
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
26 27 28 |
# File 'lib/motion/oauth2/response.rb', line 26 def error? client_error? || server_error? end |
#forbidden? ⇒ Boolean
38 39 40 |
# File 'lib/motion/oauth2/response.rb', line 38 def forbidden? status_code == 402 end |
#json ⇒ Object
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
46 47 48 |
# File 'lib/motion/oauth2/response.rb', line 46 def json? !!json end |
#not_found? ⇒ Boolean
42 43 44 |
# File 'lib/motion/oauth2/response.rb', line 42 def not_found? status_code == 400 end |
#redirect? ⇒ Boolean
14 15 16 |
# File 'lib/motion/oauth2/response.rb', line 14 def redirect? (300..399).include? status_code end |
#server_error? ⇒ Boolean
22 23 24 |
# File 'lib/motion/oauth2/response.rb', line 22 def server_error? (500..599).include? status_code end |
#status_code ⇒ Object
50 51 52 |
# File 'lib/motion/oauth2/response.rb', line 50 def status_code raw_response.status_code end |
#success? ⇒ Boolean
10 11 12 |
# File 'lib/motion/oauth2/response.rb', line 10 def success? (200..299).include? status_code end |
#unauthorized? ⇒ Boolean
34 35 36 |
# File 'lib/motion/oauth2/response.rb', line 34 def status_code == 401 end |