Class: Rfm::Connection

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

Overview

These have been moved to rfm.rb. SaxParser.default_class = CaseInsensitiveHash SaxParser.template_prefix = File.join(File.dirname(__FILE__), './sax/') SaxParser.templates.merge!({ :fmpxmllayout => 'fmpxmllayout.yml', :fmresultset => 'fmresultset.yml', :fmpxmlresult => 'fmpxmlresult.yml', :none => nil })

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
52
# 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,
    :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


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

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


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

def host_name; state[:host]; end

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


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

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


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

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

#schemeObject


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

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

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


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

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


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

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