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 +4 -4
- data/lib/simple/http/version.rb +1 -1
- data/lib/simple/http.rb +16 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45910b0d50187f5fcfb6ada7bd0b93718b2d9a74
|
4
|
+
data.tar.gz: a3daf4073ade9170518cd3528f7fc60098626118
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83c053ef9e4d81b888cc545a4b074f4eedb7ee5ddebf3879a951cabcde0719b06fe5d195f527edbe41b0384715660c6fe70e2c539c5a5219141d84f75cfea316
|
7
|
+
data.tar.gz: fdaeffe33eec00750bb1849de6affc72d462ce2a10c21fe811b926315a687d303cef8af56f2edd582d6b444719dbea1eb5f0c0dca5f8c0f0f0fd5e33c6726a43
|
data/lib/simple/http/version.rb
CHANGED
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.
|
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-
|
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
|