class SwaggerClient::Swagger::Response
Attributes
raw[RW]
Public Class Methods
new(raw)
click to toggle source
# File lib/swagger_client/swagger/response.rb, line 8 def initialize(raw) self.raw = raw case self.code when 500..510 then raise(ServerError, self.error_message) when 299..426 then raise(ClientError, self.error_message) end end
Public Instance Methods
body()
click to toggle source
If body is JSON, parse it Otherwise return raw string
# File lib/swagger_client/swagger/response.rb, line 30 def body JSON.parse(raw.body, :symbolize_names => true) rescue raw.body end
code()
click to toggle source
# File lib/swagger_client/swagger/response.rb, line 17 def code raw.code end
error_message()
click to toggle source
Account for error messages that take different forms…
# File lib/swagger_client/swagger/response.rb, line 22 def error_message body['message'] rescue body end
format()
click to toggle source
Extract the response format from the header hash e.g. {‘Content-Type’ => ‘application/json’}
# File lib/swagger_client/swagger/response.rb, line 46 def format headers['Content-Type'].split("/").last.downcase end
headers()
click to toggle source
json?()
click to toggle source
# File lib/swagger_client/swagger/response.rb, line 50 def json? format == 'json' end
pretty_body()
click to toggle source
# File lib/swagger_client/swagger/response.rb, line 58 def pretty_body return unless body.present? case format when 'json' then JSON.pretty_generate(body).gsub(/\n/, '<br/>') end end
pretty_headers()
click to toggle source
# File lib/swagger_client/swagger/response.rb, line 65 def pretty_headers JSON.pretty_generate(headers).gsub(/\n/, '<br/>') end
xml?()
click to toggle source
# File lib/swagger_client/swagger/response.rb, line 54 def xml? format == 'xml' end