Class: Rfm::Connection
- 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
- #connect(action = @action, params = @params, request_options = @request_options, account_name = state[:account_name], password = state[:password]) ⇒ Object
- #host_name ⇒ Object
-
#initialize(action, params, request_options = {}, *args) ⇒ Connection
constructor
A new instance of Connection.
- #parse(template = nil, initial_object = nil, parser = nil, options = {}) ⇒ Object
- #port ⇒ Object
- #scheme ⇒ Object
- #select_grammar(post, options = {}) ⇒ Object
- #state(*args) ⇒ Object
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 |
# File 'lib/rfm/utilities/connection.rb', line 22 def initialize(action, params, ={}, *args) config *args # Action sent to FMS @action = action # Query params sent to FMS @params = params # Additional options sent to FMS @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, account_name=state[:account_name], password=state[:password]) grammar_option = .delete(:grammar) post = params.merge(()).merge({action => ''}) grammar = select_grammar(post, :grammar=>grammar_option) http_fetch(host_name, port, "/fmi/xml/#{grammar}.xml", account_name, password, post) end |
#host_name ⇒ Object
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, ={}) (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(*)).result end |
#port ⇒ Object
59 |
# File 'lib/rfm/utilities/connection.rb', line 59 def port; state[:ssl] && state[:port].nil? ? 443 : state[:port]; end |
#scheme ⇒ Object
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, ={}) grammar = state()[: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 |