Sha256: d1a6500d0532a48c1fb0236f1b86f786a19c7d500562454966f8b5aa3d3e6cab

Contents?: true

Size: 1.26 KB

Versions: 74

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://www.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

74 entries across 74 versions & 2 rubygems

Version Path
ably-1.0.3 lib/ably/modules/http_helpers.rb
ably-1.0.2 lib/ably/modules/http_helpers.rb
ably-1.0.1 lib/ably/modules/http_helpers.rb
ably-rest-1.0.0 lib/submodules/ably-ruby/lib/ably/modules/http_helpers.rb
ably-1.0.0 lib/ably/modules/http_helpers.rb
ably-rest-0.8.15 lib/submodules/ably-ruby/lib/ably/modules/http_helpers.rb
ably-0.8.15 lib/ably/modules/http_helpers.rb
ably-rest-0.9.3 lib/submodules/ably-ruby/lib/ably/modules/http_helpers.rb
ably-rest-0.9.2 lib/submodules/ably-ruby/lib/ably/modules/http_helpers.rb
ably-rest-0.9.1 lib/submodules/ably-ruby/lib/ably/modules/http_helpers.rb
ably-rest-0.9.0 lib/submodules/ably-ruby/lib/ably/modules/http_helpers.rb
ably-rest-0.8.14 lib/submodules/ably-ruby/lib/ably/modules/http_helpers.rb
ably-0.8.14 lib/ably/modules/http_helpers.rb
ably-rest-0.8.13 lib/submodules/ably-ruby/lib/ably/modules/http_helpers.rb
ably-0.8.13 lib/ably/modules/http_helpers.rb
ably-0.8.12 lib/ably/modules/http_helpers.rb
ably-0.8.11 lib/ably/modules/http_helpers.rb
ably-0.8.10 lib/ably/modules/http_helpers.rb
ably-rest-0.8.9 lib/submodules/ably-ruby/lib/ably/modules/http_helpers.rb
ably-0.8.9 lib/ably/modules/http_helpers.rb