sk-hoth 0.3.2 → 0.3.4

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.
Files changed (2) hide show
  1. data/lib/hoth/transport/http_hmac.rb +20 -6
  2. metadata +3 -3
@@ -1,5 +1,7 @@
1
1
  require 'king_hmac'
2
2
  require 'net/http'
3
+ require 'net/https'
4
+
3
5
  module Hoth
4
6
  module Transport
5
7
  class HttpHmac < Http
@@ -14,24 +16,36 @@ module Hoth
14
16
  # the call can be made
15
17
  # === Returns
16
18
  # <Object>:. Net::HTTPResponse
17
- def post_payload(payload)
19
+ def post_payload(payload, use_ssl=false)
18
20
  raise TransportError, 'no hmac credentials set for hmac transport' unless hmac_access_id && hmac_secret
19
21
  uri = URI.parse(self.endpoint.to_url)
20
22
  # construct request object
21
23
  self.req = Net::HTTP::Post.new(uri.path)
22
24
  # add its form data
23
25
  self.req.form_data = {'name' => self.name.to_s,
24
- 'params' => encoder.encode(payload) }
26
+ 'params' => encoder.encode(payload) }
25
27
  # ensure a date header is set, needed for hmac
26
28
  self.req['Date'] = Time.now.httpdate if self.req['Date'].nil?
27
29
  # sign request object => set Authorisation header
28
30
  KingHmac::Auth.sign!(self.req, hmac_access_id, hmac_secret)
29
- # go for it
30
- return Net::HTTP.new(uri.host, uri.port).start {|http|
31
- http.request(self.req)
32
- }
31
+ #create request
32
+ request = Net::HTTP.new(uri.host, uri.port)
33
+ request.use_ssl = use_ssl
34
+ response = request.start {|http| http.request(self.req) }
35
+ case response
36
+ when Net::HTTPSuccess, Net::HTTPRedirection
37
+ response
38
+ else
39
+ response.error!
40
+ end
33
41
  end
42
+ end
34
43
 
44
+ class HttpsHmac < HttpHmac
45
+ def post_payload(payload)
46
+ super(payload, true)
47
+ end
35
48
  end
49
+
36
50
  end
37
51
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 2
9
- version: 0.3.2
8
+ - 4
9
+ version: 0.3.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Dirk Breuer
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-04-14 00:00:00 +02:00
18
+ date: 2010-04-30 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency