routeros-api 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14c6115c02446080bc47d5ad9b98e15e19cb34771adfce52ebd0919d2c61cac6
4
- data.tar.gz: 63287c6efaba8a6d654d5ca939f6aa2cb1f301077561bce58a5db7e7b43a01cd
3
+ metadata.gz: b5febdeccbba11422cb6b855ea59a0f9fb065d375f8782c0ba6771c083d8d2bf
4
+ data.tar.gz: 27aab05e7586a813b76ebd300d212828d8dcad0b1347485a3878774f21299a11
5
5
  SHA512:
6
- metadata.gz: 8f9ccae171b00da8b4dc1216bede71a1608ba252264e708140fc757a4fd14e35c832d6829192996c2859c7376f8f0e540f7c48ede314a88887366ec2490f6b43
7
- data.tar.gz: e72a2576902ab545c98daf4336b16b1d1c9e236f28397fe3af7fed022609981b62a7abeef9857f82b154ce2f49f25ca76badcdd05e410cf29b3c0c1068ac17f8
6
+ metadata.gz: 70e416037d768b5e1c7e9c04db9849703409db8c6d64c14a1015c51c671a2c2f50bb237898a37cbddd6d959fe0696bcb0252f7f80c4f358908b833ecf5ddf039
7
+ data.tar.gz: 38f1a4a21045413c7e5f31b12362ebc52e746245c79dc5357ce1d0a1a373fd17883e4023da38a695aa9c347f1f554313177bd623428d8ed12ce29408200ed43b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.4.0] - 2024-10-22
4
+
5
+ - Support `async` gem
6
+
3
7
  ## [0.3.0] - 2024-10-16
4
8
 
5
9
  - SSL support
data/README.md CHANGED
@@ -24,10 +24,9 @@ if response.ok?
24
24
  end
25
25
  ```
26
26
 
27
- ## Planned Features
27
+ ### Async
28
28
 
29
- - [ ] Async support
30
- - [ ] Auto deploy and auto changelog
29
+ Async gem is supported but not required, if the gem can be loaded a method `async_command` will be available. Look at the examples folder for a full example.
31
30
 
32
31
  ## Development
33
32
 
data/examples/async.rb ADDED
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/setup"
4
+ require "routeros/api"
5
+
6
+ api = RouterOS::API.new("192.168.1.1", 8728, ssl: false)
7
+ response = api.login("test", "test")
8
+ puts(response) # (OK) []
9
+
10
+ if response.ok?
11
+ if RouterOS::API.async_enabled?
12
+ response = api.async_command("ip/route/getall")
13
+ puts(response) # Async::Task
14
+ puts(response.wait.data) # [{ ... }]
15
+ else
16
+ warn('asyn gem could not be loaded')
17
+ end
18
+ end
19
+
20
+ api.close
data/examples/simple.rb CHANGED
@@ -9,7 +9,7 @@ puts(response) # (OK) []
9
9
 
10
10
  if response.ok?
11
11
  response = api.command("ip/route/getall")
12
- puts(response.data) # (OK) [{ ... }]
12
+ puts(response.data) # [{ ... }]
13
13
  end
14
14
 
15
15
  api.close
data/lib/routeros/api.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "socket"
4
4
  require "openssl"
5
+ require_relative "async"
5
6
  require_relative "request"
6
7
  require_relative "response"
7
8
  require_relative "word_stream"
@@ -9,7 +10,9 @@ require_relative "word_stream"
9
10
  module RouterOS
10
11
  # Main abstraction to connect to RouterOS
11
12
  class API
12
- VERSION = "0.3.0"
13
+ include RouterOS::Async
14
+
15
+ VERSION = "0.4.0"
13
16
 
14
17
  class Error < StandardError; end
15
18
 
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RouterOS
4
+ # adds async support if async gem is present
5
+ module Async
6
+ @enabled = false
7
+
8
+ def self.included(base)
9
+ base.extend(ClassMethods)
10
+ end
11
+
12
+ def self.enabled?
13
+ @enabled
14
+ end
15
+
16
+ # class methods to be added when this module is included
17
+ module ClassMethods
18
+ def async_enabled?
19
+ RouterOS::Async.enabled?
20
+ end
21
+ end
22
+
23
+ begin
24
+ require 'async'
25
+
26
+ def async_command(cmd, args = [])
27
+ Async do
28
+ command(cmd, args)
29
+ end
30
+ end
31
+
32
+ @enabled = true
33
+ rescue LoadError
34
+ # async gem is not available, so no-op
35
+ end
36
+ end
37
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: routeros-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcelo Barros
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-10-17 00:00:00.000000000 Z
11
+ date: 2024-10-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -23,8 +23,10 @@ files:
23
23
  - LICENSE.txt
24
24
  - README.md
25
25
  - Rakefile
26
+ - examples/async.rb
26
27
  - examples/simple.rb
27
28
  - lib/routeros/api.rb
29
+ - lib/routeros/async.rb
28
30
  - lib/routeros/request.rb
29
31
  - lib/routeros/response.rb
30
32
  - lib/routeros/word_stream.rb