Sha256: 128e08d8fc180f09fdfca549ea35a2b0cb2f764822f96c610913ef38c3b2c2c8

Contents?: true

Size: 693 Bytes

Versions: 11

Compression:

Stored size: 693 Bytes

Contents

module GnipApi
  class Response
    # List of codes that are considered OK
    OK_STATUSES = [200, 201, 202, 203, 204, 205, 206, 207, 208, 226]

    attr_reader :body, :headers, :status, :request
    
    def initialize request, status, body, headers
      @status = status
      @body = body
      @headers = headers
      @request = request
    end

    def request_method
      @request.request_method
    end

    def request_uri
      @request.uri
    end

    def ok?
      OK_STATUSES.include? @status
    end

    def error_message
      if @body && !@body.empty?
        parsed = GnipApi::JsonParser.new.parse(@body)
        return parsed
      end
      return nil
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
gnip_api-1.1.3 lib/gnip_api/response.rb
gnip_api-1.1.2 lib/gnip_api/response.rb
gnip_api-1.1.1 lib/gnip_api/response.rb
gnip_api-1.1.0 lib/gnip_api/response.rb
gnip_api-1.0.6 lib/gnip_api/response.rb
gnip_api-1.0.5 lib/gnip_api/response.rb
gnip_api-1.0.4 lib/gnip_api/response.rb
gnip_api-1.0.3 lib/gnip_api/response.rb
gnip_api-1.0.2 lib/gnip_api/response.rb
gnip_api-1.0.1 lib/gnip_api/response.rb
gnip_api-1.0.0 lib/gnip_api/response.rb