jeff 0.5.0 → 0.6.0

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 (4) hide show
  1. data/README.md +1 -1
  2. data/lib/jeff.rb +19 -16
  3. data/lib/jeff/version.rb +1 -1
  4. metadata +2 -2
data/README.md CHANGED
@@ -9,6 +9,6 @@
9
9
 
10
10
  [stat]: https://secure.travis-ci.org/papercavalier/jeff.png
11
11
  [trav]: http://travis-ci.org/papercavalier/jeff
12
+ [sign]: http://docs.amazonwebservices.com/general/latest/gr/signature-version-2.html
12
13
  [aws]: http://aws.amazon.com/
13
14
  [jeff]: http://f.cl.ly/items/0a3R3J0k1R2f423k1q2l/jeff.jpg
14
- [sign]: http://docs.amazonwebservices.com/general/latest/gr/signature-version-2.html
@@ -8,9 +8,9 @@ require 'jeff/version'
8
8
 
9
9
  # Mixes in Amazon Web Services (AWS) client behaviour.
10
10
  module Jeff
11
- MissingEndpoint = Class.new ArgumentError
12
- MissingKey = Class.new ArgumentError
13
- MissingSecret = Class.new ArgumentError
11
+ MissingEndpoint = Class.new(ArgumentError)
12
+ MissingKey = Class.new(ArgumentError)
13
+ MissingSecret = Class.new(ArgumentError)
14
14
 
15
15
  UNRESERVED = /([^\w.~-]+)/
16
16
 
@@ -31,7 +31,7 @@ module Jeff
31
31
  'Timestamp' => -> { Time.now.utc.iso8601 }
32
32
  end
33
33
 
34
- # Internal: Builds a sorted query.
34
+ # Internal: Build a sorted query.
35
35
  #
36
36
  # hsh - A hash of query parameters specific to the request.
37
37
  #
@@ -40,7 +40,7 @@ module Jeff
40
40
  params
41
41
  .merge(hsh)
42
42
  .sort
43
- .map { |k, v| "#{k}=#{ escape v }" }
43
+ .map { |k, v| "#{k}=#{ escape(v) }" }
44
44
  .join('&')
45
45
  end
46
46
 
@@ -102,27 +102,30 @@ module Jeff
102
102
  eval <<-DEF
103
103
  def #{method}(opts = {})
104
104
  opts.update :method => :#{method}
105
- if opts[:body]
106
- opts[:headers] ||= {}
107
- opts[:headers].update 'Content-MD5' => calculate_md5(opts[:body])
108
- end
109
-
110
- connection.request(sign(opts))
105
+ connection.request(build_options(opts))
111
106
  end
112
107
  DEF
113
108
  end
114
109
 
115
110
  private
116
111
 
112
+ def build_options(opts)
113
+ opts[:headers] ||= {}
114
+ opts[:headers].update('Host' => connection_host)
115
+
116
+ if opts[:body]
117
+ opts[:headers].update('Content-MD5' => calculate_md5(opts[:body]))
118
+ end
119
+
120
+ sign(opts)
121
+ end
122
+
117
123
  def calculate_md5(body)
118
124
  Base64.encode64(Digest::MD5.digest(body)).strip
119
125
  end
120
126
 
121
127
  def connection_host
122
- [
123
- connection.data[:host],
124
- connection.data[:port]
125
- ].join ':'
128
+ connection.data[:host]
126
129
  end
127
130
 
128
131
  def connection_path
@@ -143,7 +146,7 @@ module Jeff
143
146
  connection_host,
144
147
  opts[:path] || connection_path,
145
148
  query
146
- ].join "\n"
149
+ ].join("\n")
147
150
  signature = secret.sign(string_to_sign)
148
151
 
149
152
  opts.update query: [
@@ -1,3 +1,3 @@
1
1
  module Jeff
2
- VERSION = '0.5.0'
2
+ VERSION = '0.6.0'
3
3
  end
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: jeff
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.5.0
5
+ version: 0.6.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Hakan Ensari
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-24 00:00:00.000000000 Z
12
+ date: 2013-02-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  version_requirements: !ruby/object:Gem::Requirement