Class: CatalogRuleService

Inherits:
Object
  • Object
show all
Defined in:
lib/api/catalogrule/CatalogRuleService.rb

Overview

CatalogRuleService

This class provides a facade for SOAP method calls to the ZXTM Virtual Server web service.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint = nil, username = nil, password = nil) ⇒ CatalogRuleService

Returns a new instance of CatalogRuleService.



12
13
14
15
16
# File 'lib/api/catalogrule/CatalogRuleService.rb', line 12

def initialize(endpoint=nil, username=nil, password=nil)
  @driver = CatalogRulePort.new(endpoint)
  @driver.options["protocol.http.ssl_config.verify_mode"] = OpenSSL::SSL::VERIFY_NONE
  @driver.options["protocol.http.basic_auth"] << [endpoint, username, password]
end

Instance Attribute Details

#driverObject

Returns the value of attribute driver.



10
11
12
# File 'lib/api/catalogrule/CatalogRuleService.rb', line 10

def driver
  @driver
end

Instance Method Details

#copy(name, new_name) ⇒ Object

Copies a rule

Args name (String) - Name of current rule new_name (String) - Name of new rule

Examples copy(name, new_name) - Copies rule called "name" to a new rule, called "new_name"



100
101
102
# File 'lib/api/catalogrule/CatalogRuleService.rb', line 100

def copy(name, new_name)
  @driver.copyRule([name], [new_name])
end

#create(name, text) ⇒ Object

Creates a new rule

Args name (String) - Rule name text (String) - Rule text

Examples create("route-traffic", ["text_of_rule"]) - Creates new rule called "route-traffic" with text of rule as supplied.



27
28
29
# File 'lib/api/catalogrule/CatalogRuleService.rb', line 27

def create(name, text)
  @driver.addRule([name], [text])
end

#delete(name) ⇒ Object

Deletes a rule

Args name (String) - Name of rule

Examples delete(name) - Deletes rule called "name"



112
113
114
# File 'lib/api/catalogrule/CatalogRuleService.rb', line 112

def delete(name)
  @driver.deleteRule([name])
end

#details(name) ⇒ Object

Fetches details about a rule

Args name (String) - Name of rule

Returns

Examples details(name) - returns CatalogRuleRuleInfo object for rule



126
127
128
# File 'lib/api/catalogrule/CatalogRuleService.rb', line 126

def details(name)
  @driver.getRuleDetails([name]).first
end

#errors(text) ⇒ Object

Returns a list of errors for the rule

Args text (String) - Rule text

Returns errors (Array) - Array of errors

Examples errors("text_of_rule")



70
71
72
73
# File 'lib/api/catalogrule/CatalogRuleService.rb', line 70

def errors(text)
  res = @driver.checkSyntax([text])
  return res.first.errors
end

#listObject

List rules by name

Args None

Examples list - Returns a list of rule names



39
40
41
# File 'lib/api/catalogrule/CatalogRuleService.rb', line 39

def list
  @driver.getRuleNames
end

#note(name, note = nil) ⇒ Object

Sets or returns the note for a rule

name (String)       - Name of rule
note (String)       - Text of note

Examples note(name, note) - Sets the note for a rule called "name" note(name) - Returns the note for the rule "name"



149
150
151
152
153
154
155
156
# File 'lib/api/catalogrule/CatalogRuleService.rb', line 149

def note(name, note=nil)
  if note.nil?
    details(name).rule_notes
  else
    @driver.setRuleNotes([name], [note])
  end

end

#rename(name, new_name) ⇒ Object

Renames a rule

name (String)       - Name of current rule
new_name (String)   - Name of new rule

Examples rename(name, new_name) - Copies rule called "name" to a new rule, called "new_name"



137
138
139
# File 'lib/api/catalogrule/CatalogRuleService.rb', line 137

def rename(name, new_name)
  @driver.renameRule([name], [new_name])
end

#text(name, text = nil) ⇒ Object

Sets or returns the text for a rule

name (String)       - Name of rule
text (String)       - Text of rule

Examples text(name, text) - Sets the text for a rule called "name" text(name) - Returns the text for the rule "name"



166
167
168
169
170
171
172
# File 'lib/api/catalogrule/CatalogRuleService.rb', line 166

def text(name, text=nil)
  if text.nil?
    details(name).rule_text
  else
    @driver.setRuleText([name], [text])
  end
end

#valid?(text) ⇒ Boolean

Checks whether the text of a rule is valid TrafficScript

Args text (String) - Rule text

Returns valid (boolean) - True if valid

Examples valid?("text_of_rule") - Calls a check on the rule, returns boolean

Returns:

  • (Boolean)


54
55
56
57
# File 'lib/api/catalogrule/CatalogRuleService.rb', line 54

def valid?(text)
  res = @driver.checkSyntax([text])
  return res.first.valid
end

#warnings(text) ⇒ Object

Returns a list of warnings for the rule

Args text (String) - Rule text

Returns warnings (Array) - Array of errors

Examples warnings("text_of_rule")



86
87
88
89
# File 'lib/api/catalogrule/CatalogRuleService.rb', line 86

def warnings(text)
  res = @driver.checkSyntax([text])
  return res.first.warnings
end