Class: OPNsenseAPI::Client

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

Constant Summary collapse

BASE_PATH =
'/api'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host:, api_key:, api_secret:, **options) ⇒ Client

Returns a new instance of Client.



27
28
29
30
31
32
33
34
35
36
# File 'lib/opnsense_api/client.rb', line 27

def initialize(host:, api_key:, api_secret:, **options)
  @host = host.is_a?(URI) ? host : URI(host)
  @api_key = api_key
  @api_secret = api_secret
  @options = {
    verify_ssl: options[:verify_ssl] || true,
    debug: options[:debug] || false,
    **options
  }
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



25
26
27
# File 'lib/opnsense_api/client.rb', line 25

def api_key
  @api_key
end

#api_secretObject (readonly)

Returns the value of attribute api_secret.



25
26
27
# File 'lib/opnsense_api/client.rb', line 25

def api_secret
  @api_secret
end

#hostObject (readonly)

Returns the value of attribute host.



25
26
27
# File 'lib/opnsense_api/client.rb', line 25

def host
  @host
end

#optionsObject (readonly)

Returns the value of attribute options.



25
26
27
# File 'lib/opnsense_api/client.rb', line 25

def options
  @options
end

Instance Method Details

#captive_portalObject



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

def captive_portal
  Core::CaptivePortal.new(self)
end

#coreObject



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

def core
  Core::Core.new(self)
end

#cronObject



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

def cron
  Core::Cron.new(self)
end

#diagnosticsObject



50
51
52
# File 'lib/opnsense_api/client.rb', line 50

def diagnostics
  Core::Diagnostics.new(self)
end

#firewallObject



54
55
56
# File 'lib/opnsense_api/client.rb', line 54

def firewall
  Core::Firewall.new(self)
end

#get(path, params = {}) ⇒ Object



98
99
100
101
102
103
# File 'lib/opnsense_api/client.rb', line 98

def get(path, params = {})
  request = Net::HTTP::Get.new("#{BASE_PATH}#{path}")
  setup_request(request)
  request.params = params if params.any?
  handle_response(http.request(request))
end

#idsObject



58
59
60
# File 'lib/opnsense_api/client.rb', line 58

def ids
  Core::IDS.new(self)
end

#interfacesObject



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

def interfaces
  Core::Interfaces.new(self)
end

#ipsecObject



66
67
68
# File 'lib/opnsense_api/client.rb', line 66

def ipsec
  Core::IPSec.new(self)
end

#monitObject



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

def monit
  Core::Monit.new(self)
end

#open_vpnObject



74
75
76
# File 'lib/opnsense_api/client.rb', line 74

def open_vpn
  Core::OpenVPN.new(self)
end

#post(path, body = {}) ⇒ Object



105
106
107
108
109
110
# File 'lib/opnsense_api/client.rb', line 105

def post(path, body = {})
  request = Net::HTTP::Post.new("#{BASE_PATH}#{path}")
  setup_request(request)
  request.body = body.to_json
  handle_response(http.request(request))
end

#proxyObject



78
79
80
# File 'lib/opnsense_api/client.rb', line 78

def proxy
  Core::Proxy.new(self)
end

#routesObject



82
83
84
# File 'lib/opnsense_api/client.rb', line 82

def routes
  Core::Routes.new(self)
end

#syslogObject



86
87
88
# File 'lib/opnsense_api/client.rb', line 86

def syslog
  Core::Syslog.new(self)
end

#traffic_shapingObject



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

def traffic_shaping
  Core::TrafficShaping.new(self)
end

#unboundObject



94
95
96
# File 'lib/opnsense_api/client.rb', line 94

def unbound
  Core::Unbound.new(self)
end