Audiovox P965 Datový list Strana 201

  • Stažení
  • Přidat do mých příruček
  • Tisk
  • Strana
    / 280
  • Tabulka s obsahem
  • KNIHY
  • Hodnocené. / 5. Na základě hodnocení zákazníků
Zobrazit stránku 200
API Ruby class
198
One may wonder why not use ?name=foo instead of using the ID parameter. The gem author has discovered that
API commands that make changes often do not work even though the API does not respond with an error, unless the
object to be changed is directly referenced by .id. In updating or removing users, this appears to be the case.
Execute a multiple-response command and automatically cancel it to limit the number of
replies
require 'rubygems'
require 'mtik'
# Be verbose in output
MTik::verbose = true
# Connect to the device:
p connection = MTik::command(
:host => '10.0.0.1',
:user => 'username',
:pass => 'password',
:command => [
"/interface/monitor-traffic",
"=interface=ether0",
"=.proplist=rx-bits-per-second,tx-bits-per-second"
],
:limit => 10 ## Auto-cancel after 10 replies
)
In the above code, the /interface/monitor-traffic command is executed using the blocking
(non-event-style) MTik::command() library method. But because the monitor-traffic command normally
will keep sending replies (one per second) forever, the :limit => 10 parameter was passed. That makes the
library count replies and automatically issue a /cancel API command after the specified number of replies have
been received. That way the blocking-style MTik::command() method can be safely used without the program
hanging forever.
Below is what this example might output. REMEMBER that MTik::verbose = true so most of the output is
due to that, and only the final line is the actual final data returned by the MTik::command() call:
<<< '/login' (6)
<<< '.tag=0' (6)
<<< END-OF-SENTENCE
>>> '!done' (5)
>>> 'ret=2830ce30c78f9123d31544654d28a6e0' (36)
>>> '.tag=0' (6)
>>> END-OF SENTENCE
<<< '/login' (6)
<<< '=name=username' (9)
<<< '=response=008a9eba141f9e0f8d2337ab84366298cb' (44)
<<< '.tag=1' (6)
<<< END-OF-SENTENCE
Zobrazit stránku 200
1 2 ... 196 197 198 199 200 201 202 203 204 205 206 ... 279 280

Komentáře k této Příručce

Žádné komentáře