Module: Hoth::Transport

Defined in:
lib/hoth/transport.rb,
lib/hoth/transport/base.rb,
lib/hoth/transport/http.rb,
lib/hoth/transport/https.rb,
lib/hoth/transport/beanstalkd.rb

Defined Under Namespace

Classes: Base, Beanstalkd, Http, Https

Constant Summary collapse

POSSIBLE_TRANSPORTS =
{
  :json_via_http => {
    :transport_class => Transport::Http,
    :encoder => Encoding::Json
  },
  :http => :json_via_http,

  :json_via_https => {
    :transport_class => Transport::Https,
    :encoder => Encoding::Json
  },
  :https => :json_via_https,

  :beanstalkd => {
    :transport_class => Transport::Beanstalkd,
    :encoder => Encoding::Json
  }
}

Class Method Summary collapse

Class Method Details

.create(transport_name, service) ⇒ Object



32
33
34
# File 'lib/hoth/transport.rb', line 32

def create(transport_name, service)
  new_transport_with_encoding(transport_name, service)
end

.new_transport_with_encoding(transport_name, service) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/hoth/transport.rb', line 36

def new_transport_with_encoding(transport_name, service)
  if POSSIBLE_TRANSPORTS[transport_name.to_sym]
    if POSSIBLE_TRANSPORTS[transport_name.to_sym].kind_of?(Hash)
      POSSIBLE_TRANSPORTS[transport_name.to_sym][:transport_class].new(service, :encoder => POSSIBLE_TRANSPORTS[transport_name.to_sym][:encoder])
    else
      new_transport_with_encoding(POSSIBLE_TRANSPORTS[transport_name.to_sym], service)
    end
  else
    raise TransportException.new("specified transport '#{transport_name}' does not exist, use one of these: #{POSSIBLE_TRANSPORTS.keys.join(", ")}")
  end
end