http-client 0.3.0 → 0.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 442016d7995b5d8e1e31886a4aaff8a34102635d
4
- data.tar.gz: f7bc4ab873d2cc41abccecac5b4d46c148e88d78
3
+ metadata.gz: d546e0cdecec14e9d20d4b95c21bd149602b3c12
4
+ data.tar.gz: c564d50a791ce9244b199276c9e7b7b55e843127
5
5
  SHA512:
6
- metadata.gz: 9347691549ccb5381f277597a198fd6042b3cfa3c6b3b0eafcf0f539cfd3ca7be6a6d5d7f36590d46099cbd98602757ff936754c0e3a3986dfe45085da216ca1
7
- data.tar.gz: dfe32ba2b0e52035fe0572023fc34a914cc6b518cd00b746cd8779f895fa718b771094c37a51b29dd2ba0f268a6662090af82d4aaa0586b3c9634e65006e9523
6
+ metadata.gz: d76ba488f562a71c3335f87b59848f8ab51a5e179e9cdbd682b5e075ebf72361736aa34f620677602d8f7fda62738cbd1dd774c7d310a87839507fbd82b55c27
7
+ data.tar.gz: fd787d6c479ae7acf074a88a493e38c5ed6bf975a91954d1ed50772bd84c568ea2a029337a5c41c5dd912a8c9d9728f6301b7d36d4bfcc4b303ac31e1db696aa
data/CHANGELOG CHANGED
@@ -1,4 +1,8 @@
1
- == 0.3.0 (2017-06-30
1
+ == 0.4.0 (2017-07-05)
2
+
3
+ * Cleanup error classes namespacing.
4
+
5
+ == 0.3.0 (2017-06-30)
2
6
 
3
7
  * Rescue error conditions and re-raise them as HTTP::Client::Error sub-classes.
4
8
 
data/README.md CHANGED
@@ -56,6 +56,7 @@ HTTP::Client::Error
56
56
  HTTP::Client::Error::Zlib
57
57
  HTTP::Client::Error::Timeout
58
58
  HTTP::Client::Error::Transport
59
+ HTTP::Client::Error::Argument
59
60
  ```
60
61
 
61
62
  ### Request parameters
data/lib/http/client.rb CHANGED
@@ -9,7 +9,7 @@ require 'zlib'
9
9
 
10
10
  module HTTP
11
11
  module Client
12
- VERSION = '0.3.0'
12
+ VERSION = '0.4.0'
13
13
 
14
14
  GET = Net::HTTP::Get
15
15
  HEAD = Net::HTTP::Head
@@ -22,12 +22,6 @@ module HTTP
22
22
  SSL_VERIFY_NONE = OpenSSL::SSL::VERIFY_NONE
23
23
  SSL_VERIFY_PEER = OpenSSL::SSL::VERIFY_PEER
24
24
 
25
- class Error < StandardError;
26
- end
27
-
28
- class ArgumentError < Error;
29
- end
30
-
31
25
  class Request
32
26
  VALID_PARAMETERS = %w(headers files query body auth timeout open_timeout ssl_timeout read_timeout max_redirects ssl_verify jar)
33
27
  DEFAULT_HEADERS = {'User-Agent' => 'HTTP Client API/1.0'}
@@ -54,7 +48,7 @@ module HTTP
54
48
  # @option args [Integer] read_timeout Read timeout in seconds.
55
49
  # @option args [Integer] ssl_timeout SSL handshake timeout in seconds.
56
50
  # @option args [Integer] max_redirects Max redirect follow, default: 0
57
- # @option args [Integer] ssl_verify OpenSSL verification, SSL_VERIFY_PEER or SSL_VERIFY_NONE, defaults to SSL_VERIFY_PEER.
51
+ # @option args [Integer] ssl_verify OpenSSL verification, SSL_VERIFY_PEER (default) or SSL_VERIFY_NONE.
58
52
  # @option args [HTTP::CookieJar] jar Optional cookie jar to use. Relies on HTTP::CookieJar from http-cookie gem.
59
53
  #
60
54
  # @return [HTTP::Client::Request]
@@ -71,7 +65,11 @@ module HTTP
71
65
  # response = HTTP::Client.get("http://www.example.org/", max_redirects: 3)
72
66
  #
73
67
  # @example Upload a few files in a POST request.
74
- # request = HTTP::Client::Request.new(:post, "http://www.example.org/", files: {"cats" => "cats.jpg", "dogs" => "dogs.jpg"}, query: {title: "cute pics"})
68
+ # request = HTTP::Client::Request.new(
69
+ # :post, "http://www.example.org/",
70
+ # files: {"cats" => "cats.jpg", "dogs" => "dogs.jpg"},
71
+ # query: {title: "cute pics"}
72
+ # )
75
73
  # response = request.execute
76
74
  #
77
75
  # @example Pass in an external cookie jar.
@@ -81,14 +79,14 @@ module HTTP
81
79
  #
82
80
  def initialize verb, uri, args = {}
83
81
  args.each do |k, v|
84
- raise ArgumentError, "unknown argument #{k}" unless VALID_PARAMETERS.include?(k.to_s)
82
+ raise Error::Argument, "unknown argument #{k}" unless VALID_PARAMETERS.include?(k.to_s)
85
83
  end
86
84
 
87
85
  uri = parse_uri!(uri)
88
86
  @delegate = create_request_delegate(verb, uri, args)
89
87
 
90
88
  if body = args[:body]
91
- raise ArgumentError, "#{verb} cannot have body" unless @delegate.class.const_get(:REQUEST_HAS_BODY)
89
+ raise Error::Argument, "#{verb} cannot have body" unless @delegate.class.const_get(:REQUEST_HAS_BODY)
92
90
  @delegate.body = body
93
91
  end
94
92
 
@@ -155,19 +153,19 @@ module HTTP
155
153
  uri = uri.kind_of?(URI) ? uri : URI.parse(uri)
156
154
  case uri
157
155
  when URI::HTTP, URI::HTTPS
158
- raise ArgumentError, "Invalid URI #{uri}" if uri.host.nil?
156
+ raise Error::URI, "Invalid URI #{uri}" if uri.host.nil?
159
157
  uri
160
158
  when URI::Generic
161
159
  if @delegate && @delegate.uri
162
160
  @delegate.uri.dup.tap {|s| s += uri }
163
161
  else
164
- raise ArgumentError, "Invalid URI #{uri}"
162
+ raise Error::URI, "Invalid URI #{uri}"
165
163
  end
166
164
  else
167
- raise ArgumentError, "Invalid URI #{uri}"
165
+ raise Error::URI, "Invalid URI #{uri}"
168
166
  end
169
167
  rescue URI::InvalidURIError => e
170
- raise ArgumentError, "Invalid URI #{uri}"
168
+ raise Error::URI, "Invalid URI #{uri}"
171
169
  end
172
170
 
173
171
  def create_request_delegate verb, uri, args
@@ -180,7 +178,7 @@ module HTTP
180
178
  delegate = nil
181
179
 
182
180
  if files
183
- raise ArgumentError, "#{verb} cannot have body" unless klass.const_get(:REQUEST_HAS_BODY)
181
+ raise Error::Argument, "#{verb} cannot have body" unless klass.const_get(:REQUEST_HAS_BODY)
184
182
  multipart = Multipart.new(files, qs)
185
183
  delegate = klass.new(uri, headers)
186
184
  delegate.content_type = multipart.content_type
@@ -264,7 +262,7 @@ module HTTP
264
262
  when /^post$/i then POST
265
263
  when /^delete$/i then DELETE
266
264
  else
267
- raise ArgumentError, "Invalid verb #{string}"
265
+ raise Error::Argument, "Invalid verb #{string}"
268
266
  end
269
267
  end
270
268
  end # Request
@@ -439,6 +437,7 @@ module HTTP
439
437
  class Zlib < Error; end
440
438
  class Timeout < Error; end
441
439
  class Transport < Error; end
440
+ class Argument < Error; end
442
441
  end # Error
443
442
  end # Client
444
443
  end # HTTP
data/test/test_request.rb CHANGED
@@ -4,17 +4,17 @@ require_relative 'helper'
4
4
 
5
5
  describe 'HTTP Client Request' do
6
6
  it 'should reject invalid arguments' do
7
- assert_raises(HTTP::Client::ArgumentError, 'invalid verb') {HTTP::Client::Request.new(:foo, 'http://example.org/')}
8
- assert_raises(HTTP::Client::ArgumentError, 'invalid uri') {HTTP::Client::Request.new(:get, 'http://')}
9
- assert_raises(HTTP::Client::ArgumentError, 'invalid uri') {HTTP::Client::Request.new(:get, '/hello')}
7
+ assert_raises(HTTP::Client::Error::Argument, 'invalid verb') {HTTP::Client::Request.new(:foo, 'http://example.org/')}
8
+ assert_raises(HTTP::Client::Error::URI, 'invalid uri') {HTTP::Client::Request.new(:get, 'http://')}
9
+ assert_raises(HTTP::Client::Error::URI, 'invalid uri') {HTTP::Client::Request.new(:get, '/hello')}
10
10
 
11
- assert_raises(HTTP::Client::ArgumentError, 'invalid argument') do
11
+ assert_raises(HTTP::Client::Error::Argument, 'invalid argument') do
12
12
  HTTP::Client::Request.new(:get, 'http://example.org/', foo: 1)
13
13
  end
14
14
  end
15
15
 
16
16
  it 'validates body based on request verb' do
17
- assert_raises(HTTP::Client::ArgumentError, 'get cannot have body') do
17
+ assert_raises(HTTP::Client::Error::Argument, 'get cannot have body') do
18
18
  HTTP::Client::Request.new(:get, 'http://a.c', files: {test: __FILE__})
19
19
  end
20
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bharanee Rathna
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-30 00:00:00.000000000 Z
11
+ date: 2017-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mime-types
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  version: '0'
125
125
  requirements: []
126
126
  rubyforge_project:
127
- rubygems_version: 2.6.8
127
+ rubygems_version: 2.6.11
128
128
  signing_key:
129
129
  specification_version: 4
130
130
  summary: A client wrapper around Net::HTTP