mtik 3.1.1 → 3.1.2

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.
@@ -1,3 +1,17 @@
1
+ 2011-01-11 (11 JAN 2011) VERSION 3.1.2 Aaron D. Gifford (http://www.aarongifford.com)
2
+ * Added source file encoding comments and updated the copyright notices
3
+ * Fixed a tiny bug in lib/mtik/connection.rb
4
+ * Changed MTik::Request@state member in lib/mtik/request.rb to Symbol instead of String
5
+ * Moved tikfetch.rb, tikcli.rb, and tikcommand.rb from examples/ to bin/ and removed
6
+ the .rb suffix -- left tikjson.rb behind in examples/
7
+ * Renamed a few variables that, with warnings enabled, Ruby complained were overlapping
8
+ or hiding outer variables of the same name to avoid the warning.
9
+
10
+ 2010-12-30 (30 DEC 2011) VERSION 3.1.1 Aaron D. Gifford (http://www.aarongifford.com)
11
+ * Changed the tikfetch.rb utility so it no longer requires a destination filename
12
+ by default--it will use the supplied URL's final path element as a filename. Also
13
+ updated the stats output a bit.
14
+
1
15
  2010-04-24 (24 APR 2010) VERSION 3.1.0 Aaron D. Gifford (http://www.aarongifford.com)
2
16
  * Added find_sentences() method to MTik::Reply -- just sugar to Array.select()
3
17
  * Changed MTik::Connection.fetch() method to add an optional timeout parameter
@@ -5,7 +5,7 @@
5
5
  #
6
6
  #++
7
7
  # Author:: Aaron D. Gifford - http://www.aarongifford.com/
8
- # Copyright:: Copyright (c) 2009-2010, InfoWest, Inc.
8
+ # Copyright:: Copyright (c) 2009-2011, InfoWest, Inc.
9
9
  # License:: BSD license
10
10
  #--
11
11
  # Redistribution and use in source and binary forms, with or without
data/Rakefile CHANGED
@@ -11,7 +11,6 @@ gemspec = Gem::Specification.new do |spec|
11
11
  spec.homepage = 'http://www.aarongifford.com/computers/mtik/'
12
12
  spec.summary = 'MTik implements the MikroTik RouterOS API for use in Ruby.'
13
13
  spec.description = 'MTik implements the MikroTik RouterOS API for use in Ruby.'
14
- spec.has_rdoc = true ## Only partially true currently
15
14
  spec.rubyforge_project = 'mtik'
16
15
  spec.extra_rdoc_files = [ 'README.txt' ]
17
16
  spec.require_paths = [ 'lib' ]
@@ -21,10 +20,10 @@ gemspec = Gem::Specification.new do |spec|
21
20
  'README.txt',
22
21
  'VERSION.txt',
23
22
  'Rakefile',
24
- 'examples/tikcli.rb',
25
- 'examples/tikcommand.rb',
26
- 'examples/tikfetch.rb',
27
23
  'examples/tikjson.rb',
24
+ 'bin/tikcli',
25
+ 'bin/tikcommand',
26
+ 'bin/tikfetch',
28
27
  'lib/mtik.rb',
29
28
  'lib/mtik/connection.rb',
30
29
  'lib/mtik/error.rb',
@@ -33,6 +32,7 @@ gemspec = Gem::Specification.new do |spec|
33
32
  'lib/mtik/request.rb',
34
33
  'lib/mtik/timeouterror.rb'
35
34
  ]
35
+ spec.executables = [ 'tikcli', 'tikcommand', 'tikfetch' ]
36
36
  end
37
37
 
38
38
  Rake::GemPackageTask.new(gemspec) do |pkg|
@@ -1 +1 @@
1
- 3.1.1
1
+ 3.1.2
@@ -6,7 +6,7 @@
6
6
  #
7
7
  #++
8
8
  # Author:: Aaron D. Gifford - http://www.aarongifford.com/
9
- # Copyright:: Copyright (c) 2009-2010, InfoWest, Inc.
9
+ # Copyright:: Copyright (c) 2009-2011, InfoWest, Inc.
10
10
  # License:: BSD license
11
11
  #--
12
12
  # Redistribution and use in source and binary forms, with or without
@@ -35,6 +35,8 @@
35
35
  # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
36
36
  # THE POSSIBILITY OF SUCH DAMAGE.
37
37
  ########################################################################
38
+ # encoding: ASCII-8BIT
39
+
38
40
  $LOAD_PATH.unshift(File.dirname(__FILE__)+'/../lib')
39
41
 
40
42
  require 'rubygems'
@@ -6,7 +6,7 @@
6
6
  #
7
7
  #++
8
8
  # Author:: Aaron D. Gifford - http://www.aarongifford.com/
9
- # Copyright:: Copyright (c) 2009-2010, InfoWest, Inc.
9
+ # Copyright:: Copyright (c) 2009-2011, InfoWest, Inc.
10
10
  # License:: BSD license
11
11
  #--
12
12
  # Redistribution and use in source and binary forms, with or without
@@ -35,6 +35,8 @@
35
35
  # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
36
36
  # THE POSSIBILITY OF SUCH DAMAGE.
37
37
  ########################################################################
38
+ # encoding: ASCII-8BIT
39
+
38
40
  $LOAD_PATH.unshift(File.dirname(__FILE__)+'/../lib')
39
41
 
40
42
  require 'rubygems'
@@ -6,7 +6,7 @@
6
6
  #
7
7
  #++
8
8
  # Author:: Aaron D. Gifford - http://www.aarongifford.com/
9
- # Copyright:: Copyright (c) 2009-2010, InfoWest, Inc.
9
+ # Copyright:: Copyright (c) 2009-2011, InfoWest, Inc.
10
10
  # License:: BSD license
11
11
  #--
12
12
  # Redistribution and use in source and binary forms, with or without
@@ -35,6 +35,8 @@
35
35
  # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
36
36
  # THE POSSIBILITY OF SUCH DAMAGE.
37
37
  ########################################################################
38
+ # encoding: ASCII-8BIT
39
+
38
40
  $LOAD_PATH.unshift(File.dirname(__FILE__)+'/../lib')
39
41
 
40
42
  require 'rubygems'
@@ -6,7 +6,7 @@
6
6
  #
7
7
  #++
8
8
  # Author:: Aaron D. Gifford - http://www.aarongifford.com/
9
- # Copyright:: Copyright (c) 2009-2010, InfoWest, Inc.
9
+ # Copyright:: Copyright (c) 2009-2011, InfoWest, Inc.
10
10
  # License:: BSD license
11
11
  #--
12
12
  # Redistribution and use in source and binary forms, with or without
@@ -35,6 +35,8 @@
35
35
  # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
36
36
  # THE POSSIBILITY OF SUCH DAMAGE.
37
37
  ########################################################################
38
+ # encoding: ASCII-8BIT
39
+
38
40
  $LOAD_PATH.unshift(File.dirname(__FILE__)+'/../lib')
39
41
 
40
42
  require 'rubygems'
@@ -2,7 +2,7 @@
2
2
  ## A Ruby library implementing the Ruby MikroTik API
3
3
  ############################################################################
4
4
  ## Author:: Aaron D. Gifford - http://www.aarongifford.com/
5
- ## Copyright:: Copyright (c) 2009-2010, InfoWest, Inc.
5
+ ## Copyright:: Copyright (c) 2009-2011, InfoWest, Inc.
6
6
  ## License:: BSD license
7
7
  ##
8
8
  ## Redistribution and use in source and binary forms, with or without
@@ -31,6 +31,8 @@
31
31
  ## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32
32
  ## THE POSSIBILITY OF SUCH DAMAGE.
33
33
  ############################################################################
34
+ # encoding: ASCII-8BIT
35
+
34
36
  module MTik
35
37
  require 'mtik/error.rb'
36
38
  require 'mtik/fatalerror.rb'
@@ -122,7 +124,7 @@ module MTik
122
124
  cmd == '/tool/fetch' && sentence.key?('status') && sentence['status'] == 'finished'
123
125
  ) || (maxreply > 0 && count == maxreply)
124
126
  state = 2
125
- req.cancel do |req, sentence|
127
+ req.cancel do |r, s|
126
128
  state = 1
127
129
  end
128
130
  end
@@ -2,7 +2,7 @@
2
2
  ## A Ruby library implementing the Ruby MikroTik API
3
3
  ############################################################################
4
4
  ## Author:: Aaron D. Gifford - http://www.aarongifford.com/
5
- ## Copyright:: Copyright (c) 2009-2010, InfoWest, Inc.
5
+ ## Copyright:: Copyright (c) 2009-2011, InfoWest, Inc.
6
6
  ## License:: BSD license
7
7
  ##
8
8
  ## Redistribution and use in source and binary forms, with or without
@@ -31,6 +31,7 @@
31
31
  ## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32
32
  ## THE POSSIBILITY OF SUCH DAMAGE.
33
33
  ############################################################################
34
+ # encoding: ASCII-8BIT
34
35
 
35
36
  ## The MTik::Connection class is the workhorse where most stuff gets done.
36
37
  ## Create an instance of this object to connect to a MikroTik device via
@@ -336,10 +337,10 @@ class MTik::Connection
336
337
  ##
337
338
  def send_request(await_completion, command, *args, &callback)
338
339
  if await_completion.is_a?(MTik::Request)
340
+ req = await_completion
339
341
  if req.done?
340
342
  raise MTik::Error.new("Cannot MTik#send_request() with an already-completed MTik::Request object.")
341
343
  end
342
- req = await_completion
343
344
  req.addarg(command)
344
345
  req.addargs(*args)
345
346
  else
@@ -511,7 +512,7 @@ class MTik::Connection
511
512
  '/tool/fetch',
512
513
  '=url=' + url,
513
514
  '=dst-path=' + filename
514
- ) do |req, s|
515
+ ) do |r, s|
515
516
  if s.key?('!re') && !done
516
517
  unless s.key?('status')
517
518
  raise MTik::Error.new("Unknown response to '/tool/fetch': missing 'status' in response.")
@@ -525,24 +526,24 @@ class MTik::Connection
525
526
  lastactivity = Time.now
526
527
  elsif timeout != 0 && !timeout.nil? && Time.now - lastactivity > timeout
527
528
  ## Cancel the request (idle too long):
528
- get_reply('/cancel', '=tag=' + req.tag) {}
529
+ get_reply('/cancel', '=tag=' + r.tag) {}
529
530
  end
530
- callback.call(status, total, bytes, req)
531
+ callback.call(status, total, bytes, r)
531
532
  when 'connecting', 'requesting'
532
- callback.call(status, 0, 0, req)
533
+ callback.call(status, 0, 0, r)
533
534
  when 'failed', 'finished'
534
535
  bytes = total if status == 'finished'
535
- callback.call(status, total, bytes, req)
536
+ callback.call(status, total, bytes, r)
536
537
  done = true
537
538
  ## Now terminate the download request (since it's done):
538
- get_reply('/cancel', '=tag=' + req.tag) {}
539
+ get_reply('/cancel', '=tag=' + r.tag) {}
539
540
  else
540
541
  raise MTik::Error.new("Unknown status in '/tool/fetch' response: '#{status}'")
541
542
  end
542
543
  elsif s.key?('!trap')
543
544
  ## Pass trap message back (unless finished--in which case we
544
545
  ## ignore the 'interrrupted' trap message):
545
- callback.call(s['message'], total, bytes, req) if !done
546
+ callback.call(s['message'], total, bytes, r) if !done
546
547
  end
547
548
  end
548
549
  end
@@ -605,8 +606,8 @@ class MTik::Connection
605
606
  if s.key?(key)
606
607
  ## A key matches! && s[k] != v
607
608
  oldv = s[k]
608
- get_reply(cmdpath + '/set', '='+k+'='+v) do |req, s|
609
- trap = req.reply.find_sentence('!trap')
609
+ get_reply(cmdpath + '/set', '='+k+'='+v) do |r, sn|
610
+ trap = r.reply.find_sentence('!trap')
610
611
  unless trap.nil?
611
612
  raise MTik::Error.new("Trap while executing '#{cmdpath}/set =#{k}=#{v}': #{trap['message']}")
612
613
  end
@@ -2,7 +2,7 @@
2
2
  ## A Ruby library implementing the Ruby MikroTik API
3
3
  ############################################################################
4
4
  ## Author:: Aaron D. Gifford - http://www.aarongifford.com/
5
- ## Copyright:: Copyright (c) 2009-2010, InfoWest, Inc.
5
+ ## Copyright:: Copyright (c) 2009-2011, InfoWest, Inc.
6
6
  ## License:: BSD license
7
7
  ##
8
8
  ## Redistribution and use in source and binary forms, with or without
@@ -31,6 +31,7 @@
31
31
  ## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32
32
  ## THE POSSIBILITY OF SUCH DAMAGE.
33
33
  ############################################################################
34
+ # encoding: ASCII-8BIT
34
35
 
35
36
  ## Basic execption type raised by this code
36
37
  class MTik::Error < RuntimeError ; end
@@ -2,7 +2,7 @@
2
2
  ## A Ruby library implementing the Ruby MikroTik API
3
3
  ############################################################################
4
4
  ## Author:: Aaron D. Gifford - http://www.aarongifford.com/
5
- ## Copyright:: Copyright (c) 2009-2010, InfoWest, Inc.
5
+ ## Copyright:: Copyright (c) 2009-2011, InfoWest, Inc.
6
6
  ## License:: BSD license
7
7
  ##
8
8
  ## Redistribution and use in source and binary forms, with or without
@@ -31,6 +31,7 @@
31
31
  ## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32
32
  ## THE POSSIBILITY OF SUCH DAMAGE.
33
33
  ############################################################################
34
+ # encoding: ASCII-8BIT
34
35
 
35
36
  ## Execption raised when a <i>"!fatal"</i> response is received from a device
36
37
  class MTik::FatalError < MTik::Error ; end
@@ -2,7 +2,7 @@
2
2
  ## A Ruby library implementing the Ruby MikroTik API
3
3
  ############################################################################
4
4
  ## Author:: Aaron D. Gifford - http://www.aarongifford.com/
5
- ## Copyright:: Copyright (c) 2009-2010, InfoWest, Inc.
5
+ ## Copyright:: Copyright (c) 2009-2011, InfoWest, Inc.
6
6
  ## License:: BSD license
7
7
  ##
8
8
  ## Redistribution and use in source and binary forms, with or without
@@ -31,6 +31,7 @@
31
31
  ## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32
32
  ## THE POSSIBILITY OF SUCH DAMAGE.
33
33
  ############################################################################
34
+ # encoding: ASCII-8BIT
34
35
 
35
36
  ## A MikroTik API reply is stored as an array of response sentences. Each
36
37
  ## sentence is a key/value Hash object. The MTik::Reply class is simply
@@ -2,7 +2,7 @@
2
2
  ## A Ruby library implementing the Ruby MikroTik API
3
3
  ############################################################################
4
4
  ## Author:: Aaron D. Gifford - http://www.aarongifford.com/
5
- ## Copyright:: Copyright (c) 2009-2010, InfoWest, Inc.
5
+ ## Copyright:: Copyright (c) 2009-2011, InfoWest, Inc.
6
6
  ## License:: BSD license
7
7
  ##
8
8
  ## Redistribution and use in source and binary forms, with or without
@@ -31,6 +31,7 @@
31
31
  ## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32
32
  ## THE POSSIBILITY OF SUCH DAMAGE.
33
33
  ############################################################################
34
+ # encoding: ASCII-8BIT
34
35
 
35
36
  ## A MikroTik API request object is stored as an array of MikroTik
36
37
  ## API-style words, the first word being the command, subsequent words
@@ -67,7 +68,7 @@ class MTik::Request < Array
67
68
  @reply = MTik::Reply.new
68
69
  @command = command
69
70
  @await_completion = await_completion
70
- @state = 'new' ## 'new', 'sent', 'cancelled', 'complete'
71
+ @state = :new ## :new, :sent, :canceled, :complete
71
72
  @conn = nil
72
73
 
73
74
  args.flatten!
@@ -134,7 +135,7 @@ class MTik::Request < Array
134
135
  ## Return the boolean completion status of the request,
135
136
  ## _true_ if complete, _false_ if not-yet-complete.
136
137
  def done?
137
- return @state == 'complete'
138
+ return @state == :complete
138
139
  end
139
140
 
140
141
  attr_reader :command, :tag, :await_completion, :reply, :state
@@ -232,39 +233,42 @@ class MTik::Request < Array
232
233
  "is not yet associated with an MTik::Connection object."
233
234
  )
234
235
  end
235
- @state = 'sent'
236
+ @state = :sent
236
237
  return @conn.xmit(self)
237
238
  end
238
239
 
239
240
  ## Cancel a 'sent' request:
240
241
  def cancel(&callback)
241
- if @state != 'sent'
242
+ if @state != :sent
242
243
  raise MTik::Error.new(
243
244
  "Method MTik::Request#cancel() called with state '#{@state}' " +
244
245
  "(should only call when state is 'sent')"
245
246
  )
246
247
  end
247
248
  @conn.send_request(true, '/cancel', '=tag=' + @tag, &callback)
248
- @state = 'cancelled'
249
+ @state = :canceled
249
250
  end
250
251
 
251
252
  ## Cancel a 'sent' request:
252
253
  def cancel_each(&callback)
253
- if @state != 'sent'
254
+ if @state != :sent
254
255
  raise MTik::Error.new(
255
256
  "Method MTik::Request#cancel() called with state '#{@state}' " +
256
257
  "(should only call when state is 'sent')"
257
258
  )
258
259
  end
259
260
  @conn.send_request(false, '/cancel', '=tag=' + @tag, &callback)
260
- @state = 'cancelled'
261
+ @state = :canceled
261
262
  end
262
263
 
263
264
  ## Method the internal parser calls to flag this reply as completed
264
- ## upon receipt of a <i>"!done"</i> reply sentence.
265
+ ## upon receipt of a <i>"!done"</i> reply sentence. WARNING: If you
266
+ ## call this manually and another sentence arrives, an exception
267
+ ## will be raised!
265
268
  def done!
266
- @state = 'complete'
269
+ @state = :complete
267
270
  return true
268
271
  end
272
+
269
273
  end
270
274
 
@@ -2,7 +2,7 @@
2
2
  ## A Ruby library implementing the Ruby MikroTik API
3
3
  ############################################################################
4
4
  ## Author:: Aaron D. Gifford - http://www.aarongifford.com/
5
- ## Copyright:: Copyright (c) 2009-2010, InfoWest, Inc.
5
+ ## Copyright:: Copyright (c) 2009-2011, InfoWest, Inc.
6
6
  ## License:: BSD license
7
7
  ##
8
8
  ## Redistribution and use in source and binary forms, with or without
@@ -31,6 +31,7 @@
31
31
  ## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32
32
  ## THE POSSIBILITY OF SUCH DAMAGE.
33
33
  ############################################################################
34
+ # encoding: ASCII-8BIT
34
35
 
35
36
  ## Exception raised upon timeout
36
37
  class MTik::TimeoutError < MTik::Error ; end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 3
7
7
  - 1
8
- - 1
9
- version: 3.1.1
8
+ - 2
9
+ version: 3.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Aaron D. Gifford
@@ -14,14 +14,16 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-30 00:00:00 -07:00
17
+ date: 2011-01-11 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
21
21
  description: MTik implements the MikroTik RouterOS API for use in Ruby.
22
22
  email: email_not_accepted@aarongifford.com
23
- executables: []
24
-
23
+ executables:
24
+ - tikcli
25
+ - tikcommand
26
+ - tikfetch
25
27
  extensions: []
26
28
 
27
29
  extra_rdoc_files:
@@ -32,10 +34,10 @@ files:
32
34
  - README.txt
33
35
  - VERSION.txt
34
36
  - Rakefile
35
- - examples/tikcli.rb
36
- - examples/tikcommand.rb
37
- - examples/tikfetch.rb
38
37
  - examples/tikjson.rb
38
+ - bin/tikcli
39
+ - bin/tikcommand
40
+ - bin/tikfetch
39
41
  - lib/mtik.rb
40
42
  - lib/mtik/connection.rb
41
43
  - lib/mtik/error.rb