Sha256: 40bae9a4c088d41d7152d1d2eb01c97cb1af4715249a11d75de6c5234b03eea7

Contents?: true

Size: 1.42 KB

Versions: 14

Compression:

Stored size: 1.42 KB

Contents

require 'sauce_whisk/rest_request_builder'

module SauceWhisk
  class Tunnels
    extend RestRequestBuilder

    def self.resource
      "#{SauceWhisk.username}/tunnels"
    end

    def self.all(opts = {:fetch_each => true})
      all_tunnels = JSON.parse get
      fetch_each = opts[:fetch_each]

      unless fetch_each
        return all_tunnels
      end

      tunnels = all_tunnels.map do |tunnel|
        fetch tunnel
      end

      return tunnels
    end

    def self.open(opts, wait_until_ready = true)
      new_tunnel_parameters = JSON.parse((post :payload => opts), :symbolize_names => true)
      new_tunnel = fetch new_tunnel_parameters[:id]

      while(["starting", "booting"].include? new_tunnel.status)

        new_tunnel = fetch new_tunnel_parameters[:id]
      end

      return new_tunnel
    end

    def self.stop tunnel_id
      delete tunnel_id
    end

    def self.fetch tunnel_id
      unless tunnel_id
        raise ArgumentError, "Can't fetch a tunnel without an id (you provided blank or nil)"
      end
      tunnel_parameters = JSON.parse(get(tunnel_id), :symbolize_names => true)
      Tunnel.new tunnel_parameters
    end
  end

  class Tunnel
    attr_reader :id, :owner, :status, :host, :creation_time, :ssh_port

    def initialize(params)
      params.each do |param, val|
        self.instance_variable_set("@#{param}", val)
      end
    end

    def stop
      SauceWhisk::Tunnels.stop self.id
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
sauce_whisk-0.2.0 lib/sauce_whisk/tunnels.rb
sauce_whisk-0.1.0 lib/sauce_whisk/tunnels.rb
sauce_whisk-0.0.22 lib/sauce_whisk/tunnels.rb
sauce_whisk-0.0.21 lib/sauce_whisk/tunnels.rb
sauce_whisk-0.0.20 lib/sauce_whisk/tunnels.rb
sauce_whisk-0.0.19 lib/sauce_whisk/tunnels.rb
sauce_whisk-0.0.18 lib/sauce_whisk/tunnels.rb
sauce_whisk-0.0.17 lib/sauce_whisk/tunnels.rb
sauce_whisk-0.0.16 lib/sauce_whisk/tunnels.rb
sauce_whisk-0.0.15 lib/sauce_whisk/tunnels.rb
sauce_whisk-0.0.14 lib/sauce_whisk/tunnels.rb
sauce_whisk-0.0.13 lib/sauce_whisk/tunnels.rb
sauce_whisk-0.0.12 lib/sauce_whisk/tunnels.rb
sauce_whisk-0.0.11 lib/sauce_whisk/tunnels.rb