Sha256: 7b50ce2aca95d92172ca5f4cc5579ddaf1d9d3bb91800cc2809bb6277a165bd3

Contents?: true

Size: 741 Bytes

Versions: 15

Compression:

Stored size: 741 Bytes

Contents

module Vzaar
  module Response
    class Base < Struct.new(:res)
      include Vzaar::Helper

      def body
        json? ? JSON.parse(res.body) : res.body
      end

      def content_type
        @content_type ||= res.content_type
      end

      def json?
        content_type == "application/json"
      end
    end

    def self.handle_response(response)
      case response.code.to_i
      when 302
        error("Moved Temporarily")
      when 401
        error("Protected Resource")
      when 403
        error("Forbidden")
      when 404
        error("Not Found")
      when 502
        error("Bad Gateway")
      else
        response
      end
    end

    def self.error(msg)
      raise(Vzaar::Error, msg)
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
vzaar-1.6.2 lib/vzaar/response/base.rb
vzaar-1.6.1 lib/vzaar/response/base.rb
vzaar-1.6.0 lib/vzaar/response/base.rb
vzaar-1.5.3 lib/vzaar/response/base.rb
vzaar-1.5.2 lib/vzaar/response/base.rb
vzaar-1.5.1 lib/vzaar/response/base.rb
vzaar-1.5.0 lib/vzaar/response/base.rb
vzaar-1.4.4 lib/vzaar/response/base.rb
vzaar-1.4.1 lib/vzaar/response/base.rb
vzaar-1.3.1 lib/vzaar/response/base.rb
vzaar-1.3.0 lib/vzaar/response/base.rb
vzaar-1.2.4 lib/vzaar/response/base.rb
vzaar-1.2.3 lib/vzaar/response/base.rb
vzaar-1.2.2 lib/vzaar/response/base.rb
vzaar-1.0.0 lib/vzaar/response/base.rb