zanoxrb 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb0e3c81b39e97f52e2e1db629b60ba632f9abcb
4
- data.tar.gz: 159dbebcc514d393d43655cbf1cfd3e565b6253a
3
+ metadata.gz: 1dd9f08ace2ce5f98f28b96a2d844abb3e2f152f
4
+ data.tar.gz: b3ceb6ac205b0d431bc9f0eb504e6a3700812891
5
5
  SHA512:
6
- metadata.gz: 6c3ad875d26619c956875c63b31421bbaaf3bd68f8dbeeed710d2fb0ad32a19ae10a5ae2a68ee726accea87f574fab1bbf9160e18e811b1e008a93802a3f97c3
7
- data.tar.gz: 31d75ad5c119003e2cd8f4eac3b266067a5bf7d453f929505ec5bc9cb292402d817afe9766562ce87637b89e4b2e5f7fa76cfe9302d10fceb7bae5d4c09644c4
6
+ metadata.gz: 2db51f310649d9a5881ed495879d8eb074bb1bc5dcebb15356d24062c7d1330ee69ac04a6a73ccabadeffc34fe606d5d54026b79945011785312882f2f207140
7
+ data.tar.gz: fe6900a5666f4ea39bf4957297c7d9045f19712e22cded574e3bef974676e81c550f8e9d4f529cf0519572b6aad705c4345577e358f44be3e8d315d9470d6b7f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zanoxrb (0.1)
4
+ zanoxrb (0.2)
5
5
  httparty (~> 0.13)
6
6
 
7
7
  GEM
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
- method_path = method[0] == '/' ? method : "/#{method}"
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
@@ -23,5 +23,5 @@
23
23
  #++
24
24
 
25
25
  module Zanox
26
- VERSION = '0.1'
26
+ VERSION = '0.2'
27
27
  end
data/specs/spec_helper.rb CHANGED
@@ -3,4 +3,3 @@ require 'rspec/collection_matchers'
3
3
 
4
4
  Zanox::API::Session.connect_id = '802B8BF4AE99EBE00F41'
5
5
  Zanox::API::Session.secret_key = 'fa4c0c2020Aa4c+ab9Ea0ec8d39E06/df2c5aa44'
6
- Zanox::API.debug!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zanoxrb
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Giovanni Capuano