<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>certs/ssl_cert.pem</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,3 +1,8 @@
+0.5.0
+----
+  * ApiError is raised when API KEY was invalid (before did only return nil)
+  * ServerError is now seperated into ApiError and ServiceUnavailableError
+
 0.4.2
 ----
   * default IDs are strings, not integers, since RPX supports both</diff>
      <filename>CHANGELOG</filename>
    </modified>
    <modified>
      <diff>@@ -1,8 +1,7 @@
 Problem
 =======
- - OpenID is complex
- - OpenID is not universally used
- - Facebook / Myspace / MS-LiveId / AOL connections require different libraries and knowledge
+ - OpenID is complex, limited and hard to use for users
+ - Facebook / Twitter / Myspace / Google / MS-LiveId / AOL connections require different libraries and knowledge
  - Multiple heterogenouse providers are hard to map to a single user
 
 Solution
@@ -25,70 +24,59 @@ Install
 =======
  - As Rails plugin: `script/plugin install git://github.com/grosser/rpx_now.git `
  - As gem: `sudo gem install grosser-rpx_now --source http://gems.github.com/`
- - As gem from source: `git clone git://github.com/grosser/rpx_now.git`,`cd rpx_now &amp;&amp; rake install`
 
 Examples
 ========
 
 View
 ----
-    #login.erb
-    #here 'mywebsite' is your subdomain/realm on RPX
+    #'mywebsite' is your subdomain/realm on RPX
     &lt;%=RPXNow.embed_code('mywebsite',rpx_token_sessions_url)%&gt;
     OR
     &lt;%=RPXNow.popup_code('Login here...','mywebsite',rpx_token_sessions_url,:language=&gt;'de')%&gt;
 
-    (`popup_code` can also be called with `:unobstrusive=&gt;true`)
+`popup_code` can also be called with `:unobstrusive=&gt;true`
 
 Controller
 ----------
-    # simple: use defaults
-    # user_data returns e.g.
-    # {:name=&gt;'John Doe', :username =&gt; 'john', :email=&gt;'john@doe.com', :identifier=&gt;'blug.google.com/openid/dsdfsdfs3f3'}
-    # when no user_data was found (invalid token supplied), data is empty, you may want to handle that seperatly...
-    # your user model must have an identifier column
+    RPXNow.api_key = &quot;YOU RPX API KEY&quot;
+
+    # user_data
+    # found: {:name=&gt;'John Doe', :username =&gt; 'john', :email=&gt;'john@doe.com', :identifier=&gt;'blug.google.com/openid/dsdfsdfs3f3'}
+    # not found: nil (can happen with e.g. invalid tokens)
     def rpx_token
-      data = RPXNow.user_data(params[:token],'YOUR RPX API KEY')
+      raise &quot;hackers?&quot; unless data = RPXNow.user_data(params[:token])
       self.current_user = User.find_by_identifier(data[:identifier]) || User.create!(data)
       redirect_to '/'
     end
 
-    # process the raw response yourself:
-    RPXNow.user_data(params[:token],'YOUR RPX API KEY'){|raw| {:email=&gt;raw['profile']['verifiedEmail']}}
-
-    # request extended parameters (most users and APIs do not supply them)
-    RPXNow.user_data(params[:token],'YOUR RPX API KEY',:extended=&gt;'true'){|raw| ...have a look at the RPX API DOCS...}
+    # raw request processing
+    RPXNow.user_data(params[:token]){|raw| {:email=&gt;raw['profile']['verifiedEmail']} }
 
-    # you can provide the api key once, and leave it out on all following calls
-    RPXNow.api_key = 'YOUR RPX API KEY'
-    RPXNow.user_data(params[:token],:extended=&gt;'true')
+    # raw request with extended parameters (most users and APIs do not supply them)
+    RPXNow.user_data(params[:token], :extended=&gt;'true'){|raw| ...have a look at the RPX API DOCS...}
 
 Advanced
 --------
 ###Versions
-The version of RPXNow api can be set globally:
     RPXNow.api_version = 2
-Or local on each call:
-    RPXNow.mappings(primary_key, :api_version=&gt;1)
 
 ###Mappings
 You can map your primary keys (e.g. user.id) to identifiers, so that  
 users can login to the same account with multiple identifiers.
-    #add a mapping
-    RPXNow.map(identifier,primary_key,'YOUR RPX API KEY')
-
-    #remove a mapping
-    RPXNow.unmap(identifier,primary_key,'YOUR RPX API KEY')
-
-    #show mappings
-    RPXNow.mappings(primary_key,'YOUR RPX API KEY') # [identifier1,identifier2,...]
+    RPXNow.map(identifier, primary_key) #add a mapping
+    RPXNow.unmap(identifier, primary_key) #remove a mapping
+    RPXNow.mappings(primary_key) # [identifier1,identifier2,...]
 
 After a primary key is mapped to an identifier, when a user logs in with this identifier,  
 `RPXNow.user_data` will contain his `primaryKey` as `:id`.
 
 TODO
 ====
- - validate RPXNow.com SSL certificate
+ - add provider?
+ - add get_contacts (premium rpx service)
+ - add all_mappings
+
 
 Author
 ======</diff>
      <filename>README.markdown</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,4 @@
 --- 
-:minor: 4
-:patch: 2
+:minor: 5
+:patch: 0
 :major: 0</diff>
      <filename>VERSION.yml</filename>
    </modified>
    <modified>
      <diff>@@ -3,7 +3,10 @@ require 'json'
 module RPXNow
   extend self
 
-  attr_writer :api_key
+  HOST = 'rpxnow.com'
+  SSL_CERT = File.join(File.dirname(__FILE__), '..', 'certs', 'ssl_cert.pem')
+
+  attr_accessor :api_key
   attr_accessor :api_version
   self.api_version = 2
 
@@ -14,9 +17,9 @@ module RPXNow
     options = {:token=&gt;token,:apiKey=&gt;api_key}.merge options
 
     begin
-      data = secure_json_post(&quot;https://rpxnow.com/api/v#{version}/auth_info&quot;, options)
+      data = secure_json_post(&quot;/api/v#{version}/auth_info&quot;, options)
     rescue ServerError
-      return nil if $!.to_s =~ /token/ or $!.to_s=~/Data not found/
+      return nil if $!.to_s=~/Data not found/
       raise
     end
     if block_given? then yield(data) else read_user_data_from_response(data) end
@@ -26,27 +29,27 @@ module RPXNow
   def map(identifier, primary_key, *args)
     api_key, version, options = extract_key_version_and_options!(args)
     options = {:identifier=&gt;identifier,:primaryKey=&gt;primary_key,:apiKey=&gt;api_key}.merge options
-    secure_json_post(&quot;https://rpxnow.com/api/v#{version}/map&quot;, options)
+    secure_json_post(&quot;/api/v#{version}/map&quot;, options)
   end
 
   # un-maps an identifier to an primary-key (e.g. user.id)
   def unmap(identifier, primary_key, *args)
     api_key, version, options = extract_key_version_and_options!(args)
     options = {:identifier=&gt;identifier,:primaryKey=&gt;primary_key,:apiKey=&gt;api_key}.merge options
-    secure_json_post(&quot;https://rpxnow.com/api/v#{version}/unmap&quot;, options)
+    secure_json_post(&quot;/api/v#{version}/unmap&quot;, options)
   end
 
   # returns an array of identifiers which are mapped to one of your primary-keys (e.g. user.id)
   def mappings(primary_key, *args)
     api_key, version, options = extract_key_version_and_options!(args)
     options = {:primaryKey=&gt;primary_key,:apiKey=&gt;api_key}.merge options
-    data = secure_json_post(&quot;https://rpxnow.com/api/v#{version}/mappings&quot;, options)
+    data = secure_json_post(&quot;/api/v#{version}/mappings&quot;, options)
     data['identifiers']
   end
 
   def embed_code(subdomain,url)
 &lt;&lt;EOF
-&lt;iframe src=&quot;https://#{subdomain}.rpxnow.com/openid/embed?token_url=#{url}&quot;
+&lt;iframe src=&quot;https://#{subdomain}.#{HOST}/openid/embed?token_url=#{url}&quot;
   scrolling=&quot;no&quot; frameBorder=&quot;no&quot; style=&quot;width:400px;height:240px;&quot;&gt;
 &lt;/iframe&gt;
 EOF
@@ -64,16 +67,16 @@ EOF
 
   def unobtrusive_popup_code(text, subdomain, url, options={})
     version = extract_version! options
-    &quot;&lt;a class=\&quot;rpxnow\&quot; href=\&quot;https://#{subdomain}.rpxnow.com/openid/v#{version}/signin?token_url=#{url}\&quot;&gt;#{text}&lt;/a&gt;&quot;
+    &quot;&lt;a class=\&quot;rpxnow\&quot; href=\&quot;https://#{subdomain}.#{HOST}/openid/v#{version}/signin?token_url=#{url}\&quot;&gt;#{text}&lt;/a&gt;&quot;
   end
 
   def obtrusive_popup_code(text, subdomain, url, options = {})
     version = extract_version! options
     &lt;&lt;EOF
-&lt;a class=&quot;rpxnow&quot; onclick=&quot;return false;&quot; href=&quot;https://#{subdomain}.rpxnow.com/openid/v#{version}/signin?token_url=#{url}&quot;&gt;
+&lt;a class=&quot;rpxnow&quot; onclick=&quot;return false;&quot; href=&quot;https://#{subdomain}.#{HOST}/openid/v#{version}/signin?token_url=#{url}&quot;&gt;
   #{text}
 &lt;/a&gt;
-&lt;script src=&quot;https://rpxnow.com/openid/v#{version}/widget&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
+&lt;script src=&quot;https://#{HOST}/openid/v#{version}/widget&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
 &lt;script type=&quot;text/javascript&quot;&gt;
   //&lt;![CDATA[
   RPXNOW.token_url = &quot;#{url}&quot;;
@@ -115,51 +118,50 @@ EOF
     data = {}
     data[:identifier] = user_data['identifier']
     data[:email] = user_data['verifiedEmail'] || user_data['email']
-    data[:username] = user_data['preferredUsername'] || data[:email].sub(/@.*/,'')
+    data[:username] = user_data['preferredUsername'] || data[:email].to_s.sub(/@.*/,'')
     data[:name] = user_data['displayName'] || data[:username]
     data[:id] = user_data['primaryKey'] unless user_data['primaryKey'].to_s.empty?
     data
   end
 
-  def secure_json_post(url,data={})
-    data = JSON.parse(post(url,data))
-    raise ServerError.new(data['err']) if data['err']
-    raise ServerError.new(data.inspect) unless data['stat']=='ok'
-    data
+  def secure_json_post(path, data)
+    parse_response(post(path,data))
   end
 
-  def post(url,data)
+  def post(path, data)
     require 'net/http'
-    url = URI.parse(url)
-    http = Net::HTTP.new(url.host, url.port)
-    if url.scheme == 'https'
-      require 'net/https'
-      http.use_ssl = true
-      #TODO do we really want to verify the certificate? http://notetoself.vrensk.com/2008/09/verified-https-in-ruby/
-      http.verify_mode = OpenSSL::SSL::VERIFY_NONE
-    end
-    resp, data = http.post(url.path, to_query(data))
-    raise &quot;POST FAILED:&quot;+resp.inspect unless resp.is_a? Net::HTTPOK
-    data
+    require 'net/https'
+    request = Net::HTTP::Get.new(path)
+    request.form_data = data
+    make_request(request)
   end
 
-  def to_query(data = {})
-    return data.to_query if Hash.respond_to? :to_query
-    return &quot;&quot; if data.empty?
-
-    #simpler to_query
-    query_data = []
-    data.each do |k, v|
-      query_data &lt;&lt; &quot;#{k}=#{v}&quot;
-    end
-    
-    return query_data.join('&amp;')
+  def make_request(request)
+    http = Net::HTTP.new(HOST, 443)
+    http.use_ssl = true
+    http.ca_file = SSL_CERT
+    http.verify_mode = OpenSSL::SSL::VERIFY_PEER
+    http.verify_depth = 5
+    http.request(request)
   end
 
-  class ServerError &lt; Exception
-    #to_s returns message(which is a hash...)
-    def to_s
-      super.to_s
+  def parse_response(response)
+    if response.code.to_i &gt;= 400
+      raise ServiceUnavailableError, &quot;The RPX service is temporarily unavailable. (4XX)&quot;
+    else
+      result = JSON.parse(response.body)
+      return result unless result['err']
+      
+      code = result['err']['code']
+      if code == -1
+        raise ServiceUnavailableError, &quot;The RPX service is temporarily unavailable.&quot;
+      else
+        raise ApiError, &quot;Got error: #{result['err']['msg']} (code: #{code}), HTTP status: #{response.code}&quot;
+      end
     end
   end
+
+  class ServerError &lt; Exception; end #backwards compatibility / catch all
+  class ApiError &lt; ServerError; end
+  class ServiceUnavailableError &lt; ServerError; end
 end</diff>
      <filename>lib/rpx_now.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,11 +2,11 @@
 
 Gem::Specification.new do |s|
   s.name = %q{rpx_now}
-  s.version = &quot;0.4.2&quot;
+  s.version = &quot;0.5.0&quot;
 
   s.required_rubygems_version = Gem::Requirement.new(&quot;&gt;= 0&quot;) if s.respond_to? :required_rubygems_version=
   s.authors = [&quot;Michael Grosser&quot;]
-  s.date = %q{2009-05-22}
+  s.date = %q{2009-06-17}
   s.email = %q{grosser.michael@gmail.com}
   s.extra_rdoc_files = [
     &quot;README.markdown&quot;
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
   s.homepage = %q{http://github.com/grosser/rpx_now}
   s.rdoc_options = [&quot;--charset=UTF-8&quot;]
   s.require_paths = [&quot;lib&quot;]
-  s.rubygems_version = %q{1.3.2}
+  s.rubygems_version = %q{1.3.1}
   s.summary = %q{Helper to simplify RPX Now user login/creation}
   s.test_files = [
     &quot;spec/rpx_now_spec.rb&quot;,
@@ -32,7 +32,7 @@ Gem::Specification.new do |s|
 
   if s.respond_to? :specification_version then
     current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
-    s.specification_version = 3
+    s.specification_version = 2
 
     if Gem::Version.new(Gem::RubyGemsVersion) &gt;= Gem::Version.new('1.2.0') then
       s.add_runtime_dependency(%q&lt;activesupport&gt;, [&quot;&gt;= 0&quot;])</diff>
      <filename>rpx_now.gemspec</filename>
    </modified>
    <modified>
      <diff>@@ -5,14 +5,14 @@ API_VERSION = RPXNow.api_version
 
 describe RPXNow do
   before do
-    RPXNow.api_key = nil
+    RPXNow.api_key = API_KEY
     RPXNow.api_version = API_VERSION
   end
 
   describe :api_key= do
     it &quot;stores the api key, so i do not have to supply everytime&quot; do
       RPXNow.api_key='XX'
-      RPXNow.expects(:post).with{|x,data|data[:apiKey]=='XX'}.returns %Q({&quot;stat&quot;:&quot;ok&quot;})
+      RPXNow.expects(:post).with{|x,data|data[:apiKey]=='XX'}.returns mock(:code=&gt;'200', :body=&gt;%Q({&quot;stat&quot;:&quot;ok&quot;}))
       RPXNow.mappings(1)
     end
   end
@@ -62,50 +62,77 @@ describe RPXNow do
   end
 
   describe :user_data do
+    before do
+      @response_body = %Q({&quot;profile&quot;:{&quot;verifiedEmail&quot;:&quot;grosser.michael@googlemail.com&quot;,&quot;displayName&quot;:&quot;Michael Grosser&quot;,&quot;preferredUsername&quot;:&quot;grosser.michael&quot;,&quot;identifier&quot;:&quot;https:\/\/www.google.com\/accounts\/o8\/id?id=AItOawmaOlyYezg_WfbgP_qjaUyHjmqZD9qNIVM&quot;,&quot;email&quot;:&quot;grosser.michael@gmail.com&quot;},&quot;stat&quot;:&quot;ok&quot;})
+      @fake_user_data = {'profile'=&gt;{}}
+    end
+
     def fake_response
-      %Q({&quot;profile&quot;:{&quot;verifiedEmail&quot;:&quot;grosser.michael@googlemail.com&quot;,&quot;displayName&quot;:&quot;Michael Grosser&quot;,&quot;preferredUsername&quot;:&quot;grosser.michael&quot;,&quot;identifier&quot;:&quot;https:\/\/www.google.com\/accounts\/o8\/id?id=AItOawmaOlyYezg_WfbgP_qjaUyHjmqZD9qNIVM&quot;,&quot;email&quot;:&quot;grosser.michael@gmail.com&quot;},&quot;stat&quot;:&quot;ok&quot;})
+      mock(:code=&gt;&quot;200&quot;,:body=&gt;@response_body)
     end
     
-    it &quot;is empty when used with an invalid token&quot; do
-      RPXNow.user_data('xxxx',API_KEY).should == nil
+    it &quot;raises ApiError when used with an invalid token&quot; do
+      lambda{
+        RPXNow.user_data('xxxx')
+      }.should raise_error(RPXNow::ApiError)
     end
     
     it &quot;is empty when used with an unknown token&quot; do
-      RPXNow.user_data('60d8c6374f4e9d290a7b55f39da7cc6435aef3d3',API_KEY).should == nil
+      RPXNow.user_data('60d8c6374f4e9d290a7b55f39da7cc6435aef3d3').should == nil
     end
     
     it &quot;parses JSON response to user data&quot; do
       RPXNow.expects(:post).returns fake_response
-      RPXNow.user_data('','x').should == {:name=&gt;'Michael Grosser',:email=&gt;'grosser.michael@googlemail.com',:identifier=&gt;&quot;https://www.google.com/accounts/o8/id?id=AItOawmaOlyYezg_WfbgP_qjaUyHjmqZD9qNIVM&quot;, :username =&gt; 'grosser.michael'}
+      RPXNow.user_data('').should == {:name=&gt;'Michael Grosser',:email=&gt;'grosser.michael@googlemail.com',:identifier=&gt;&quot;https://www.google.com/accounts/o8/id?id=AItOawmaOlyYezg_WfbgP_qjaUyHjmqZD9qNIVM&quot;, :username =&gt; 'grosser.michael'}
     end
     
     it &quot;adds a :id when primaryKey was returned&quot; do
-      RPXNow.expects(:post).returns fake_response.sub(%Q(&quot;verifiedEmail&quot;), %Q(&quot;primaryKey&quot;:&quot;2&quot;,&quot;verifiedEmail&quot;))
-      RPXNow.user_data('','x')[:id].should == '2'
+      @response_body.sub!(%Q(&quot;verifiedEmail&quot;), %Q(&quot;primaryKey&quot;:&quot;2&quot;,&quot;verifiedEmail&quot;))
+      RPXNow.expects(:post).returns fake_response
+      RPXNow.user_data('')[:id].should == '2'
     end
 
     it &quot;handles primaryKeys that are not numeric&quot; do
-      RPXNow.expects(:post).returns fake_response.sub(%Q(&quot;verifiedEmail&quot;), %Q(&quot;primaryKey&quot;:&quot;dbalatero&quot;,&quot;verifiedEmail&quot;))
-      RPXNow.user_data('','x')[:id].should == 'dbalatero'
+      @response_body.sub!(%Q(&quot;verifiedEmail&quot;), %Q(&quot;primaryKey&quot;:&quot;dbalatero&quot;,&quot;verifiedEmail&quot;))
+      RPXNow.expects(:post).returns fake_response
+      RPXNow.user_data('')[:id].should == 'dbalatero'
     end
     
     it &quot;hands JSON response to supplied block&quot; do
-      RPXNow.expects(:post).returns %Q({&quot;x&quot;:&quot;1&quot;,&quot;stat&quot;:&quot;ok&quot;})
+      RPXNow.expects(:post).returns mock(:code=&gt;'200',:body=&gt;%Q({&quot;x&quot;:&quot;1&quot;,&quot;stat&quot;:&quot;ok&quot;}))
       response = nil
-      RPXNow.user_data('','x'){|data| response = data}
+      RPXNow.user_data(''){|data| response = data}
       response.should == {&quot;x&quot; =&gt; &quot;1&quot;, &quot;stat&quot; =&gt; &quot;ok&quot;}
     end
     
     it &quot;returns what the supplied block returned&quot; do
-      RPXNow.expects(:post).returns %Q({&quot;x&quot;:&quot;1&quot;,&quot;stat&quot;:&quot;ok&quot;})
-      RPXNow.user_data('','x'){|data| &quot;x&quot;}.should == 'x'
+      RPXNow.expects(:post).returns mock(:code=&gt;'200',:body=&gt;%Q({&quot;x&quot;:&quot;1&quot;,&quot;stat&quot;:&quot;ok&quot;}))
+      RPXNow.user_data(''){|data| &quot;x&quot;}.should == 'x'
     end
     
     it &quot;can send additional parameters&quot; do
       RPXNow.expects(:post).with{|url,data|
         data[:extended].should == 'true'
       }.returns fake_response
-      RPXNow.user_data('','x',:extended=&gt;'true')
+      RPXNow.user_data('',:extended=&gt;'true')
+    end
+
+    it &quot;works with api key as 2nd parameter (backwards compatibility)&quot; do
+      RPXNow.expects(:secure_json_post).with('/api/v2/auth_info', :apiKey=&gt;'THE KEY', :token=&gt;'id').returns @fake_user_data
+      RPXNow.user_data('id', 'THE KEY')
+      RPXNow.api_key.should == API_KEY
+    end
+
+    it &quot;works with api key as 2nd parameter and options (backwards compatibility)&quot; do
+      RPXNow.expects(:secure_json_post).with('/api/v2/auth_info', :apiKey=&gt;'THE KEY', :extended=&gt;'abc', :token=&gt;'id' ).returns @fake_user_data
+      RPXNow.user_data('id', 'THE KEY', :extended=&gt;'abc')
+      RPXNow.api_key.should == API_KEY
+    end
+
+    it &quot;works with api version as option (backwards compatibility)&quot; do
+      RPXNow.expects(:secure_json_post).with('/api/v123/auth_info', :apiKey=&gt;API_KEY, :token=&gt;'id', :extended=&gt;'abc').returns @fake_user_data
+      RPXNow.user_data('id', :extended=&gt;'abc', :api_version=&gt;123)
+      RPXNow.api_version.should == API_VERSION
     end
   end
 
@@ -119,45 +146,56 @@ describe RPXNow do
     end
   end
 
-  describe :secure_json_post do
+  describe :parse_response do
     it &quot;parses json when status is ok&quot; do
-      RPXNow.expects(:post).returns %Q({&quot;stat&quot;:&quot;ok&quot;,&quot;data&quot;:&quot;xx&quot;})
-      RPXNow.send(:secure_json_post, %Q(&quot;yy&quot;))['data'].should == &quot;xx&quot;
+      response = mock(:code=&gt;'200', :body=&gt;%Q({&quot;stat&quot;:&quot;ok&quot;,&quot;data&quot;:&quot;xx&quot;}))
+      RPXNow.send(:parse_response, response)['data'].should == &quot;xx&quot;
     end
-    
+
     it &quot;raises when there is a communication error&quot; do
-      RPXNow.expects(:post).returns %Q({&quot;err&quot;:&quot;wtf&quot;,&quot;stat&quot;:&quot;ok&quot;})
-      lambda{RPXNow.send(:secure_json_post,'xx')}.should raise_error(RPXNow::ServerError)
+      response = stub(:code=&gt;'200', :body=&gt;%Q({&quot;err&quot;:&quot;wtf&quot;,&quot;stat&quot;:&quot;ok&quot;}))
+      lambda{
+        RPXNow.send(:parse_response,response)
+      }.should raise_error(RPXNow::ApiError)
     end
-    
-    it &quot;raises when status is not ok&quot; do
-      RPXNow.expects(:post).returns %Q({&quot;stat&quot;:&quot;err&quot;})
-      lambda{RPXNow.send(:secure_json_post,'xx')}.should raise_error(RPXNow::ServerError)
+
+    it &quot;raises when service has downtime&quot; do
+      response = stub(:code=&gt;'200', :body=&gt;%Q({&quot;err&quot;:{&quot;code&quot;:-1},&quot;stat&quot;:&quot;ok&quot;}))
+      lambda{
+        RPXNow.send(:parse_response,response)
+      }.should raise_error(RPXNow::ServiceUnavailableError)
+    end
+
+    it &quot;raises when service is down&quot; do
+      response = stub(:code=&gt;'400',:body=&gt;%Q({&quot;stat&quot;:&quot;err&quot;}))
+      lambda{
+        RPXNow.send(:parse_response,response)
+      }.should raise_error(RPXNow::ServiceUnavailableError)
     end
   end
 
   describe :mappings do
     it &quot;parses JSON response to unmap data&quot; do
-      RPXNow.expects(:post).returns %Q({&quot;stat&quot;:&quot;ok&quot;, &quot;identifiers&quot;: [&quot;http://test.myopenid.com/&quot;]})
+      RPXNow.expects(:post).returns mock(:code=&gt;'200',:body=&gt;%Q({&quot;stat&quot;:&quot;ok&quot;, &quot;identifiers&quot;: [&quot;http://test.myopenid.com/&quot;]}))
       RPXNow.mappings(1, &quot;x&quot;).should == [&quot;http://test.myopenid.com/&quot;]
     end
   end
 
   describe :map do
     it &quot;adds a mapping&quot; do
-      RPXNow.expects(:post).returns %Q({&quot;stat&quot;:&quot;ok&quot;})
+      RPXNow.expects(:post).returns mock(:code=&gt;'200',:body=&gt;%Q({&quot;stat&quot;:&quot;ok&quot;}))
       RPXNow.map('http://test.myopenid.com',1, API_KEY)
     end
   end
 
   describe :unmap do
     it &quot;unmaps a indentifier&quot; do
-      RPXNow.expects(:post).returns %Q({&quot;stat&quot;:&quot;ok&quot;})
+      RPXNow.expects(:post).returns mock(:code=&gt;'200',:body=&gt;%Q({&quot;stat&quot;:&quot;ok&quot;}))
       RPXNow.unmap('http://test.myopenid.com', 1, &quot;x&quot;)
     end
 
     it &quot;can be called with a specific version&quot; do
-      RPXNow.expects(:secure_json_post).with{|a,b|a == &quot;https://rpxnow.com/api/v300/unmap&quot;}
+      RPXNow.expects(:secure_json_post).with{|a,b|a == &quot;/api/v300/unmap&quot;}
       RPXNow.unmap('http://test.myopenid.com', 1, :api_key=&gt;'xxx', :api_version=&gt;300)
     end
   end
@@ -192,15 +230,4 @@ describe RPXNow do
       RPXNow.mappings(1,API_KEY).should == [@k1]
     end
   end
-  
-  describe :to_query do
-    it &quot;should not depend on active support&quot; do
-      RPXNow.send('to_query', {:one =&gt; &quot; abc&quot;}).should == &quot;one= abc&quot;
-    end
-    
-    it &quot;should use ActiveSupport core extensions&quot; do
-      require 'activesupport'
-      RPXNow.send('to_query', {:one =&gt; &quot; abc&quot;}).should == &quot;one=+abc&quot;
-    end
-  end
-end
+end
\ No newline at end of file</diff>
      <filename>spec/rpx_now_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>74b5a8b054ae394960f4b4112c2549a9156fe13e</id>
    </parent>
  </parents>
  <author>
    <name>grosser</name>
    <email>grosser.michael@gmail.com</email>
  </author>
  <url>http://github.com/grosser/rpx_now/commit/80c77e44aea164860d65d3898b3960f05e6ca985</url>
  <id>80c77e44aea164860d65d3898b3960f05e6ca985</id>
  <committed-date>2009-06-17T11:13:25-07:00</committed-date>
  <authored-date>2009-06-17T11:13:25-07:00</authored-date>
  <message>merge conflic and now everything is one big commit :&lt;</message>
  <tree>5069fe657db18f01956e55b8a721ceff924e739f</tree>
  <committer>
    <name>grosser</name>
    <email>grosser.michael@gmail.com</email>
  </committer>
</commit>
