simple-http 0.3.1 → 0.3.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
  SHA256:
3
- metadata.gz: 8582dc364c1a5a1937cdd0c7441c46977c55085887a55c17b73f3e8eece2eb09
4
- data.tar.gz: ebdc906e6717181d79724830ca58b0cf6658a1daf6d6101e56a03fa142050148
3
+ metadata.gz: c7bdabbc5ad9589138ddf4724fb952870d18da4f4f96d957fdc51a145d86adaf
4
+ data.tar.gz: 6a4842332bc30e54c0271cb70177efc5d6283197230eaf1e0c382f1528835574
5
5
  SHA512:
6
- metadata.gz: 27ff83af6949e82d4d91fe3eb884bc4469a08bd5c0eb29b88a32e35ead60dee8ff887f019ad4791aba4de94111f398a6222923cf68ef5256465ea3f7e65eaddd
7
- data.tar.gz: bd5c296e85160ad96cc42897c11d7a28f9208184d1e28b8cc879a759d7f4c2945791d4db1a1970d8c65b77f3b01d72a946b58cdb3d34e69040c9a40bd5fb41c9
6
+ metadata.gz: e8844fa1eb87462695fc7a82329e18055fa2bdf3ecf0dc251872fdec5c640fda6a532e86e82ca1048d5e78a5f7993769d4494ceca7973e51f310dd9cfac794c5
7
+ data.tar.gz: c37bedd490d573c8da46484d990ccb197dead457c00569e0b87eaa374f6cf36b39ef80941b5069406f8ab88dde2a74abd14ba12b168512019a30a27c052ac33c
data/lib/simple/http.rb CHANGED
@@ -55,23 +55,27 @@ class Simple::HTTP
55
55
  end
56
56
 
57
57
  def head(url, headers = {})
58
- request :HEAD, url, nil, headers
58
+ perform_request! :HEAD, url, nil, headers
59
59
  end
60
60
 
61
61
  def get(url, headers = {})
62
- request :GET, url, nil, headers
62
+ perform_request! :GET, url, nil, headers
63
+ end
64
+
65
+ def options(url, headers = {})
66
+ perform_request! :OPTIONS, url, nil, headers
63
67
  end
64
68
 
65
69
  def post(url, body = nil, headers = {})
66
- request :POST, url, body, headers
70
+ perform_request! :POST, url, body, headers
67
71
  end
68
72
 
69
73
  def put(url, body = nil, headers = {})
70
- request :PUT, url, body, headers
74
+ perform_request! :PUT, url, body, headers
71
75
  end
72
76
 
73
77
  def delete(url, headers = {})
74
- request :DELETE, url, nil, headers
78
+ perform_request! :DELETE, url, nil, headers
75
79
  end
76
80
 
77
81
  #
@@ -83,7 +87,7 @@ class Simple::HTTP
83
87
 
84
88
  # -- HTTP request -----------------------------------------------------------
85
89
 
86
- def request(verb, url, body, headers)
90
+ def perform_request!(verb, url, body, headers)
87
91
  #
88
92
  # normalize url; i.e. prepend base_url if the url itself is incomplete.
89
93
  unless url =~ /^(http|https):/
@@ -141,6 +145,7 @@ class Simple::HTTP
141
145
  started_at = Time.now
142
146
 
143
147
  response = driver.execute_request(request, client: self)
148
+ response.send(:set_request, request)
144
149
 
145
150
  logger.info do
146
151
  "#{request}: #{response}, #{"%.3f secs" % (Time.now - started_at)}"
@@ -16,14 +16,13 @@ module Simple::HTTP::Driver::Default
16
16
  uri = URI.parse(url)
17
17
 
18
18
  # build Net::HTTP request
19
- request = build_request verb, uri, body, headers, client: client
19
+ net_request = build_request verb, uri, body, headers, client: client
20
20
 
21
21
  # execute request
22
22
  net_http = load_net_http(uri.scheme, uri.host, uri.port)
23
- resp = net_http.request(request)
23
+ resp = net_http.request(net_request)
24
24
 
25
- ::Simple::HTTP::Response.new request: request,
26
- status: Integer(resp.code),
25
+ ::Simple::HTTP::Response.new status: Integer(resp.code),
27
26
  message: resp.message,
28
27
  headers: Simple::HTTP::Headers.new(resp),
29
28
  body: resp.body
@@ -35,6 +34,7 @@ module Simple::HTTP::Driver::Default
35
34
  REQUEST_CLASSES = {
36
35
  :HEAD => Net::HTTP::Head,
37
36
  :GET => Net::HTTP::Get,
37
+ :OPTIONS => Net::HTTP::Options,
38
38
  :POST => Net::HTTP::Post,
39
39
  :PUT => Net::HTTP::Put,
40
40
  :DELETE => Net::HTTP::Delete
@@ -9,9 +9,10 @@ class Simple::HTTP::Response
9
9
  attr_reader :headers
10
10
  attr_reader :original_body
11
11
 
12
- def initialize(request:, body:, headers:, status:, message:)
13
- @request, @headers = request, headers
14
- @status, @message = status, message
12
+ def initialize(body:, headers:, status:, message:)
13
+ @headers = headers
14
+ @status = status
15
+ @message = message
15
16
  @original_body = body
16
17
 
17
18
  # adjust encoding on original_body
@@ -22,6 +23,14 @@ class Simple::HTTP::Response
22
23
  end
23
24
  end
24
25
 
26
+ private
27
+
28
+ def set_request(request)
29
+ @request = request
30
+ end
31
+
32
+ public
33
+
25
34
  # e.g "text/plain"
26
35
  def media_type
27
36
  @body_builder.media_type
@@ -5,14 +5,13 @@
5
5
 
6
6
  module Simple; end
7
7
  class Simple::HTTP
8
-
9
8
  module GemHelper
10
9
  extend self
11
10
 
12
11
  def version(name)
13
12
  spec = Gem.loaded_specs[name]
14
13
  version = spec ? spec.version.to_s : "0.0.0"
15
- # version += "+unreleased" if !spec || unreleased?(spec)
14
+ version += "+unreleased" if !spec || unreleased?(spec)
16
15
  version
17
16
  end
18
17
 
@@ -22,6 +21,7 @@ class Simple::HTTP
22
21
  return false unless defined?(Bundler::Source::Gemspec)
23
22
  return true if spec.source.is_a?(::Bundler::Source::Gemspec)
24
23
  return true if spec.source.is_a?(::Bundler::Source::Path)
24
+
25
25
  false
26
26
  end
27
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - radiospiel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-16 00:00:00.000000000 Z
11
+ date: 2019-11-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Simple code for simple HTTP requests
14
14
  email: eno@radiospiel.org