Notes on ScopePort

Tag: ruby

How to use Rails SMTP configuration parameters from database

by Lennart on Jul.26, 2009, under Ruby On Rails

Usually the Rails SMTP configuration takes place in config/environment.rb like this:

ActionMailer::Base.smtp_settings = {
  :address => "smtp.gmail.com",
  :port => 587,
  :domain => "domain.com",
  :user_name => "user@domain.com",
  :password => "password",
  :authentication => :plain
}

ScopePort already has a Email settings part in the setup section where all the required SMTP settings are stored. I wanted to fetch the SMTP configuration from the database to avoid double configuration. I stumbled over this blog post after a while: http://broadcast.oreilly.com/2009/03/using-multiple-smtp-accounts-w.html Based on this I developed the following dynamic way to define the SMTP settings:

class EmergencyMailer < ActionMailer::Base   
  def load_settings
    @@smtp_settings = {
      :address => Setting.first.mail_server,
      :port => Setting.first.mail_port,
      :domain => Setting.first.mail_hostname,
      :authentication => :plain,
      :user_name => Setting.first.mail_user,
      :password =>Setting.first.mail_pass
    }
  end
 
  def emergency_notification(emergency, email)
    load_settings
    recipients  email
    from        Setting.first.mail_from
    subject     "[ScopePort] An emergency has been declared!"
    sent_on     Time.now
    body        :emergency => emergency
  end
end

The method load_settings gets called by the delivery method and fills the smtp_settings instance variable with parameters from the database.

Check out this Rails Guide if you want to learn more about ActionMailer: http://guides.rubyonrails.org/action_mailer_basics.html

1 Comment :, , , , , , more...

ScopePort client now available via Rubygems

by Lennart on Jun.15, 2009, under ScopePort

You can now install the latest version of the ScopePort client via Rubygems. The gem is hosted at GitHub so you have to add GitHub as a repository first:

root@sundaysister# gem sources -a http://gems.github.com

You can now install the ScopePort client:

root@sundaysister# gem install lennartkoopmann-scopeport-client-ruby

Just start the client with “scopeport-client” if the gem binaries are in your $PATH.

Note that the current client version can only connect to a ScopePort server. It does not send real sensor data yet.

Leave a Comment :, , , more...

ScopePort sample client written in Ruby

by Lennart on Jun.12, 2009, under ScopePort

I just pushed a first ScopePort sample client to our repositories. It is written in Ruby, connects to a ScopePort server, logs in and sends a sample sensor data package.

See the source code here: http://github.com/lennartkoopmann/scopeport-client-ruby/blob/665e4d69a93c73fd8055511aae55e88afcfb42c2/scopeport-client.rb

The ScopePort protocol for logging in and sending sensor data is described here: http://scopeport.org/docs/host_communications

Hey, by the way: ScopePort is now on Twitter!

Leave a Comment :, , , more...

extconf.rb:1:in `require’: no such file to load

by Lennart on Jan.09, 2009, under Uncategorized

When a gem installation fails with something like “extconf.rb:1:in `require’: no such file to load” you are probably missing the ruby development packages.

On Ubuntu you can fix this by installing the ruby1.8-dev package. (sudo aptitude install ruby1.8-dev)

2 Comments :, , , , , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!