jeff 1.3.0 → 1.4.0

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: 26d4ecc099e2a707deb20d81eb0e99c146f4e4a4
4
- data.tar.gz: c3c7d33f9cad57ec5bcfe55dacb7cc44f1175bfb
3
+ metadata.gz: 2256dcb03eb1bf6ce825c9cf1b2f1de192dff544
4
+ data.tar.gz: 29d63828239369329ffab1120d8beb0c18570277
5
5
  SHA512:
6
- metadata.gz: dd29ac1f134dd1a98c841e63e7c1f17e1a8a82282abde2ccc0e694daf1dc347d853d477e87a929f2f4982e49acaaea88cf41c59b22f3f3bef30389cb6c9b5281
7
- data.tar.gz: bbab285296bf3ddee692e21337ea04540af2104c9bfe6eb98d0b6939fdc20e0f93a19002845355b89f4b91031d2a1f8d3d7c2aefeb11a8868a968c31ea021cf4
6
+ metadata.gz: e30ba915c8f8f2be48ff203d6187330ee03eaacc51290aeb6c980cf91a8f8e46acecc8d05805b7e735c05fcd3cf5b4bb7bd49915f8346d64f4f2b5c88c665452
7
+ data.tar.gz: 1a15572f7d538ab793f45da18de98e7ce8fdfd609da3aea93c01fccc41746ca3f6ce54fcfe154628d849f3a09d11ae2ceacb3ba46208fe83f932c8d33c501ac6
@@ -0,0 +1,2 @@
1
+ StringLiterals:
2
+ EnforcedStyle: double_quotes
@@ -1,6 +1,7 @@
1
1
  # 1.3.0 15/4/2015
2
2
 
3
3
  - Handle overly long request queries
4
+ See https://github.com/hakanensari/peddler/issues/36
4
5
 
5
6
  # 1.2.0 23/1/2015
6
7
 
@@ -13,7 +13,7 @@ require "jeff/version"
13
13
  module Jeff
14
14
  # Converts query field-value pairs to a sorted query string.
15
15
  class Query
16
- attr :values
16
+ attr_reader :values
17
17
 
18
18
  def initialize(values)
19
19
  @values = values
@@ -22,13 +22,13 @@ module Jeff
22
22
  def to_s
23
23
  values
24
24
  .sort { |a, b| a[0].to_s <=> b[0].to_s }
25
- .map { |k, v| "#{k}=#{ Utils.escape(v) }" }.join("&")
25
+ .map { |k, v| "#{k}=#{Utils.escape(v)}" }.join("&")
26
26
  end
27
27
  end
28
28
 
29
29
  # Calculates an MD5sum for file being uploaded.
30
30
  class Content
31
- attr :body
31
+ attr_reader :body
32
32
 
33
33
  def initialize(body)
34
34
  @body = body
@@ -41,7 +41,7 @@ module Jeff
41
41
 
42
42
  # Signs an AWS request.
43
43
  class Signer
44
- attr :method, :host, :path, :query_string
44
+ attr_reader :method, :host, :path, :query_string
45
45
 
46
46
  def initialize(method, host, path, query_string)
47
47
  @method = method.upcase
@@ -72,7 +72,7 @@ module Jeff
72
72
  end
73
73
 
74
74
  def secret
75
- @secret or raise ArgumentError.new("Missing secret")
75
+ @secret || fail(ArgumentError, "Missing secret")
76
76
  end
77
77
  end
78
78
 
@@ -82,7 +82,8 @@ module Jeff
82
82
 
83
83
  def self.escape(val)
84
84
  val.to_s.gsub(UNRESERVED) do
85
- "%" + $1.unpack("H2" * $1.bytesize).join("%").upcase
85
+ match = Regexp.last_match[1]
86
+ "%" + match.unpack("H2" * match.bytesize).join("%").upcase
86
87
  end
87
88
  end
88
89
  end
@@ -104,11 +105,11 @@ module Jeff
104
105
 
105
106
  # A reusable HTTP connection.
106
107
  def connection
107
- @connection ||= Excon.new(aws_endpoint,
108
- headers: { "User-Agent" => self.class.user_agent },
109
- expects: 200,
110
- omit_default_port: true
111
- )
108
+ @connection ||= Excon.new(aws_endpoint, connection_params)
109
+ end
110
+
111
+ def connection_params
112
+ @connection_params ||= default_connection_params
112
113
  end
113
114
 
114
115
  attr_accessor :aws_endpoint
@@ -144,8 +145,16 @@ module Jeff
144
145
 
145
146
  private
146
147
 
148
+ def default_connection_params
149
+ {
150
+ headers: { "User-Agent" => self.class.user_agent },
151
+ expects: 200,
152
+ omit_default_port: true
153
+ }
154
+ end
155
+
147
156
  def add_md5_digest(options)
148
- return unless options.has_key?(:body)
157
+ return unless options.key?(:body)
149
158
  md5 = Content.new(options[:body]).md5
150
159
  (options[:headers] ||= {}).store("Content-MD5", md5)
151
160
  end
@@ -165,18 +174,19 @@ module Jeff
165
174
  end
166
175
 
167
176
  def move_query_to_body(options)
168
- (options[:headers] ||= {}).store("Content-Type", "application/x-www-form-urlencoded")
177
+ options[:headers] ||= {}
178
+ options[:headers].store("Content-Type", "application/x-www-form-urlencoded")
169
179
  options.store(:body, options.delete(:query))
170
180
  end
171
181
 
172
182
  def default_query_values
173
183
  self.class.params
174
- .reduce({}) { |qv, (k, v)|
184
+ .reduce({}) do |qv, (k, v)|
175
185
  v = v.respond_to?(:call) ? instance_exec(&v) : v
176
186
 
177
187
  # Ignore keys with nil values
178
188
  v.nil? ? qv : qv.update(k => v)
179
- }
189
+ end
180
190
  end
181
191
 
182
192
  module ClassMethods
@@ -187,12 +197,9 @@ module Jeff
187
197
 
188
198
  def user_agent
189
199
  @user_agent ||= default_user_agent
190
-
191
200
  end
192
201
 
193
- def user_agent=(user_agent)
194
- @user_agent = user_agent
195
- end
202
+ attr_writer :user_agent
196
203
 
197
204
  private
198
205
 
@@ -1,3 +1,3 @@
1
1
  module Jeff
2
- VERSION = "1.3.0"
2
+ VERSION = "1.4.0"
3
3
  end
@@ -20,13 +20,13 @@ class TestJeff < Minitest::Test
20
20
 
21
21
  def test_has_required_request_query_parameters
22
22
  %w(AWSAccessKeyId SignatureMethod SignatureVersion Timestamp).each do |key|
23
- assert @klass.params.has_key?(key)
23
+ assert @klass.params.key?(key)
24
24
  end
25
25
  end
26
26
 
27
27
  def test_configures_request_query_parameters
28
28
  @klass.params "Foo" => "bar"
29
- assert @klass.params.has_key?("Foo")
29
+ assert @klass.params.key?("Foo")
30
30
  end
31
31
 
32
32
  def test_allows_dynamic_values_for_request_query_parameters
@@ -92,7 +92,7 @@ class TestJeffInAction < Minitest::Test
92
92
 
93
93
  Excon::HTTP_VERBS.each do |method|
94
94
  define_method "test_makes_#{method}_request" do
95
- Excon.stub({}, { status: 200 })
95
+ Excon.stub({}, status: 200)
96
96
  assert_equal 200, @client.send(method, mock: true).status
97
97
  end
98
98
  end
@@ -123,7 +123,16 @@ class TestJeffInAction < Minitest::Test
123
123
 
124
124
  def test_gets_from_an_actual_endpoint
125
125
  @client.aws_endpoint = "https://mws.amazonservices.com/Sellers/2011-07-01"
126
- res = @client.post(query: { "Action" => "GetServiceStatus"})
126
+ res = @client.post(query: { "Action" => "GetServiceStatus" })
127
127
  assert_equal 200, res.status
128
128
  end
129
+
130
+ def test_has_no_proxy_by_default
131
+ refute @client.connection.proxy
132
+ end
133
+
134
+ def test_sets_proxy
135
+ @client.connection_params.store(:proxy, "http://my.proxy:4321")
136
+ assert @client.connection.proxy
137
+ end
129
138
  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: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hakan Ensari
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-15 00:00:00.000000000 Z
11
+ date: 2015-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon
@@ -60,6 +60,7 @@ extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
62
  - ".gitignore"
63
+ - ".rubocop.yml"
63
64
  - ".travis.yml"
64
65
  - CHANGELOG.md
65
66
  - Gemfile
@@ -96,4 +97,3 @@ specification_version: 4
96
97
  summary: An AWS client
97
98
  test_files:
98
99
  - test/test_jeff.rb
99
- has_rdoc: