Class: SauceWhisk::Tunnels

Inherits:
Object
  • Object
show all
Extended by:
RestRequestBuilder
Defined in:
lib/sauce_whisk/tunnels.rb

Class Method Summary collapse

Methods included from RestRequestBuilder

auth_details, delete, fully_qualified_resource, get, make_request, post, put, request_from_rest_client

Class Method Details

.all(opts = {:fetch_each => true}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/sauce_whisk/tunnels.rb', line 11

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

.fetch(tunnel_id) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/sauce_whisk/tunnels.rb', line 42

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

.open(opts, wait_until_ready = true) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/sauce_whisk/tunnels.rb', line 26

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

.resourceObject



7
8
9
# File 'lib/sauce_whisk/tunnels.rb', line 7

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

.stop(tunnel_id) ⇒ Object



38
39
40
# File 'lib/sauce_whisk/tunnels.rb', line 38

def self.stop tunnel_id
  delete tunnel_id
end