change-ruby 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/requests/client.rb +8 -4
- data/lib/resources/collection_resource.rb +1 -1
- data/lib/resources/resource.rb +5 -1
- data/test/member_resource_test.rb +17 -5
- metadata +1 -1
data/lib/requests/client.rb
CHANGED
@@ -17,12 +17,16 @@ module Change
|
|
17
17
|
|
18
18
|
params[:api_key] = @api_key
|
19
19
|
|
20
|
-
if resource.
|
20
|
+
if resource.needs_request_signature?(method)
|
21
21
|
params[:endpoint] = endpoint
|
22
22
|
params[:timestamp] = Time.now.utc.iso8601
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
if resource.needs_authorization?(action_or_collection)
|
25
|
+
auth_key_to_use = params.delete(:auth_key_to_use) || resource.auth_key
|
26
|
+
params[:rsig] = generate_rsig(params, auth_key_to_use['auth_key'])
|
27
|
+
else
|
28
|
+
params[:rsig] = generate_rsig(params)
|
29
|
+
end
|
26
30
|
end
|
27
31
|
|
28
32
|
response = send(method.to_s, final_url(endpoint), params)
|
@@ -57,7 +61,7 @@ module Change
|
|
57
61
|
HTTParty.post(url, { :body => params })
|
58
62
|
end
|
59
63
|
|
60
|
-
def generate_rsig(params, auth_key)
|
64
|
+
def generate_rsig(params, auth_key = nil)
|
61
65
|
body_to_digest = "#{post_body(params)}#{@secret_token}#{auth_key}"
|
62
66
|
Digest::SHA2.hexdigest(body_to_digest)
|
63
67
|
end
|
data/lib/resources/resource.rb
CHANGED
@@ -23,10 +23,14 @@ module Change
|
|
23
23
|
path.prepend('/')
|
24
24
|
end
|
25
25
|
|
26
|
-
def
|
26
|
+
def needs_request_signature?(method)
|
27
27
|
method != :get
|
28
28
|
end
|
29
29
|
|
30
|
+
def needs_authorization?(action = nil)
|
31
|
+
action != :auth_keys
|
32
|
+
end
|
33
|
+
|
30
34
|
def auth_key(key_number = 0)
|
31
35
|
@auth_keys[key_number]
|
32
36
|
end
|
@@ -33,16 +33,28 @@ describe 'MemberResource' do
|
|
33
33
|
@resource = TesterResource.new(@client)
|
34
34
|
end
|
35
35
|
|
36
|
-
describe '#
|
36
|
+
describe '#needs_request_signature?' do
|
37
37
|
|
38
38
|
it "should return true for :get" do
|
39
|
-
@resource.
|
39
|
+
@resource.needs_request_signature?(:get).must_equal false
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should return false for :post, :put, and :delete" do
|
43
|
-
@resource.
|
44
|
-
@resource.
|
45
|
-
@resource.
|
43
|
+
@resource.needs_request_signature?(:post).must_equal true
|
44
|
+
@resource.needs_request_signature?(:put).must_equal true
|
45
|
+
@resource.needs_request_signature?(:delete).must_equal true
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '#needs_authorization?' do
|
51
|
+
|
52
|
+
it "should return false for :auth_keys" do
|
53
|
+
@resource.needs_authorization?(:auth_keys).must_equal false
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should return true for no action" do
|
57
|
+
@resource.needs_authorization?.must_equal true
|
46
58
|
end
|
47
59
|
|
48
60
|
end
|