change-ruby 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,12 +17,16 @@ module Change
17
17
 
18
18
  params[:api_key] = @api_key
19
19
 
20
- if resource.needs_authorization?(method)
20
+ if resource.needs_request_signature?(method)
21
21
  params[:endpoint] = endpoint
22
22
  params[:timestamp] = Time.now.utc.iso8601
23
23
 
24
- auth_key_to_use = params.delete(:auth_key_to_use)
25
- params[:rsig] = generate_rsig(params, auth_key_to_use['auth_key'])
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
@@ -22,7 +22,7 @@ module Change
22
22
  super(@parent_resource.client, properties)
23
23
  end
24
24
 
25
- def load(params)
25
+ def load(params = {})
26
26
  @parent_resource.load_collection(self.class.collection_name.to_sym, params)
27
27
  end
28
28
 
@@ -23,10 +23,14 @@ module Change
23
23
  path.prepend('/')
24
24
  end
25
25
 
26
- def needs_authorization?(method)
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 '#needs_authorization?' do
36
+ describe '#needs_request_signature?' do
37
37
 
38
38
  it "should return true for :get" do
39
- @resource.needs_authorization?(:get).must_equal false
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.needs_authorization?(:post).must_equal true
44
- @resource.needs_authorization?(:put).must_equal true
45
- @resource.needs_authorization?(:delete).must_equal true
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: change-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: