Class: Snarl::SNP::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/snarl/snp/request.rb

Constant Summary collapse

PROTOCOL_NAME =
"SNP"
PROTOCOL_VERSION =
"1.0"
SNP_ACTIONS =
{
  'register'     => %w(type version action app),
  'add_class'    => %w(type version action app class title),
  'notification' => %w(type version action app class title text timeout icon priority),
  'unregister'   => %w(type version action app),
  'hello'        => %w(type version action),
  'version'      => %w(type version action),
}
ENCODING =

You have to send non-ascii messages by “Windows” encoding.

'cp932'
SNP_SEPARATOR =
'#?'
SNP_TERMINAL_STRING =
"\r\n"
SNP_HEADER =
{'type' => PROTOCOL_NAME, 'version' => PROTOCOL_VERSION}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cmd_hash = {}) ⇒ Request

make SNP request string from command hash and is Request object.



24
25
26
27
# File 'lib/snarl/snp/request.rb', line 24

def initialize(cmd_hash={})
  @commands = {}.update(cmd_hash)
  normalize unless @commands.empty?
end

Instance Attribute Details

#commandsObject (readonly)

Returns the value of attribute commands.



29
30
31
# File 'lib/snarl/snp/request.rb', line 29

def commands
  @commands
end

Instance Method Details

#[](cmdkey) ⇒ Object

Returns command value for command key



41
# File 'lib/snarl/snp/request.rb', line 41

def [](cmdkey) ; @commands[cmdkey] ; end

#[]=(cmdkey, value) ⇒ Object

Adds command key and value to Request



32
33
34
35
36
37
38
39
# File 'lib/snarl/snp/request.rb', line 32

def []=(cmdkey, value)
  norm_cmdkey = normalize_cmdkey(cmdkey)
  if norm_cmdkey == 'action' then
    @commands['action'] = normalize_action_value(value)
  else
    @commands[norm_cmdkey] = normalize_value(value)
  end
end

#actionObject



48
# File 'lib/snarl/snp/request.rb', line 48

def action ; @commands['action'] ; end

#inspectObject

Returns Request query string. has no SNP_TERMINAL_STRING “rn”.



47
# File 'lib/snarl/snp/request.rb', line 47

def inspect ; query.inspect ; end

#to_strObject Also known as: to_s

Returns Request query string with SNP_TERMINAL_STRING “rn”



44
# File 'lib/snarl/snp/request.rb', line 44

def to_str ; query + SNP_TERMINAL_STRING ; end