Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

correct api signature generation

  • Loading branch information...
commit f9a4571c8e66b36d4997efcbad2eaf0fe6cde618 1 parent 9d4e4b4
Nik Wakelin authored

Showing 2 changed files with 4 additions and 5 deletions. Show diff stats Hide diff stats

  1. +2 3 lib/realestate/client.rb
  2. +2 2 test/unit/client_test.rb
5 lib/realestate/client.rb
@@ -22,7 +22,6 @@ def suburbs
22 22
23 23 def request(method, path, params = {})
24 24 query = prepare_params(path, params).map { |x| x.join("=") }.join("&")
25   -
26 25 process_response(self.class.send(method, path, :query => query))
27 26 end
28 27
@@ -51,8 +50,8 @@ def calculate_api_sig(request_path, params_array)
51 50 # Sort your URL argument list into alphabetical (ASCII) order based on the parameter name and value. e.g. a=B, foo=1, bar=2, baz=P, baz=3 sorts to a=B, bar=2, baz=3, baz=P, foo=1
52 51 sorted_params = params_array.sort_by { |k, v| "#{k}-#{v}" }
53 52
54   - # Concatenate api secret, request base uri, request path, sorted params
55   - concatenated_string = [ self.private_key, self.class.base_uri, request_path, sorted_params.to_s ].join("/")
  53 + # Concatenate api secret, request path (no slashes as we're joining with those later), sorted params
  54 + concatenated_string = [ self.private_key, "#{Realestate::API_VERSION}", request_path.gsub("/", ""), sorted_params.to_s ].join("/")
56 55
57 56 Digest::MD5.hexdigest(concatenated_string)
58 57 end
4 test/unit/client_test.rb
@@ -27,13 +27,13 @@ class ClientTest < ActiveSupport::TestCase
27 27 api_sig = @client.send(:calculate_api_sig, "suburbs/", :a => 5)
28 28
29 29 # here's a signature I prepared earlier...
30   - assert_equal "139a0697e7cb5ecd7f989157831f2af1", api_sig
  30 + assert_equal "c742042c6a82e517ddd637e1ee027e2d", api_sig
31 31 end
32 32
33 33 should "order the params correctly" do
34 34 api_sig = @client.send(:calculate_api_sig, "suburbs/", :b => "Z", :a => [6, 3], "baz" => 45)
35 35
36   - assert_equal "d5e86b009fde203a7e600e6f9f94c8aa", api_sig
  36 + assert_equal "1500f0d54ae8bef8c10a9d42e9a694fb", api_sig
37 37 end
38 38
39 39 end

0 comments on commit f9a4571

Please sign in to comment.
Something went wrong with that request. Please try again.