Sha256: c9dff81f14d98565ae1606e1ad331319da1887d7ab578c7746834440ee9d32d0

Contents?: true

Size: 1.03 KB

Versions: 8

Compression:

Stored size: 1.03 KB

Contents

# typed: true
# frozen_string_literal: true

require 'stream-chat/stream_rate_limits'
require 'stream-chat/types'

module StreamChat
  class StreamResponse < Hash
    extend T::Sig

    sig { returns(StreamRateLimits) }
    attr_reader :rate_limit

    sig { returns(Integer) }
    attr_reader :status_code

    sig { returns(StringKeyHash) }
    attr_reader :headers

    sig { params(hash: T::Hash[T.untyped, T.untyped], response: Faraday::Response).void }
    def initialize(hash, response)
      super(nil)
      merge!(hash)

      if response.headers.key?('X-Ratelimit-Limit')
        @rate_limit = T.let(StreamRateLimits.new(
                              T.must(response.headers['X-Ratelimit-Limit']),
                              T.must(response.headers['X-Ratelimit-Remaining']),
                              T.must(response.headers['X-Ratelimit-Reset'])
                            ), StreamRateLimits)
      end

      @status_code = T.let(response.status, Integer)
      @headers = T.let(response.headers, StringKeyHash)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
stream-chat-ruby-3.7.0 lib/stream-chat/stream_response.rb
stream-chat-ruby-3.5.1 lib/stream-chat/stream_response.rb
stream-chat-ruby-3.5.0 lib/stream-chat/stream_response.rb
stream-chat-ruby-3.4.0 lib/stream-chat/stream_response.rb
stream-chat-ruby-3.3.0 lib/stream-chat/stream_response.rb
stream-chat-ruby-3.2.0 lib/stream-chat/stream_response.rb
stream-chat-ruby-3.1.0 lib/stream-chat/stream_response.rb
stream-chat-ruby-3.0.0 lib/stream-chat/stream_response.rb