Sha256: e9df2187077f1d761576d2553a91f0f7e61879e14b81eea2537137a84b7c0708

Contents?: true

Size: 1.26 KB

Versions: 8

Compression:

Stored size: 1.26 KB

Contents

require 'base64'

require 'ably/version'

require 'ably/rest/middleware/encoder'
require 'ably/rest/middleware/external_exceptions'
require 'ably/rest/middleware/fail_if_unsupported_mime_type'
require 'ably/rest/middleware/logger'
require 'ably/rest/middleware/parse_json'
require 'ably/rest/middleware/parse_message_pack'

module Ably::Modules
  # HttpHelpers provides common private methods to classes to simplify HTTP interactions with Ably
  module HttpHelpers
    protected
    def encode64(text)
      Base64.encode64(text).gsub("\n", '')
    end

    def user_agent
      "Ably Ruby client #{Ably::VERSION} (https://ably.io)"
    end

    def setup_outgoing_middleware(builder)
      # Convert request params to "www-form-urlencoded"
      builder.use Ably::Rest::Middleware::Encoder
    end

    def setup_incoming_middleware(builder, logger, options = {})
      builder.use Ably::Rest::Middleware::Logger, logger

      # Parse JSON / MsgPack response bodies. ParseJson must be first (default) parsing middleware
      if options[:fail_if_unsupported_mime_type] == true
        builder.use Ably::Rest::Middleware::FailIfUnsupportedMimeType
      end

      builder.use Ably::Rest::Middleware::ParseJson
      builder.use Ably::Rest::Middleware::ParseMessagePack
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
ably-0.7.6 lib/ably/modules/http_helpers.rb
ably-rest-0.7.5 lib/submodules/ably-ruby/lib/ably/modules/http_helpers.rb
ably-0.7.5 lib/ably/modules/http_helpers.rb
ably-0.7.4 lib/ably/modules/http_helpers.rb
ably-rest-0.7.3 lib/submodules/ably-ruby/lib/ably/modules/http_helpers.rb
ably-0.7.2 lib/ably/modules/http_helpers.rb
ably-0.7.1 lib/ably/modules/http_helpers.rb
ably-0.7.0 lib/ably/modules/http_helpers.rb