Module: Queri::XmlClient

Defined in:
lib/queri/request.rb,
lib/queri/xml_client.rb

Defined Under Namespace

Classes: Request

Constant Summary collapse

@@server =
nil

Class Method Summary collapse

Class Method Details

.configObject



21
22
23
# File 'lib/queri/xml_client.rb', line 21

def self.config
  @config
end

.configure(opts = {}) ⇒ Object

Raises:

  • (ArgumentError)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/queri/xml_client.rb', line 25

def self.configure opts={}
  raise ArgumentError, "expected hash, got something else" if opts.class != Hash
  unless opts.empty?
    if (@valid_config_keys - opts.keys).any?
      puts "WARNING:  erroneous keys given to ::config. Acceptible keys include #{@valid_config_keys}"
    end
    if (opts.keys & @valid_config_keys).empty?
      raise ArgumentError, "erroneous keys given to ::config. Acceptible keys include #{@valid_config_keys}"
    else
      opts.each {|k,v| @config[k.to_sym] = v if @valid_config_keys.include?(k.to_sym)}
      @@server = XMLRPC::Client.new(host = @config[:host], path = @config[:path], port = @config[:port])
    end
  end
end

.configure_with(path_to_yaml_file) ⇒ Object

Raises:

  • (ArgumentError)


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

def self.configure_with path_to_yaml_file
  raise ArgumentError, "expected path to yaml file as string, got something else" if path_to_yaml_file.class != String
  begin
    config = YAML.load(IO.read(path_to_yaml_file))
  rescue Errno::ENOENT
    raise LoadError, "the specified configuration file could not be found"
  rescue Psych::SyntaxError
    raise LoadError, "the specified configuration file contains invalid syntax"
  end
  configure(config)
  @@server = XMLRPC::Client.new(host = @config[:host], path = @config[:path], port = @config[:port])
end

.send_request(*args) ⇒ Object

Raises:

  • (LoadError)


53
54
55
56
57
58
# File 'lib/queri/xml_client.rb', line 53

def self.send_request *args
  raise LoadError, "client configs not set. Assign by passing a hash to Queri.configure or a yaml file path to Queri.configure_with" if @@server.nil?
  request = Request.new(args)
  response = @@server.call(*request.parameters)
  return response[request.report.class.xml_code]
end