Class: DiandianOAuth::ResponseMeta

Inherits:
Object
  • Object
show all
Defined in:
lib/diandian_oauth/models/response_meta.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#messageObject

Returns the value of attribute message.



3
4
5
# File 'lib/diandian_oauth/models/response_meta.rb', line 3

def message
  @message
end

#statusObject

Returns the value of attribute status.



3
4
5
# File 'lib/diandian_oauth/models/response_meta.rb', line 3

def status
  @status
end

Class Method Details

.from_response(response_json) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/diandian_oauth/models/response_meta.rb', line 4

def self.from_response response_json
  meta = response_json['meta']
  response_meta = ResponseMeta.new
  response_meta.status = meta['status']
  response_meta.message = meta['msg']
  response_meta
end

Instance Method Details

#success?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/diandian_oauth/models/response_meta.rb', line 12

def success?
  self.validate
end

#validateObject



16
17
18
# File 'lib/diandian_oauth/models/response_meta.rb', line 16

def validate
  self.status == 200
end

#validate!Object



20
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
# File 'lib/diandian_oauth/models/response_meta.rb', line 20

def validate!
  if !self.validate
    exception =
        case self.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, self.message
  end
  self
end