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

Returns a new instance of Connection.



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 23

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



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

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
60
61
# File 'lib/rfm/utilities/connection.rb', line 59

def host_name
  state[:host]
end

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



89
90
91
92
93
94
# File 'lib/rfm/utilities/connection.rb', line 89

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



67
68
69
# File 'lib/rfm/utilities/connection.rb', line 67

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

#schemeObject



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

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

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



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

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