Created
April 16, 2009 05:40
-
-
Save practicingruby/96247 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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