class Songkick::Transport::Response
Attributes
body[R]
data[R]
headers[R]
status[R]
Public Class Methods
new(status, headers, body)
click to toggle source
# File lib/songkick/transport/response.rb, line 29 def initialize(status, headers, body) @body = body @data = Response.parse(body, headers['Content-Type']) @headers = Headers.new(headers) @status = status.to_i end
parse(body, content_type)
click to toggle source
# File lib/songkick/transport/response.rb, line 19 def self.parse(body, content_type) return body unless body.is_a?(String) return nil if body.strip == '' content_type = (content_type || '').split(/\s*;\s*/).first Transport.parser_for(content_type).parse(body) end
process(request, status, headers, body, user_error_codes=409)
click to toggle source
# File lib/songkick/transport/response.rb, line 5 def self.process(request, status, headers, body, user_error_codes=409) case status.to_i when 200 then OK.new(status, headers, body) when 201 then Created.new(status, headers, body) when 204 then NoContent.new(status, headers, body) when *user_error_codes then UserError.new(status, headers, body) else raise HttpError.new(request, status, headers, body) end rescue Yajl::ParseError Transport.logger.warn "Request returned invalid JSON: #{request}" raise Transport::InvalidJSONError, request end
Public Instance Methods
errors()
click to toggle source
# File lib/songkick/transport/response.rb, line 36 def errors data && data['errors'] end