Class: Forward::API::Tunnel

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

Constant Summary

Constants inherited from Resource

Resource::DEFAULT_ERROR_MESSAGE

Constants included from Common

Common::EMAIL_REGEX

Instance Attribute Summary

Attributes inherited from Resource

#http, #uri

Class Method Summary collapse

Methods inherited from Resource

#add_body!, #add_head!, #delete, #get, #initialize, #post, #request

Methods included from Common

#config, #exit_with_error, #exit_with_message, #logged_in?, #logger, #os, #stop_reactor_and_exit, #windows?

Constructor Details

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

Class Method Details

.create(options, &block) ⇒ Object



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

def self.create(options, &block)
  resource = new
  options  = {
    path:          "#{API.base_path}/tunnels/",
    authenticated: true,
    params: {
       hostport:  options[:port],
       vhost:     options[:host],
       subdomain: options[:subdomain_prefix],
       cname:     options[:cname],
       username:  options[:username],
       password:  options[:password],
       no_auth:   options[:no_auth],
       client:    Forward.client_string,
    }
  }

  resource.post(options) do |response, status|
    if status == 200
      block.call(response)
    else
      handle_error(response, status)
    end
  end
end

.destroy(id, &block) ⇒ Object



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

def self.destroy(id, &block)
  resource = new
  options  = {
    path:          "#{API.base_path}/tunnels/#{id}",
    authenticated: true,
  }

  resource.delete(options) do |response, status|
    block.call(response)
  end
end