zanoxrb 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/zanox/api.rb +1 -24
- data/lib/zanox/session.rb +23 -0
- data/lib/zanox/version.rb +1 -1
- data/specs/spec_helper.rb +0 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1dd9f08ace2ce5f98f28b96a2d844abb3e2f152f
|
4
|
+
data.tar.gz: b3ceb6ac205b0d431bc9f0eb504e6a3700812891
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2db51f310649d9a5881ed495879d8eb074bb1bc5dcebb15356d24062c7d1330ee69ac04a6a73ccabadeffc34fe606d5d54026b79945011785312882f2f207140
|
7
|
+
data.tar.gz: fe6900a5666f4ea39bf4957297c7d9045f19712e22cded574e3bef974676e81c550f8e9d4f529cf0519572b6aad705c4345577e358f44be3e8d315d9470d6b7f
|
data/Gemfile.lock
CHANGED
data/lib/zanox/api.rb
CHANGED
@@ -45,8 +45,7 @@ module Zanox
|
|
45
45
|
|
46
46
|
def request(method, options = {}, headers = {})
|
47
47
|
if Session.secret_key
|
48
|
-
|
49
|
-
timestamp, nonce, signature = fingerprint_of(method_path, options)
|
48
|
+
timestamp, nonce, signature = Session.fingerprint_of(method, options)
|
50
49
|
headers.merge!({
|
51
50
|
'Authorization' => "ZXWS #{Session.connect_id}:#{signature}",
|
52
51
|
'Date' => timestamp,
|
@@ -61,28 +60,6 @@ module Zanox
|
|
61
60
|
response = get("/json/2011-03-01/#{method}", query: options, headers: headers)
|
62
61
|
Response.new(response)
|
63
62
|
end
|
64
|
-
|
65
|
-
private
|
66
|
-
def fingerprint_of(method, options, verb = 'GET')
|
67
|
-
timestamp = get_timestamp
|
68
|
-
nonce = get_nonce
|
69
|
-
params = ''#?' + URI.encode_www_form(options)
|
70
|
-
signature = create_signature(Session.secret_key, "#{verb}#{method.downcase}#{params}#{timestamp}#{nonce}")
|
71
|
-
[timestamp, nonce, signature]
|
72
|
-
end
|
73
|
-
|
74
|
-
def get_timestamp
|
75
|
-
Time.now.strftime('%a, %e %b %Y %T %Z')
|
76
|
-
end
|
77
|
-
|
78
|
-
def get_nonce
|
79
|
-
Digest::MD5.hexdigest((Time.new.usec + rand()).to_s)
|
80
|
-
end
|
81
|
-
|
82
|
-
def create_signature(secret_key, string_to_sign)
|
83
|
-
digest = OpenSSL::HMAC.digest('sha1', secret_key, string_to_sign)
|
84
|
-
Base64.encode64(digest)[0..-2]
|
85
|
-
end
|
86
63
|
end
|
87
64
|
end
|
88
65
|
end
|
data/lib/zanox/session.rb
CHANGED
@@ -28,6 +28,29 @@ module Zanox
|
|
28
28
|
class << self
|
29
29
|
attr_accessor :connect_id
|
30
30
|
attr_accessor :secret_key
|
31
|
+
|
32
|
+
def fingerprint_of(method, options, verb = 'GET')
|
33
|
+
method = method[0] == '/' ? method : "/#{method}"
|
34
|
+
|
35
|
+
timestamp = get_timestamp
|
36
|
+
nonce = get_nonce
|
37
|
+
signature = create_signature(Session.secret_key, "#{verb}#{method.downcase}#{timestamp}#{nonce}")
|
38
|
+
[timestamp, nonce, signature]
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
def get_timestamp
|
43
|
+
Time.now.strftime('%a, %e %b %Y %T %Z')
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_nonce
|
47
|
+
Digest::MD5.hexdigest((Time.new.usec + rand()).to_s)
|
48
|
+
end
|
49
|
+
|
50
|
+
def create_signature(secret_key, string_to_sign)
|
51
|
+
digest = OpenSSL::HMAC.digest('sha1', secret_key, string_to_sign)
|
52
|
+
Base64.encode64(digest)[0..-2]
|
53
|
+
end
|
31
54
|
end
|
32
55
|
end
|
33
56
|
end
|
data/lib/zanox/version.rb
CHANGED
data/specs/spec_helper.rb
CHANGED