Class: PritunlApiClient::Client

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

Overview

Main interface to the Pritunl api

Instance Method Summary collapse

Constructor Details

#initialize(base_url:, api_token:, api_secret:, verify_ssl: true) ⇒ Client

Returns a new instance of Client.

Parameters:

  • base_url (String)

    Full URL to a running Pritunl server (include the “https://”)

  • api_token (String)

    pi_token [String

  • api_secret (String)
  • verify_ssl (Boolean) (defaults to: true)

    Whether or not to verify SSL certificate



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

def initialize( base_url:, api_token:, api_secret:, verify_ssl: true )
  @base_url   = base_url
  @api_token  = api_token
  @api_secret = api_secret
  @verify_ssl = verify_ssl
  @api = Api.new( base_url: base_url, api_token: api_token, api_secret: api_secret, verify_ssl: verify_ssl )
end

Instance Method Details

#event(cursor: nil) ⇒ Array

Get a list of events (will poll up to 30 seconds)

Parameters:

  • cursor (String, NilClass) (defaults to: nil)

    Optional id of last event. If left out, only events that occurred after request is sent will be returned.

Returns:

  • (Array)


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

def event( cursor: nil )
  @api.get( "/event/#{cursor}" )
end

#keyPritunlApiClient::Key

Key apis



91
92
93
# File 'lib/pritunl_api_client.rb', line 91

def key
  @key ||= Key.new( @api )
end

#logArray

Returns a list of server log entries

Returns:

  • (Array)


63
64
65
# File 'lib/pritunl_api_client.rb', line 63

def log
  @api.get( '/log' )
end

#organizationPritunlApiClient::Organization

Organization apis



77
78
79
# File 'lib/pritunl_api_client.rb', line 77

def organization
  @organization ||= Organization.new( @api )
end

#pingBoolean

Server healthcheck

Returns:

  • (Boolean)


45
46
47
48
49
50
51
# File 'lib/pritunl_api_client.rb', line 45

def ping
  begin
    @api.get( '/ping' ) == ''
  rescue
    false
  end
end

#serverPritunlApiClient::Server

Server apis



98
99
100
# File 'lib/pritunl_api_client.rb', line 98

def server
  @server ||= Server.new( @api )
end

#settingsPritunlApiClient::Settings

Setting apis



70
71
72
# File 'lib/pritunl_api_client.rb', line 70

def settings
  @settings ||= Settings.new( @api )
end

#statusHash

Returns general information about the pritunl server

Returns:

  • (Hash)


56
57
58
# File 'lib/pritunl_api_client.rb', line 56

def status
  @api.get( '/status' )
end

#userPritunlApiClient::User

User apis



84
85
86
# File 'lib/pritunl_api_client.rb', line 84

def user
  @user ||= User.new( @api )
end