Browse files

Introduce the notion of api_domain for configuration.

  • Loading branch information...
1 parent ed0d3eb commit bcc1fe38da8bba963f49461e0359f18b2da225da @luigi luigi committed Jun 24, 2010
Showing with 21 additions and 21 deletions.
  1. +1 −1 .gitignore
  2. +2 −0 README.md
  3. +1 −0 api.yml.example
  4. +0 −1 key.yml.example
  5. +12 −16 lib/transparency_data.rb
  6. +4 −2 test/helper.rb
  7. +1 −1 test/transparency_data_test.rb
View
2 .gitignore
@@ -1,5 +1,5 @@
.DS_Store
coverage/
dist/
-key.yml
+api.yml
*.gem
View
2 README.md
@@ -24,6 +24,8 @@ Within a Rails app, create a `config/initializers/transparency_data.rb` and stic
config.api_key = 'YOUR_KEY_HERE'
end
+Optionally, you can set `TransparencyData.api_domain` if you don't want to hit the production API at `transparencydata.com`.
+
## Usage
See the official [API docs](http://transparencydata.com/api/) for all parameters you can send in, and the [schema docs](http://transparencydata.com/docs/) for what you get back:
View
1 api.yml.example
@@ -0,0 +1 @@
+key: YOURKEYHERE
View
1 key.yml.example
@@ -1 +0,0 @@
-api_key: YOURKEYHERE
View
28 lib/transparency_data.rb
@@ -10,26 +10,11 @@ module TransparencyData
VERSION = "0.0.3".freeze
- # config/initializers/transparency_data.rb (for instance)
- #
- # TransparencyData.configure do |config|
- # config.api_key = 'api_key'
- # end
- #
def self.configure
yield self
true
end
- def self.api_url(endpoint, version = self.api_version)
- "http://transparencydata.com/api/#{version}#{endpoint}.json"
- end
-
- # class << self
- # attr_accessor :api_key
- # attr_accessor :api_version
- # end
-
def self.api_version
@api_version || "1.0"
end
@@ -45,7 +30,18 @@ def self.api_key
def self.api_key=(value)
@api_key = value
end
-
+
+ def self.api_domain
+ @api_domain || "transparencydata.com"
+ end
+
+ def self.api_domain=(value)
+ @api_domain = value
+ end
+
+ def self.api_url(endpoint, version = self.api_version)
+ "http://#{self.api_domain}/api/#{version}#{endpoint}.json"
+ end
end
View
6 test/helper.rb
@@ -13,8 +13,10 @@
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'transparency_data'
-config = YAML.load_file(File.dirname(__FILE__) + '/../key.yml')
-TransparencyData.api_key = config['api_key']
+api_config = YAML.load_file(File.dirname(__FILE__) + '/../api.yml')
+TransparencyData.api_key = api_config['key']
+TransparencyData.api_domain = api_config['domain'] if api_config['domain']
+
class Test::Unit::TestCase
end
View
2 test/transparency_data_test.rb
@@ -12,7 +12,7 @@ class TransparencyDataTest < Test::Unit::TestCase
end
should "provide helpers for URLs" do
- TransparencyData.api_url("/contributions").should == "http://transparencydata.com/api/1.0/contributions.json"
+ TransparencyData.api_url("/contributions").should == "http://#{TransparencyData.api_domain}/api/1.0/contributions.json"
end
end

0 comments on commit bcc1fe3

Please sign in to comment.