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

Returns a new instance of 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
52
53
# 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,
    :proxy=>false,  # array of (p_addr, p_port = nil, p_user = nil, p_pass = nil)
    :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,
    :template => :fmresultset,
    :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



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

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



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

def host_name; state[:host]; end

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



81
82
83
84
85
86
# File 'lib/rfm/utilities/connection.rb', line 81

def parse(template=nil, initial_object=nil, parser=nil, options={})
	template ||= state[:template]
	#(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



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

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

#schemeObject



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

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

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



70
71
72
73
74
75
76
77
78
79
# File 'lib/rfm/utilities/connection.rb', line 70

def select_grammar(post, options={})
			grammar = state(options)[:grammar] || 'fmresultset'
			if grammar.to_s.downcase == 'auto'
# TODO: Build grammar parser in new sax engine templates to handle FMPXMLRESULT.
return "fmresultset"
post.keys.find(){|k| %w(-find -findall -dbnames -layoutnames -scriptnames).include? k.to_s} ? "FMPXMLRESULT" : "fmresultset"   
	else
		grammar
	end
end

#state(*args) ⇒ Object



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

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