Class: OPNsenseAPI::Client
- Inherits:
-
Object
- Object
- OPNsenseAPI::Client
- Defined in:
- lib/opnsense_api/client.rb
Constant Summary collapse
- BASE_PATH =
'/api'
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#api_secret ⇒ Object
readonly
Returns the value of attribute api_secret.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #captive_portal ⇒ Object
- #core ⇒ Object
- #cron ⇒ Object
- #diagnostics ⇒ Object
- #firewall ⇒ Object
- #get(path, params = {}) ⇒ Object
- #ids ⇒ Object
-
#initialize(host:, api_key:, api_secret:, **options) ⇒ Client
constructor
A new instance of Client.
- #interfaces ⇒ Object
- #ipsec ⇒ Object
- #monit ⇒ Object
- #open_vpn ⇒ Object
- #post(path, body = {}) ⇒ Object
- #proxy ⇒ Object
- #routes ⇒ Object
- #syslog ⇒ Object
- #traffic_shaping ⇒ Object
- #unbound ⇒ Object
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:, **) @host = host.is_a?(URI) ? host : URI(host) @api_key = api_key @api_secret = api_secret @options = { verify_ssl: [:verify_ssl] || true, debug: [:debug] || false, ** } end |
Instance Attribute Details
#api_key ⇒ Object (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_secret ⇒ Object (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 |
#host ⇒ Object (readonly)
Returns the value of attribute host.
25 26 27 |
# File 'lib/opnsense_api/client.rb', line 25 def host @host end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
25 26 27 |
# File 'lib/opnsense_api/client.rb', line 25 def @options end |
Instance Method Details
#captive_portal ⇒ Object
38 39 40 |
# File 'lib/opnsense_api/client.rb', line 38 def captive_portal Core::CaptivePortal.new(self) end |
#core ⇒ Object
42 43 44 |
# File 'lib/opnsense_api/client.rb', line 42 def core Core::Core.new(self) end |
#cron ⇒ Object
46 47 48 |
# File 'lib/opnsense_api/client.rb', line 46 def cron Core::Cron.new(self) end |
#diagnostics ⇒ Object
50 51 52 |
# File 'lib/opnsense_api/client.rb', line 50 def diagnostics Core::Diagnostics.new(self) end |
#firewall ⇒ Object
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 |
#interfaces ⇒ Object
62 63 64 |
# File 'lib/opnsense_api/client.rb', line 62 def interfaces Core::Interfaces.new(self) end |
#ipsec ⇒ Object
66 67 68 |
# File 'lib/opnsense_api/client.rb', line 66 def ipsec Core::IPSec.new(self) end |
#monit ⇒ Object
70 71 72 |
# File 'lib/opnsense_api/client.rb', line 70 def monit Core::Monit.new(self) end |
#open_vpn ⇒ Object
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 |
#proxy ⇒ Object
78 79 80 |
# File 'lib/opnsense_api/client.rb', line 78 def proxy Core::Proxy.new(self) end |
#routes ⇒ Object
82 83 84 |
# File 'lib/opnsense_api/client.rb', line 82 def routes Core::Routes.new(self) end |
#syslog ⇒ Object
86 87 88 |
# File 'lib/opnsense_api/client.rb', line 86 def syslog Core::Syslog.new(self) end |
#traffic_shaping ⇒ Object
90 91 92 |
# File 'lib/opnsense_api/client.rb', line 90 def traffic_shaping Core::TrafficShaping.new(self) end |