class Ratal
Constants
- CONTENT_TYPE
- USER_AGENT
Attributes
api_base[R]
api_target[R]
Public Class Methods
new(api_base, provider = NetHTTPProvider.new)
click to toggle source
# File lib/ratal.rb, line 12 def initialize(api_base, provider = NetHTTPProvider.new) @api_base = api_base @provider = provider api_string = 'api/api.php' @api_target = @api_base # Make sure it starts with http:// @api_base.prepend 'http://' unless @api_target =~ /^[a-z]+:\/\// # If it already has the api string on it, skip it return if @api_target.end_with? api_string # Make sure it ends with '/' @api_base.concat '/' unless @api_target.end_with? '/' # Make sure it ends with api/api.php @api_base.concat api_string end
Public Instance Methods
connect(username, password)
click to toggle source
# File lib/ratal.rb, line 37 def connect(username, password) call_method 'Logon', 'Logon', 'vtku', Username: username, Password: password end
settings()
click to toggle source
# File lib/ratal.rb, line 33 def settings call_method 'GetSettings', 'ServerSettings', 'vtku' end
Protected Instance Methods
call(data)
click to toggle source
# File lib/ratal.rb, line 56 def call(data) # noinspection RubyStringKeysInHashInspection headers = { 'User-Agent': USER_AGENT, 'Content-Type': CONTENT_TYPE } uri = URI(api_target) @provider.request(uri, headers, data) end
call_method(command, target, key, options = {})
click to toggle source
# File lib/ratal.rb, line 45 def call_method(command, target, key, options = {}) params = {'Command': command, 'FileName': target, 'Key': key} str = call params.merge(options) doc = REXML::Document.new(str) result = process_element(doc.root) result end
process_element(elem)
click to toggle source
# File lib/ratal.rb, line 67 def process_element(elem) result = {} children = elem.elements if children.empty? return elem.text else children.each do |e| result[symbolize e.name] = process_element(e) end end result end
symbolize(str)
click to toggle source
# File lib/ratal.rb, line 83 def symbolize(str) str.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2'). gsub(/([a-z\d])([A-Z])/, '\1_\2'). tr('- ', '_'). downcase. to_sym end