class JPush::Http::Response

Attributes

body[RW]
heades[RW]
http_code[RW]

Public Class Methods

new(raw_response) click to toggle source
# File lib/jpush/http/response.rb, line 7
def initialize(raw_response)
  @http_code = raw_response.code.to_i
  @body = parse_body(raw_response.body)
  build_error unless raw_response.kind_of? Net::HTTPSuccess
end

Private Instance Methods

build_error() click to toggle source
# File lib/jpush/http/response.rb, line 21
def build_error
  error_code, error_message =
    if @body.has_key?('error')
      [@body['error']['code'], @body['error']['message']]
    else
      [@body['code'], @body['message']]
    end
  raise Utils::Exceptions::JPushResponseError.new(http_code, error_code, error_message)
end
parse_body(body) click to toggle source
# File lib/jpush/http/response.rb, line 15
def parse_body(body)
  body = JSON.parse(body)
rescue JSON::ParserError
  raise Utils::Exceptions::JPushResponseError.new(http_code, http_code, body)
end