Permalink
Browse files

Now passing the new API key with all calls. I've included my own API …

…key with the unit tests (in a separate file 'api_key') I didn't think it was worth leaving the unit tests without an key.
  • Loading branch information...
1 parent f1f009c commit 16b63fe779b2c5d1fd1efb2295d5efd613a9eb2b Martin Owen committed Aug 3, 2008
Showing with 24 additions and 11 deletions.
  1. +2 −1 History.txt
  2. +1 −0 Manifest.txt
  3. +5 −2 README.txt
  4. +4 −3 lib/twfy.rb
  5. +1 −0 test/api_key
  6. +5 −2 test/test_twfy.rb
  7. +6 −3 test/test_twfy_chain.rb
View
@@ -1,5 +1,6 @@
-== 1.1.0 / 2008-08-02
+== 1.0.1 / 2008-08-02
+* In the near future the TWFY API will require an API Key for all calls. In preparation for this, this binding now requires an API Key. They are available at http://www.theyworkforyou.com/api/key
* Added support for new features of TWFY API (still version 1.0.0).
* getMLAs - Members of the Legislative Assembly (Members of the Northern Irish Assembly to you and me)
* getMSPs - Members of the Scottish Parliament
View
@@ -6,3 +6,4 @@ lib/data_element.rb
lib/twfy.rb
test/test_twfy.rb
test/test_twfy_chain.rb
+test/api_key
View
@@ -1,6 +1,6 @@
twfy
by Bruce Williams (http://codefluency.com)
- and Martin Owen
+ and Martin Owen (http://martinowen.net)
== DESCRIPTION:
@@ -34,7 +34,10 @@ Use is very easy.
=== Get a Client
require 'twfy'
- client = Twfy::Client.new
+ client = Twfy::Client.new(<YOUR API KEY HERE>)
+
+Note that the Twfy::Client constructor in version 1.0.1 of the binding requires an API Key
+string. If you don't have one they are available at http://www.theyworkforyou.com/api/key
=== Call API methods directly on client
View
@@ -9,7 +9,7 @@
module Twfy
- VERSION = '1.1.0'
+ VERSION = '1.0.1'
BASE = URI.parse('http://www.theyworkforyou.com/api/')
API_VERSION = '1.0.0'
@@ -20,7 +20,8 @@ class Error < ::StandardError; end
class ServiceArgumentError < ::ArgumentError; end
class APIError < ::StandardError; end
- def initialize(log_to=$stderr)
+ def initialize(api_key, log_to=$stderr)
+ @api_key = api_key
@logger = Logger.new(log_to)
end
@@ -173,7 +174,7 @@ def structure(value, target)
end
def build_query(params)
- params.update(:version=>API_VERSION)
+ params.update(:key=>@api_key, :version=>API_VERSION)
params.map{|set| set.map{|i| CGI.escape(i.to_s)}.join('=') }.join('&')
end
View
@@ -0,0 +1 @@
+B47i8vFYfgWvAa89eYErLWPF
View
@@ -2,9 +2,12 @@
require File.join(File.dirname(__FILE__), '../lib/twfy')
class BasicReturnedDataTest < Test::Unit::TestCase
-
+
+ API_KEY_LOCATION = File.join(File.dirname(__FILE__), 'api_key')
+
def setup
- @client = Twfy::Client.new
+ api_key = File.open(API_KEY_LOCATION){ |f| f.readlines[0].chomp }
+ @client = Twfy::Client.new(api_key)
end
def test_convert_url
View
@@ -2,9 +2,12 @@
require File.join(File.dirname(__FILE__), '../lib/twfy')
class ChainDataTest < Test::Unit::TestCase
-
+
+ API_KEY_LOCATION = File.join(File.dirname(__FILE__), 'api_key')
+
def setup
- @client = Twfy::Client.new
+ api_key = File.open(API_KEY_LOCATION){ |f| f.readlines[0].chomp }
+ @client = Twfy::Client.new(api_key)
@mp = @client.mp(:postcode=>'IP6 9PN')
end
@@ -46,4 +49,4 @@ def test_simple_chain_and_direct_call_are_equivalent
end
end
-
+

0 comments on commit 16b63fe

Please sign in to comment.