Class: Rfm::Server

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

Overview

The Database object represents a single FileMaker Pro database. When you retrieve a Database object from a server, its account name and password are set to the account name and password you used when initializing the Server object. You can override this of course:

myDatabase = myServer["Customers"]
myDatabase. = "foo"
myDatabase.password = "bar"

Accessing Layouts

All interaction with FileMaker happens through a Layout object. You can get a Layout object from the Database object like this:

myLayout = myDatabase["Details"]

This code gets the Layout object representing the layout called Details in the database.

Note: RFM does not talk to the server when you retrieve a Layout object in this way. Instead, it simply assumes you know what you're talking about. If the layout you specify does not exist, you will get no error at this point. Instead, you'll get an error when you use the Layout object methods to talk to FileMaker. This makes debugging a little less convenient, but it would introduce too much overhead to hit the server at this point.

The Database object has a layout attribute that provides alternate access to Layout objects. It acts like a hash of Layout objects, one for each accessible layout in the database. So, for example, you can do this if you want to print out a list of all layouts:

myDatabase.layout.each {|layout|
  puts layout.name
}

The Database::layout attribute is actually a LayoutFactory object, although it subclasses hash, so it should work in all the ways you expect. Note, though, that it is completely empty until the first time you attempt to access its elements. At that (lazy) point, it hits FileMaker, loads in the list of layouts, and constructs a Layout object for each one. In other words, it incurrs no overhead until you use it.

Accessing Scripts

If for some reason you need to enumerate the scripts in a database, you can do so:

myDatabase.script.each {|script|
  puts script.name
}

The Database::script attribute is actually a ScriptFactory object, although it subclasses hash, so it should work in all the ways you expect. Note, though, that it is completely empty until the first time you attempt to access its elements. At that (lazy) point, it hits FileMaker, loads in the list of scripts, and constructs a Script object for each one. In other words, it incurrs no overhead until you use it.

Note: You don't need a Script object to run a script (see the Layout object instead).

Attributes

In addition to the layout attribute, Server has a few other useful attributes:

  • server is the Server object this database comes from

  • name is the name of this database

  • state is a hash of all server options used to initialize this server

Constant Summary

Constant Summary

Constants included from Config

Config::CONFIG_DONT_STORE, Config::CONFIG_KEYS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Config

#config_clear, #get_config, #log, #state

Constructor Details

#initialize(*args) ⇒ Server

To create a Server object, you typically need at least a host name:

myServer = Rfm::Server.new({:host => 'my.host.com'})

Several other options are supported

  • host the hostname of the Web Publishing Engine (WPE) server (defaults to 'localhost')

  • port the port number the WPE is listening no (defaults to 80 unless ssl true which sets it to 443)

  • account_name the default account name to log in to databases with (you can also supply a account name on a per-database basis if necessary)

  • password the default password to log in to databases with (you can also supplly a password on a per-databases basis if necessary)

  • log_actions when true, RFM logs all action URLs that are sent to FileMaker server to stderr (defaults to false)

  • log_responses when true, RFM logs all raw XML responses (including headers) from FileMaker to stderr (defaults to false)

  • warn_on_redirect normally, RFM prints a warning to stderr if the Web Publishing Engine redirects (this can usually be fixed by using a different host name, which speeds things up); if you *don't* want this warning printed, set warn_on_redirect to true

  • raise_on_401 although RFM raises error when FileMaker returns error responses, it typically ignores FileMaker's 401 error (no records found) and returns an empty record set instead; if you prefer a raised error when a find produces no errors, set this option to true

SSL Options (SSL AND CERTIFICATE VERIFICATION ARE ON BY DEFAULT)

  • ssl false if you want to turn SSL (HTTPS) off when connecting to connect to FileMaker (default is true)

If you are using SSL and want to verify the certificate, use the following options:

  • root_cert true is the default. If you do not want to verify your SSL session, set this to false. You will want to turn this off if you are using a self signed certificate and do not have a certificate authority cert file. If you choose this option you will need to provide a cert root_cert_name and root_cert_path (if not in root directory).

  • root_cert_name name of pem file for certificate verification (Root cert from certificate authority who issued certificate. If self signed certificate do not use this option!!). You can download the entire bundle of CA Root Certificates from curl.haxx.se/ca/cacert.pem. Place the pem file in config directory.

  • root_cert_path path to cert file. (defaults to '/' if no path given)

Configuration Examples

Example to turn off SSL:

myServer = Rfm::Server.new({
        :host => 'localhost',
        :account_name => 'sample',
        :password => '12345',
        :ssl => false 
        })

Example using SSL without root_cert:

myServer = Rfm::Server.new({
        :host => 'localhost',
        :account_name => 'sample',
        :password => '12345',
        :root_cert => false 
        })

Example using SSL with root_cert at file root:

myServer = Rfm::Server.new({
         :host => 'localhost',
         :account_name => 'sample',
         :password => '12345',
         :root_cert_name => 'example.pem' 
         })

Example using SSL with root_cert specifying root_cert_path:

myServer = Rfm::Server.new({
         :host => 'localhost',
         :account_name => 'sample',
         :password => '12345',
         :root_cert_name => 'example.pem'
         :root_cert_path => '/usr/cert_file/'
         })


197
198
199
200
201
# File 'lib/rfm/server.rb', line 197

def initialize(*args)
	config(*args)
	raise Rfm::Error::RfmError.new(0, "New instance of Rfm::Server has no host name. Attempted name '#{state[:host]}'.") if state[:host].to_s == ''
  @databases = Rfm::Factory::DbFactory.new(self)
end

Instance Attribute Details

#databasesObject (readonly) Also known as: db

, :host_name, :port, :scheme, :state



220
221
222
# File 'lib/rfm/server.rb', line 220

def databases
  @databases
end

Instance Method Details

#config(*args) ⇒ Object



224
225
226
227
# File 'lib/rfm/server.rb', line 224

def config(*args)
	super(:capture_strings_with=>[:host, :account_name, :password]) 
	super(*args)
end

#host_nameObject



230
# File 'lib/rfm/server.rb', line 230

def host_name; state[:host]; end

#portObject



232
# File 'lib/rfm/server.rb', line 232

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

#schemeObject



231
# File 'lib/rfm/server.rb', line 231

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