Class: VpnSdk::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/vpn_sdk.rb

Constant Summary collapse

BASE_URL =
'https://vpn-gateway-deploy--bxhxbb352.replit.app'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url = BASE_URL, timeout: 10) ⇒ Client

Returns a new instance of Client.



11
12
13
14
# File 'lib/vpn_sdk.rb', line 11

def initialize(base_url = BASE_URL, timeout: 10)
  @base_url = base_url
  @timeout = timeout
end

Instance Attribute Details

#base_urlObject

Returns the value of attribute base_url.



9
10
11
# File 'lib/vpn_sdk.rb', line 9

def base_url
  @base_url
end

#timeoutObject

Returns the value of attribute timeout.



9
10
11
# File 'lib/vpn_sdk.rb', line 9

def timeout
  @timeout
end

Instance Method Details

#check_healthObject



16
17
18
# File 'lib/vpn_sdk.rb', line 16

def check_health
  get('/api/healthz')
end

#connect(country_code) ⇒ Object



42
43
44
# File 'lib/vpn_sdk.rb', line 42

def connect(country_code)
  post('/api/vpn/connect', { countryCode: country_code })
end

#countriesObject



20
21
22
# File 'lib/vpn_sdk.rb', line 20

def countries
  get('/api/vpn/countries')
end

#create_session(country_code = nil) ⇒ Object



37
38
39
40
# File 'lib/vpn_sdk.rb', line 37

def create_session(country_code = nil)
  payload = country_code ? { countryCode: country_code } : {}
  post('/api/vpn/create', payload)
end

#disconnectObject



46
47
48
# File 'lib/vpn_sdk.rb', line 46

def disconnect
  post('/api/vpn/disconnect', {})
end

#servers(country_code = nil) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/vpn_sdk.rb', line 24

def servers(country_code = nil)
  path = if country_code && !country_code.to_s.empty?
           "/api/vpn/servers?countryCode=#{URI.encode_www_form_component(country_code)}"
         else
           '/api/vpn/servers'
         end
  get(path)
end

#statusObject



33
34
35
# File 'lib/vpn_sdk.rb', line 33

def status
  get('/api/vpn/status')
end