Module: Arbor::Peakflow::Traffic
- Included in:
- Client
- Defined in:
- lib/arbor_peakflow_ruby/actions/traffic.rb
Overview
The Traffic module is for getting traffic data.
Instance Method Summary collapse
-
#encode_xml_for_url(file_contents) ⇒ Object
The encode_xml_for_url function allows you to encode an XML file’s content.
-
#traffic(query, graph = nil) ⇒ Object
The traffic function allows you to search for and retrieve XML traffic data.
Instance Method Details
#encode_xml_for_url(file_contents) ⇒ Object
The encode_xml_for_url function allows you to encode an XML file’s content. This is used automatically when calling the traffic method.
Parameters:
-
file_contents: The XML content which should be encoded into a URL
usable format.
Example
file = File.read('path/to/file.xml')
encoded_file_contents = client.encode_xml_for_url file
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/arbor_peakflow_ruby/actions/traffic.rb', line 46 def encode_xml_for_url(file_contents) encoded_file = URI.encode( file_contents .gsub!(/\n+/, '') .gsub!(/(\s+)(?![^<])/, '') ).gsub!(/\?/, '%3F') encoded_file end |
#traffic(query, graph = nil) ⇒ Object
The traffic function allows you to search for and retrieve XML traffic data.
Parameters:
-
query: An XML query in standard Peakflow SP XML query format. This
parameter is only the XML query, not an entire XML report. Data is returned in the XML result format, as specified in the _Peakflow SP and Threat Management System (TMS) User Guide_. For current report specifications, see “Using Cusomized Reports” in the _Peakflow SP and Threat Management System (TMS) User Guide_.
-
graph: (Optional) When specified, this parameter indicates that you
want Peakflow SP to return a binary PNG graph file of the queried traffic data. If you do not specify a graph argument, then Peakflow SP returns XML.
Example
query = File.read('path/to/file.xml')
response = client.traffic query
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/arbor_peakflow_ruby/actions/traffic.rb', line 24 def traffic(query, graph = nil) response = @conn.get do |req| req.url 'arborws/traffic' req.params['api_key'] = @api_key req.params['query'] = encode_xml_for_url(query) req.params['graph'] = encode_xml_for_url(graph) unless graph.nil? end response end |