Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Allows for per-user credentials for ActiveResource connections
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
example/authenticated_resource_example
.gitignore
MIT-LICENSE
README
Rakefile
init.rb
install.rb
uninstall.rb

README

HasOneAuthenticatedResource
=========================

This plugin allows you to access resources using ActiveResource without needing a static single set of credentials.  Credentials can be pulled in from the database (or anywhere else) and can be different depending on the model instance doing the request.

Example
=======

create_table :accounts, do |t|
  t.string   "tracker_token"
  t.string   "tempo_user"
  t.string   "tempo_password"
  t.string   "blinksale_user"
  t.string   "blinksale_password"
  t.string   "highrise_token"
  t.timestamps
end


class Account < ActiveRecord::Base
  has_one_authenticated_resource :tracker_projects, :headers => { 'X-TrackerToken' => :tracker_token }
  has_one_authenticated_resource :tracker_stories,  :headers => { 'X-TrackerToken' => :tracker_token }
  
  has_one_authenticated_resource :tempo_entries,  :user => :tempo_user, :password => :tempo_password
  has_one_authenticated_resource :tempo_projects, :user => :tempo_user, :password => :tempo_password
  has_one_authenticated_resource :tempo_reports,  :user => :tempo_user, :password => :tempo_password
  
  has_one_authenticated_resource :highrise_emails, :site => :highrise_site
  has_one_authenticated_resource :highrise_kases,  :site => :highrise_site
  
  has_one_authenticated_resource :blinksale_invoices, :user => :blinksale_user, :password => :blinksale_password
  has_one_authenticated_resource :blinksale_clients, :user => :blinksale_user, :password => :blinksale_password

  private
  def highrise_site
    "http://#{self.highrise_token}.highrisehq.com/"
  end
  
end

#find all the tracker projects that the credentials for the first account have access to
Account.first.tracker_projects.find(:all)


Copyright (c) 2010 Expected Behavior, released under the MIT license

# need to deal with belongs_to
Something went wrong with that request. Please try again.