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



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

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)


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

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

#keyPritunlApiClient::Key

Key apis



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

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

#logArray

Returns a list of server log entries

Returns:

  • (Array)


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

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

#organizationPritunlApiClient::Organization

Organization apis



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

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

#pingBoolean

Server healthcheck

Returns:

  • (Boolean)


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

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

#serverPritunlApiClient::Server

Server apis



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

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

#settingsPritunlApiClient::Settings

Setting apis



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

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

#statusHash

Returns general information about the pritunl server

Returns:

  • (Hash)


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

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

#userPritunlApiClient::User

User apis



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

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