Module: HTTP::MimeType

### Home Classes Methods

### In Files

- lib/http/mime_type.rb
- lib/http/mime_type/adapter.rb
- lib/http/mime_type/json.rb

### Namespace

- CLASS HTTP::MimeType::Adapter
- CLASS HTTP::MimeType::JSON

### Methods

- ::[]
- ::normalize
- ::register_adapter
- ::register_alias

### Class/Module Index

Quicksearch

- HTTP
- HTTP::Cache
- HTTP::Cache::Headers
- HTTP::Cache::NullCache
- HTTP::Cache::NullLogger
- HTTP::CacheError
- HTTP::Chainable
- HTTP::Client
- HTTP::Connection
- HTTP::Error
- HTTP::Headers
- HTTP::Headers::Mixin
- HTTP::InvalidHeaderNameError
- HTTP::MimeType
- HTTP::MimeType::Adapter
- HTTP::MimeType::JSON
- HTTP::Options
- HTTP::Redirector
- HTTP::Redirector::EndlessRedirectError
- HTTP::Redirector::TooManyRedirectsError
- HTTP::Request
- HTTP::Request::Caching
- HTTP::Request::UnsupportedMethodError
- HTTP::Request::UnsupportedSchemeError
- HTTP::Request::Writer
- HTTP::RequestError
- HTTP::Response
- HTTP::Response::Body
- HTTP::Response::Caching
- HTTP::Response::IoBody
- HTTP::Response::Parser
- HTTP::Response::Status
- HTTP::Response::StringBody
- HTTP::ResponseError
- HTTP::StateError
- HTTP::Timeout
- HTTP::Timeout::Global
- HTTP::Timeout::Null
- HTTP::Timeout::PerOperation
- HTTP::TimeoutError
- HTTP::URI
- Object

No matching classes.

# HTTP::MimeType

MIME type encode/decode adapters

### Public Class Methods

[](type) click to toggle source

Returns adapter associated with MIME type

@param [to_s] type @raise [Error] if no adapter found @return [Class]

    # File lib/http/mime_type.rb, line 35
    def [](type)
      adapters[normalize type] || fail(Error, "Unknown MIME type: #{type}")
    end

normalize(type) click to toggle source

Resolves type by shortcut if possible

@param [to_s] type @return [String]

    # File lib/http/mime_type.rb, line 56
    def normalize(type)
      aliases.fetch type, type.to_s
    end

register_adapter(type, adapter) click to toggle source

Associate MIME type with adapter

@example

    module JsonAdapter
      class << self
        def encode(obj)
          # encode logic here
        end

        def decode(str)
          # decode logic here
        end
      end
    end

    HTTP::MimeType.register_adapter 'application/json', MyJsonAdapter

@param [to_s] type @param [encode, decode] adapter @return [void]

    # File lib/http/mime_type.rb, line 26
    def register_adapter(type, adapter)
      adapters[type.to_s] = adapter
    end

register_alias(type, shortcut) click to toggle source

Register a shortcut for MIME type

@example

    HTTP::MimeType.register_alias 'application/json', :json

@param [to_s] type @param [to_sym] shortcut @return [void]

    # File lib/http/mime_type.rb, line 48
    def register_alias(type, shortcut)
      aliases[shortcut.to_sym] = type.to_s
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.