class SauceWhisk::Tunnels

def self.all(opts = {:fetch_each => true})

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.fetch tunnel_id

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

def self.open(opts, wait_until_ready = true)

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.resource

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

def self.stop tunnel_id

def self.stop tunnel_id
  delete tunnel_id
end