Sha256: e8aebc2191b68f7b020810069efcf7257927fc86b09de3e883d00b593be6b001

Contents?: true

Size: 1.57 KB

Versions: 20

Compression:

Stored size: 1.57 KB

Contents

# encoding: utf-8

module Nimbu
  class Response

    # Represents http response header
    class Header < Struct.new(:env)
      include Nimbu::Utils::Constants

      SUCCESSFUL_STATUSES = 200..299

      def loaded?
        !!env
      end

      def oauth_scopes
        loaded? ? env[:response_headers][OAUTH_SCOPES] : nil
      end

      def accepted_oauth_scopes
        loaded? ? env[:response_headers][ACCEPTED_OAUTH_SCOPES] : nil
      end

      # Requests are limited to API v3 to 5000 per hour.
      def ratelimit_limit
        loaded? ? env[:response_headers][RATELIMIT_LIMIT] : nil
      end

      def ratelimit_remaining
        loaded? ? env[:response_headers][RATELIMIT_REMAINING] : nil
      end

      def cache_control
        loaded? ? env[:response_headers][CACHE_CONTROL] : nil
      end

      def content_type
        loaded? ? env[:response_headers][CONTENT_TYPE] : nil
      end

      def content_length
        loaded? ? env[:response_headers][CONTENT_LENGTH] : nil
      end

      def etag
        loaded? ? env[:response_headers][ETAG] : nil
      end

      def date
        loaded? ? env[:response_headers][DATE] : nil
      end

      def location
        loaded? ? env[:response_headers][LOCATION] : nil
      end

      def server
        loaded? ? env[:response_headers][SERVER] : nil
      end

      def status
        loaded? ? env[:status] : nil
      end

      def success?
        SUCCESSFUL_STATUSES.include? status
      end

      # Returns raw body
      def body
        loaded? ? env[:body] : nil
      end

    end # Header
  end # Response
end # Nimbu

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
nimbu-api-0.5.0 lib/nimbu-api/response/header.rb
nimbu-api-0.4.4 lib/nimbu-api/response/header.rb
nimbu-api-0.4.3 lib/nimbu-api/response/header.rb
nimbu-api-0.4.2 lib/nimbu-api/response/header.rb
nimbu-api-0.4.1 lib/nimbu-api/response/header.rb
nimbu-api-0.4.0 lib/nimbu-api/response/header.rb
nimbu-api-0.3.0 lib/nimbu-api/response/header.rb
nimbu-api-0.2.1 lib/nimbu-api/response/header.rb
nimbu-api-0.2 lib/nimbu-api/response/header.rb
nimbu-api-0.2.beta.3 lib/nimbu-api/response/header.rb
nimbu-api-0.2.beta.2 lib/nimbu-api/response/header.rb
nimbu-api-0.2.beta.1 lib/nimbu-api/response/header.rb
nimbu-api-0.2.beta lib/nimbu-api/response/header.rb
nimbu-api-0.1.5 lib/nimbu-api/response/header.rb
nimbu-api-0.1.4 lib/nimbu-api/response/header.rb
nimbu-api-0.1.3 lib/nimbu-api/response/header.rb
nimbu-api-0.1.1 lib/nimbu-api/response/header.rb
nimbu-api-0.1 lib/nimbu-api/response/header.rb
nimbu-api-0.0.2 lib/nimbu-api/response/header.rb
nimbu-api-0.0.1 lib/nimbu-api/response/header.rb