class Faraday::Response::StubHub

Public Instance Methods

call(environment) click to toggle source
# File lib/stub_hub_api/response.rb, line 37
def call(environment)
  @app.call(environment).on_complete do |env|
    check_status(env)
    env[:body] = parse_body(env[:body])
  end
end
check_status(env) click to toggle source
# File lib/stub_hub_api/response.rb, line 27
def check_status(env)
  status = env[:status].to_s
  body   = env[:body]
  if status =~ /^5/
    raise ApiException.new({status: status, body: body})
  elsif status =~ /^4/
    raise ApiException.new({status: status, body: body})
  end
end
parse_body(body) click to toggle source
# File lib/stub_hub_api/response.rb, line 19
def parse_body(body)
  if JSON.is_json?(body)
    JSON.parse(body)
  else
    Nokogiri::XML(body)
  end
end