Class: Rfm::Connection

Inherits:
Object show all
Includes:
Config
Defined in:
lib/rfm/utilities/connection.rb

Overview

})

Constant Summary

Constants included from Config

Rfm::Config::CONFIG_DONT_STORE, Rfm::Config::CONFIG_KEYS

Instance Method Summary collapse

Methods included from Config

#config, #config_clear, #get_config, #log

Constructor Details

#initialize(action, params, request_options = {}, *args) ⇒ Connection



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rfm/utilities/connection.rb', line 22

def initialize(action, params, request_options={},  *args)
  config *args
  
  # Action sent to FMS
  @action = action
  # Query params sent to FMS
  @params = params
  # Additional options sent to FMS
  @request_options = request_options
  
  @defaults = {
    :host => 'localhost',
    #:port => 80,
    :ssl => true,
    :root_cert => true,
    :root_cert_name => '',
    :root_cert_path => '/',
    :account_name => '',
    :password => '',
    :log_actions => false,
    :log_responses => false,
    :log_parser => false,
    :warn_on_redirect => true,
    :raise_on_401 => false,
    :timeout => 60,
    :ignore_bad_data => false,
    :grammar => 'fmresultset'
  }   #.merge(options)
  
end

Instance Method Details

#connect(action = @action, params = @params, request_options = @request_options, account_name = state[:account_name], password = state[:password]) ⇒ Object



61
62
63
64
65
66
# File 'lib/rfm/utilities/connection.rb', line 61

def connect(action=@action, params=@params, request_options = @request_options, =state[:account_name], password=state[:password])
  grammar_option = request_options.delete(:grammar)
  post = params.merge(expand_options(request_options)).merge({action => ''})
  grammar = select_grammar(post, :grammar=>grammar_option)
  http_fetch(host_name, port, "/fmi/xml/#{grammar}.xml", , password, post)
end

#host_nameObject



57
# File 'lib/rfm/utilities/connection.rb', line 57

def host_name; state[:host]; end

#parse(template = nil, initial_object = nil, parser = nil, options = {}) ⇒ Object



77
78
79
80
81
# File 'lib/rfm/utilities/connection.rb', line 77

def parse(template=nil, initial_object=nil, parser=nil, options={})
  (template =  'fmresultset.yml') unless template
  #(template = File.join(File.dirname(__FILE__), '../sax/', template)) if template.is_a? String
  Rfm::SaxParser.parse(connect.body, template, initial_object, parser, state(*options)).result
end

#portObject



59
# File 'lib/rfm/utilities/connection.rb', line 59

def port; state[:ssl] && state[:port].nil? ? 443 : state[:port]; end

#schemeObject



58
# File 'lib/rfm/utilities/connection.rb', line 58

def scheme; state[:ssl] ? "https" : "http"; end

#select_grammar(post, options = {}) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/rfm/utilities/connection.rb', line 68

def select_grammar(post, options={})
      grammar = state(options)[:grammar] || 'fmresultset'
      if grammar.to_s.downcase == 'auto'
post.keys.find(){|k| %w(-find -findall -dbnames -layoutnames -scriptnames).include? k.to_s} ? "FMPXMLRESULT" : "fmresultset"   
  else
    grammar
  end
end

#state(*args) ⇒ Object



53
54
55
# File 'lib/rfm/utilities/connection.rb', line 53

def state(*args)
  @defaults.merge(super(*args))
end