Class: DiandianOAuth::Response
- Inherits:
-
Object
- Object
- DiandianOAuth::Response
- Defined in:
- lib/diandian_oauth/models/response.rb
Instance Attribute Summary collapse
-
#error ⇒ Object
Returns the value of attribute error.
-
#internal ⇒ Object
Returns the value of attribute internal.
-
#meta ⇒ Object
Returns the value of attribute meta.
-
#response ⇒ Object
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
- #validate ⇒ Object (also: #success?)
-
#validate! ⇒ Object
throw exception when an error occurs.
Instance Attribute Details
#error ⇒ Object
Returns the value of attribute error.
3 4 5 |
# File 'lib/diandian_oauth/models/response.rb', line 3 def error @error end |
#internal ⇒ Object
Returns the value of attribute internal.
3 4 5 |
# File 'lib/diandian_oauth/models/response.rb', line 3 def internal @internal end |
#meta ⇒ Object
Returns the value of attribute meta.
3 4 5 |
# File 'lib/diandian_oauth/models/response.rb', line 3 def @meta end |
#response ⇒ Object
Returns the value of attribute response.
3 4 5 |
# File 'lib/diandian_oauth/models/response.rb', line 3 def response @response end |
Class Method Details
.from_response(response) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/diandian_oauth/models/response.rb', line 4 def self.from_response response response_json = response.parsed result = Response.new result.internal = response result.error = response_json['error'] return result if result.error result. = response_json['meta'] result.response = response_json['response'] result end |
Instance Method Details
#validate ⇒ Object Also known as: success?
15 16 17 |
# File 'lib/diandian_oauth/models/response.rb', line 15 def validate !error && ['status'] == 200 end |
#validate! ⇒ Object
throw exception when an error occurs
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/diandian_oauth/models/response.rb', line 21 def validate! puts "error: '#{self.inspect}'" unless self.validate if error exception = case error[:error] when 'invalid_request' then DiandianOAuth::InvalidateRequestError when 'unauthorized_client' then DiandianOAuth::UnauthorizedClientError when 'access_denied' then DiandianOAuth::AccessDeniedError when 'unsupported_response_type' then DiandianOAuth::UnsupportedResponseTypeError when 'invalid_scope' then DiandianOAuth::InvalidScopeError when 'server_error' then DiandianOAuth::ServerError else APIError end raise exception else exception = case [:status] when 400000 then DiandianOAuth::ClientError when 400001 then DiandianOAuth::ParameterError when 400010 then DiandianOAuth::EmailError when 400011 then DiandianOAuth::PasswordError when 400012 then DiandianOAuth::EccentricAccountError when 400013 then DiandianOAuth::EmailFormatError when 400014 then DiandianOAuth::PasswordFormatError when 400015 then DiandianOAuth::EmailExistsError when 400020 then DiandianOAuth::BindingFailError when 400030 then DiandianOAuth::FollowError when 400031 then DiandianOAuth::UnfollowError when 400040 then DiandianOAuth::IllegalContentError when 400050 then DiandianOAuth::InboxContentCannotBeEmptyError when 400051 then DiandianOAuth::InboxContentTooLongError when 400052 then DiandianOAuth::InboxClosedError when 400053 then DiandianOAuth::CannotSendToOwnBlogError when 400060 then DiandianOAuth::OperationTooFastError when 400070 then DiandianOAuth::BlogClosedError when 400080 then DiandianOAuth::VerifyCodeExpiredError when 400081 then DiandianOAuth::VerifyCodeWrongError when 401000 then DiandianOAuth::UnauthorizedError when 403000 then DiandianOAuth::VisitForbiddenError when 403001 then DiandianOAuth::BlogManagerRequiredError when 404002 then DiandianOAuth::BlogNotFoundError when 404003 then DiandianOAuth::ContentNotFoundError when 404004 then DiandianOAuth::UserNotFoundError when 500000 then DiandianOAuth::InternalServerError when 500001 then DiandianOAuth::PostTypeError when 500002 then DiandianOAuth::InboxError when 503001 then DiandianOAuth::UpgradingError else DiandianOAuth::APIError end raise exception end end end |