simple-http 0.1.2 → 0.1.3

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: 2cb84068e2541d62fd7a5739099e657cbf6bd20e
4
- data.tar.gz: a91e047d0c67b341cf1abeb3369ef8cfb4a2ce3f
3
+ metadata.gz: 45910b0d50187f5fcfb6ada7bd0b93718b2d9a74
4
+ data.tar.gz: a3daf4073ade9170518cd3528f7fc60098626118
5
5
  SHA512:
6
- metadata.gz: 7d511ae7fe48339375fc6326c0356866b5b60552f94587a01539e676262930456d90d6e5cc6837f6dbf76bf7716712d02a93660eb4b04e3538021671c887b70e
7
- data.tar.gz: 6c9745a3dc55dac702ae1f5c7fd407901158262c0dc0050d8b09dceb052381b1806ca86a2390145e598c9baaed089be2217a73cc61c966012763ee601b0ab675
6
+ metadata.gz: 83c053ef9e4d81b888cc545a4b074f4eedb7ee5ddebf3879a951cabcde0719b06fe5d195f527edbe41b0384715660c6fe70e2c539c5a5219141d84f75cfea316
7
+ data.tar.gz: fdaeffe33eec00750bb1849de6affc72d462ce2a10c21fe811b926315a687d303cef8af56f2edd582d6b444719dbea1eb5f0c0dca5f8c0f0f0fd5e33c6726a43
@@ -5,5 +5,5 @@
5
5
 
6
6
  module Simple; end
7
7
  class Simple::HTTP
8
- VERSION = "0.1.2"
8
+ VERSION = "0.1.3"
9
9
  end
data/lib/simple/http.rb CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  require "net/http"
6
6
  require "json"
7
+ require "logger"
7
8
 
8
9
  module Simple; end
9
10
  class Simple::HTTP; end
@@ -21,6 +22,10 @@ require_relative "http/errors"
21
22
  # the Content-Type header is set to "application/json".
22
23
  class Simple::HTTP
23
24
 
25
+ #
26
+ # The logger instance.
27
+ attr :logger, true
28
+
24
29
  #
25
30
  # The base URL: when set, all requests that do not start with http: or
26
31
  # https: are done relative to this base URL.
@@ -43,6 +48,8 @@ class Simple::HTTP
43
48
 
44
49
  def initialize
45
50
  self.follows_redirections = true
51
+ self.logger = Logger.new(STDERR)
52
+ self.logger.level = Logger::WARN
46
53
  end
47
54
 
48
55
  def get(url, headers = {}); http :GET, url, nil, headers; end
@@ -90,6 +97,7 @@ class Simple::HTTP
90
97
  # raise an error.
91
98
  def http_(method, url, body, headers, max_redirections = 10)
92
99
  if method == :GET && cache && result = cache.read(url)
100
+ logger.debug "#{method} #{uri}: using cached result"
93
101
  return result
94
102
  end
95
103
 
@@ -110,8 +118,10 @@ class Simple::HTTP
110
118
 
111
119
  #
112
120
  # execute request
121
+ started_at = Time.now
113
122
  response = http.request(request)
114
-
123
+ logger.info "#{method} #{uri}: #{response.body.bytesize} byte, #{"%.3f secs" % (Time.now - started_at)}"
124
+
115
125
  #
116
126
  # Most of the times Net::HTTP#request returns a response with the :uri
117
127
  # attribute set, but sometimes not. We make sure that the uri is set
@@ -123,6 +133,11 @@ class Simple::HTTP
123
133
  if response.is_a?(Net::HTTPSuccess)
124
134
  result = response.result
125
135
  if cache && method == :GET && expires_in = self.expires_in(response)
136
+ if response.expires_in == expires_in
137
+ logger.debug "#{method} #{uri}: store in cache, w/expiration of #{expires_in}"
138
+ else
139
+ logger.debug "#{method} #{uri}: store in cache, w/custom expiration of #{expires_in} (instead #{response.expires_in.inspect})"
140
+ end
126
141
  cache.write(url, result, expires_in: expires_in)
127
142
  end
128
143
 
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.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - radiospiel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-17 00:00:00.000000000 Z
11
+ date: 2015-10-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Simple code for simple HTTP requests
14
14
  email: eno@radiospiel.org