viki_utils 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,7 +11,7 @@ module Viki
11
11
  @secret = secret
12
12
  end
13
13
 
14
- def sign_request(uri,body = nil)
14
+ def sign_request(uri, body = nil)
15
15
  Addressable::URI.parse(uri).tap do |signed_uri|
16
16
  query = signed_uri.query_values || {}
17
17
  query[:t] = Time.now.to_i
@@ -20,10 +20,14 @@ module Viki
20
20
  to_sign = [signed_uri.path, signed_uri.query].join('?')
21
21
  to_sign += Oj.dump(body) if body
22
22
 
23
- sig = OpenSSL::HMAC.hexdigest(DIGEST, @secret, to_sign)
23
+ sig = UriSigner.sign(@secret, to_sign)
24
24
  query.merge!(sig: sig)
25
25
  signed_uri.query_values = query
26
26
  end
27
27
  end
28
+
29
+ def self.sign(secret, data)
30
+ OpenSSL::HMAC.hexdigest(DIGEST, secret, data)
31
+ end
28
32
  end
29
33
  end
@@ -1,3 +1,3 @@
1
1
  module VikiUtils
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -3,7 +3,7 @@ require_relative "../../lib/viki/uri_signer"
3
3
  require 'timecop'
4
4
 
5
5
  describe Viki::UriSigner do
6
- describe ".sign_request" do
6
+ describe "#sign_request" do
7
7
  let(:uri) { URI("http://example.com/endpoint") }
8
8
  let(:secret) { "your_secret" }
9
9
 
@@ -40,4 +40,10 @@ describe Viki::UriSigner do
40
40
  end
41
41
  end
42
42
  end
43
+
44
+ describe ".sign" do
45
+ it "returns the signature" do
46
+ Viki::UriSigner.sign('pineapple', "it's over 9000").should == 'c838e400e8a4713af5bfe21601af9aee3a6201d7'
47
+ end
48
+ end
43
49
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: viki_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: