jeff 0.7.1 → 0.7.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: 4a639f62956efb161e7a7e49ff2e7871c4fe047c
4
- data.tar.gz: fd8e1451516c459c319994c8abc14322c6cd5d3c
3
+ metadata.gz: 531fd2a3ff845560616632dda4f42b79afafdd38
4
+ data.tar.gz: 058f220f25b627ee5d9343f396686922b2dc99f6
5
5
  SHA512:
6
- metadata.gz: bd5fef3ff0d648da00600818d716b4c16c666477c7abbc9290b9bf51763bd10ad9fb93e15cbfa7bb869147bd3b6b4ab4229b5963a80fa7d14fceb8656387f9c5
7
- data.tar.gz: 61e31b449e13ca70ff3df5c85c6ebb3d69e8ebd2c2d49357061593165f4efabd1c50345fde89789db6bf3aba793170399c0da914cbf79c834b89c985052e1679
6
+ metadata.gz: cecaa486900adfbd6505e38ebb2b39a05846033be3fd12231997a7241948e145531278ecce7a63a5cb13480f2ace09c614afc8f07a1ab9dd4c5cf4e1a568ef5d
7
+ data.tar.gz: 5c46914754a2cd3f3efb4aeeb4da4941c744226bc443686bcf1c5f9162a798288130fdd1d5c67c684ae419ee984b04e66b840fce7e969d1ec176e6a73443f54a
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  Gemfile.lock
2
+ bin
2
3
  pkg
data/README.md CHANGED
@@ -13,17 +13,21 @@ A minimal example:
13
13
  Request = Struct.new(:aws_access_key_id, :aws_secret_access_key) do
14
14
  include Jeff
15
15
 
16
- def aws_endpoint; 'https://mws.amazonservices.com/Products/2011-10-01'; end
16
+ def aws_endpoint
17
+ 'https://mws.amazonservices.com/Products/2011-10-01'
18
+ end
17
19
  end
18
20
 
19
- req = Request.new('foo', 'bar')
21
+ req = Request.new('key', 'secret')
20
22
  res = req.get(query: { 'Action' => 'GetServiceStatus' })
21
23
 
22
24
  puts res.body.match(/Status>([^<]+)/)[1]
25
+ # => "GREEN"
23
26
  ```
24
27
 
25
- [Vacuum][vac] provides an example implementation.
28
+ [Vacuum][vac] and [Peddler][ped] implement Jeff.
26
29
 
27
30
  [sig]: http://docs.amazonwebservices.com/general/latest/gr/signature-version-2.html
28
- [vac]: https://github.com/hakanensari/vacuum
29
31
  [jef]: http://f.cl.ly/items/0a3R3J0k1R2f423k1q2l/jeff.jpg
32
+ [vac]: https://github.com/hakanensari/vacuum
33
+ [ped]: https://github.com/papercavalier/peddler
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ['lib']
16
16
  gem.version = Jeff::VERSION
17
17
 
18
- gem.add_dependency 'excon', '~> 0.25.0'
18
+ gem.add_dependency 'excon', '~> 0.26.0'
19
19
  gem.add_development_dependency 'minitest'
20
20
  gem.add_development_dependency 'rake'
21
21
 
@@ -1,5 +1,4 @@
1
- # Our only external dependency. Excon is currently my preferred HTTP client in
2
- # Ruby.
1
+ # The only external dependency.
3
2
  require 'excon'
4
3
 
5
4
  # Standard library dependencies.
@@ -15,22 +14,43 @@ require 'jeff/version'
15
14
  # It's Jeff, as in Jeff Bezos.
16
15
  module Jeff
17
16
  # Converts a query value to a sorted query string.
18
- Query = Struct.new(:values) do
17
+ class Query
18
+ attr :values
19
+
20
+ def initialize(values)
21
+ @values = values
22
+ end
23
+
19
24
  def to_s
20
25
  values.sort.map { |k, v| "#{k}=#{ Utils.escape(v) }" }.join('&')
21
26
  end
22
27
  end
23
28
 
24
29
  # Calculates an MD5sum for file being uploaded.
25
- Content = Struct.new(:body) do
30
+ class Content
31
+ attr :body
32
+
33
+ def initialize(body)
34
+ @body = body
35
+ end
36
+
26
37
  def md5
27
38
  Base64.encode64(OpenSSL::Digest::MD5.digest(body)).strip
28
39
  end
29
40
  end
30
41
 
31
42
  # Signs an AWS request.
32
- Request = Struct.new(:method, :host, :path, :query_string) do
33
- def sign(aws_secret_access_key)
43
+ class Request
44
+ attr :method, :host, :path, :query_string
45
+
46
+ def initialize(method, host, path, query_string)
47
+ @method = method
48
+ @host = host
49
+ @path = path
50
+ @query_string = query_string
51
+ end
52
+
53
+ def sign_with(aws_secret_access_key)
34
54
  Signature.new(aws_secret_access_key).sign(string_to_sign)
35
55
  end
36
56
 
@@ -52,7 +72,7 @@ module Jeff
52
72
  end
53
73
 
54
74
  def secret
55
- @secret or raise ArgumentError, 'Missing secret'
75
+ @secret or raise ArgumentError.new('Missing secret')
56
76
  end
57
77
  end
58
78
 
@@ -89,10 +109,9 @@ module Jeff
89
109
  )
90
110
  end
91
111
 
92
- # An HTTP connection. It's reusable, which, as the author of Excon puts it,
93
- # is more performant!
112
+ # A reusable HTTP connection.
94
113
  def connection
95
- @connection ||= Excon.new(endpoint,
114
+ @connection ||= Excon.new(aws_endpoint,
96
115
  headers: { 'User-Agent' => USER_AGENT },
97
116
  expects: 200,
98
117
  omit_default_port: true
@@ -102,13 +121,28 @@ module Jeff
102
121
  # Accessors for required AWS attributes.
103
122
  attr_accessor :aws_endpoint, :aws_access_key_id, :aws_secret_access_key
104
123
 
105
- # We'll keep these around so we don't break dependent libraries.
106
- alias endpoint aws_endpoint
107
- alias endpoint= aws_endpoint=
108
- alias key aws_access_key_id
109
- alias key= aws_access_key_id=
110
- alias secret aws_secret_access_key
111
- alias secret= aws_secret_access_key=
124
+ # Keep these deprecated attribute accessors around for a while.
125
+ # TODO Remove when cutting v1.0.
126
+ %w(
127
+ endpoint aws_endpoint
128
+ endpoint= aws_endpoint=
129
+ key aws_access_key_id
130
+ key= aws_access_key_id=
131
+ secret aws_secret_access_key
132
+ secret= aws_secret_access_key=
133
+ ).each_slice(2) do |old, new|
134
+ if old.end_with?('=')
135
+ define_method(old) do |value|
136
+ warn "[DEPRECATION] Use #{new}"
137
+ self.send(new, value)
138
+ end
139
+ else
140
+ define_method(old) do
141
+ warn "[DEPRECATION] Use #{new}"
142
+ self.send(new)
143
+ end
144
+ end
145
+ end
112
146
 
113
147
  # Generate HTTP request verb methods.
114
148
  Excon::HTTP_VERBS.each do |method|
@@ -145,10 +179,10 @@ module Jeff
145
179
  options[:path] || connection.data[:path],
146
180
  query_string
147
181
  )
148
- .sign(aws_secret_access_key)
182
+ .sign_with(aws_secret_access_key)
149
183
 
150
184
  # Return options after appending an escaped signature to query.
151
- options.update(query: "#{query_string}&Signature=#{Utils.escape(signature)}")
185
+ options.merge(query: "#{query_string}&Signature=#{Utils.escape(signature)}")
152
186
  end
153
187
 
154
188
  module ClassMethods
@@ -1,3 +1,3 @@
1
1
  module Jeff
2
- VERSION = '0.7.1'
2
+ VERSION = '0.7.2'
3
3
  end
@@ -35,7 +35,7 @@ describe Jeff do
35
35
 
36
36
  it 'sets a User-Agent header for the client connection' do
37
37
  client = @klass.new
38
- client.endpoint = 'http://example.com/'
38
+ client.aws_endpoint = 'http://example.com/'
39
39
  client.connection.data[:headers]['User-Agent'].wont_be_nil
40
40
  end
41
41
 
@@ -43,9 +43,9 @@ describe Jeff do
43
43
  it "makes a #{method.upcase} request" do
44
44
  Excon.stub({ }, { status: 200 })
45
45
  client = @klass.new
46
- client.endpoint = 'http://example.com/'
47
- client.key = 'foo'
48
- client.secret = 'bar'
46
+ client.aws_endpoint = 'http://example.com/'
47
+ client.aws_access_key_id = 'foo'
48
+ client.aws_secret_access_key = 'bar'
49
49
  client.send(method).status.must_equal 200
50
50
  Excon.stubs.clear
51
51
  end
@@ -56,9 +56,9 @@ describe Jeff do
56
56
  { body: params[:headers]['Content-MD5'] }
57
57
  end
58
58
  client = @klass.new
59
- client.endpoint = 'http://example.com/'
60
- client.key = 'foo'
61
- client.secret = 'bar'
59
+ client.aws_endpoint = 'http://example.com/'
60
+ client.aws_access_key_id = 'foo'
61
+ client.aws_secret_access_key = 'bar'
62
62
  client.post(body: 'foo').body.wont_be_empty
63
63
  Excon.stubs.clear
64
64
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jeff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hakan Ensari
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-08 00:00:00.000000000 Z
11
+ date: 2013-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 0.25.0
19
+ version: 0.26.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: 0.25.0
26
+ version: 0.26.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement