Class: RCTClient

Inherits:
Object
  • Object
show all
Defined in:
lib/rct_client.rb

Overview


Base class for rct client classes.

Instance Method Summary collapse

Instance Method Details

#add_param(params, name, value) ⇒ Object


Adds an additional query param “name=value” to the given ‘params’. This ‘params’ may be nil.

The new param is added only if both name and value are non-nil, otherwise params is returned unchanged.



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rct_client.rb', line 39

def add_param(params, name, value)
  if (name == nil || name.empty? || value == nil || value.empty?)
    return params
  end

  val = CGI.escape(value)
  if (params == nil || params.empty?)
    return "?#{name}=#{val}"
  end

  return "#{params}&#{name}=#{val}"
end

#add_to_hash_if_set(name, hash) ⇒ Object


If the global state contains a non-nil/non-empty value for key ‘name’, add it to the ‘hash’ provided.



76
77
78
79
80
81
82
# File 'lib/rct_client.rb', line 76

def add_to_hash_if_set(name, hash)
  value = RCT.sget(name)
  return false if value == nil
  return false if value.empty?
  hash[name] = value
  return true
end

#is_cliObject


Convenience function, returns true if we’re running in CLI mode.



129
130
131
132
133
# File 'lib/rct_client.rb', line 129

def is_cli
  mode = sget(RCT_MODE)
  return true if (mode == RCT_MODE_CLI)
  false
end

#log(level, line) ⇒ Object


Log a message. Level is one of RESULT, INFO, DEBUG.



88
89
90
# File 'lib/rct_client.rb', line 88

def log(level, line)
  rct_log(level, line)
end

#sdelete(key) ⇒ Object


Delete the given ‘key’ from both permanent and temporary state.



121
122
123
# File 'lib/rct_client.rb', line 121

def sdelete(key)
  RCT.sdelete(key)
end

#set(var) ⇒ Object


Return true if var contains something (that is, it is not nil and not empty).



65
66
67
68
69
# File 'lib/rct_client.rb', line 65

def set(var)
  return false if var == nil
  return false if var.empty?
  return true
end

#sget(key) ⇒ Object


Get the value of ‘key’ (if available, or returns nil).



113
114
115
# File 'lib/rct_client.rb', line 113

def sget(key)
  RCT.sget(key)
end

#sset(key, value, temp = false) ⇒ Object


Set (or change) ‘key’ in state to contain ‘value’. If ‘temp’ is true, this key is stored in temporary state only.



97
98
99
# File 'lib/rct_client.rb', line 97

def sset(key, value, temp=false)
  RCT.sset(key, value, temp)
end

#ssettmp(key, value) ⇒ Object


Set (or change) ‘key’ in temporary state to contain ‘value’.



105
106
107
# File 'lib/rct_client.rb', line 105

def ssettmp(key, value)
  RCT.sset(key, value, true)
end

#uuidObject


Returns a random UUID.



56
57
58
# File 'lib/rct_client.rb', line 56

def uuid
  return SecureRandom.uuid()
end