Class: Forward::Api::Tunnel

Inherits:
Resource show all
Defined in:
lib/forward/api/tunnel.rb

Instance Attribute Summary

Attributes inherited from Resource

#http, #uri

Class Method Summary collapse

Methods inherited from Resource

#add_headers!, #build_request, #delete, #get, #initialize, #parse_response, #post, #put, #request

Constructor Details

This class inherits a constructor from Forward::Api::Resource

Class Method Details

.create(options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/forward/api/tunnel.rb', line 5

def self.create(options = {})
  resource     = Tunnel.new(:create)
  resource.uri = '/api/v2/tunnels'
  params       = {
    :hostport => options[:port],
    :vhost    => options[:host],
    :client   => Forward.client_string,
  }
  
  params[:subdomain] = options[:subdomain_prefix] if options.has_key?(:subdomain_prefix)
  [ :cname, :username, :password, :no_auth ].each do |param|
    params[param] = options[param] if options.has_key?(param)
  end

  resource.post(params)[:tunnel].symbolize_keys
rescue ResourceError => e
  error_on_create(e, options)
end

.indexObject



24
25
26
27
28
29
# File 'lib/forward/api/tunnel.rb', line 24

def self.index
  resource     = Tunnel.new(:index)
  resource.uri = "/api/v2/tunnels"

  resource.get[:tunnels]
end

.show(id) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/forward/api/tunnel.rb', line 31

def self.show(id)
  resource     = Tunnel.new(:show)
  resource.uri = "/api/v2/tunnels/#{id}"

  resource.get[:tunnel].symbolize_keys
rescue Forward::Api::ResourceNotFound
  nil
end