Skip to content

Instantly share code, notes, and snippets.

@practicingruby
Created April 16, 2009 05:40
Show Gist options
  • Select an option

  • Save practicingruby/96247 to your computer and use it in GitHub Desktop.

Select an option

Save practicingruby/96247 to your computer and use it in GitHub Desktop.
require 'yaml'
require 'activeresource'
class ServiceLocator
API_KEY = "kittens"
def self.services
return @services if @services
config_file = File.join(RAILS_ROOT, %w[config services.yml])
config = YAML.load_file(config_file)
@services = config[RAILS_ENV]
end
def self.[](name)
services[name.to_s]
end
end
def Service(name)
Class.new(ActiveResource::Base) do
self.site = "http://#{ServiceLocator[name]}"
self.user = "api"
self.password = ServiceLocator::API_KEY
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment