Class: Squash::Uploader

Inherits:
Object
  • Object
show all
Defined in:
lib/squash/uploader.rb

Overview

Class that handles communicating with the Squash API.

By default, transmission is done with ‘Net::HTTP`. If this is unpalatable to you, reimplement #http_post.

Constant Summary collapse

DEFAULT_CONFIGURATION =

Default configuration options. See #initialize.

{
    :open_timeout      => 15,
    :read_timeout      => 15,
    :skip_verification => false,
    :success           => [Net::HTTPSuccess]
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, options = {}) ⇒ Uploader

Creates a new Squash uploader that will communicate with a given host.

Parameters:

  • host (String)

    The host name and scheme of the Squash server (e.g., “squash.mycompany.com”).

  • options (Hash) (defaults to: {})

    Additional options.

Options Hash (options):

  • :open_timeout (Fixnum) — default: 15

    The number of seconds to wait when opening a connection to the Squash server.

  • :read_timeout (Fixnum) — default: 15

    The number of seconds to wait when waiting for data from the Squash server.

  • :skip_verification (true, false) — default: false

    If ‘true`, SSL peer verification will not be performed.

  • :success (Array<Class, Fixnum>) — default: [Net::HTTPSuccess]

    A list of subclasses of ‘Net::HTTPResponse` or response codes that are considered successful and will not raise an exception.



58
59
60
61
# File 'lib/squash/uploader.rb', line 58

def initialize(host, options={})
  @host    = host
  @options = DEFAULT_CONFIGURATION.merge(options)
end

Instance Attribute Details

#hostString

Returns The host name and scheme of the Squash server (e.g., “squash.mycompany.com”).

Returns:



39
40
41
# File 'lib/squash/uploader.rb', line 39

def host
  @host
end

#optionsHash<Symbol, Object>

Returns Additional options for uploading.

Returns:

  • (Hash<Symbol, Object>)

    Additional options for uploading.



41
42
43
# File 'lib/squash/uploader.rb', line 41

def options
  @options
end

Instance Method Details

#transmit(path, data) ⇒ Object

Transmits information to Squash.

Parameters:

  • path (String)

    The path portion of the URL, with leading slash.

  • data (Hash)

    Data to JSON-serialize and place in the request body.



68
69
70
71
72
# File 'lib/squash/uploader.rb', line 68

def transmit(path, data)
  http_post (host + path),
            {'Content-Type' => 'application/json'},
            [data.to_json]
end