httpdisk 0.5.1 → 1.0.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 +4 -4
- data/.github/workflows/test.yml +4 -8
- data/.rubocop.yml +10 -24
- data/Gemfile +7 -7
- data/Gemfile.lock +51 -54
- data/README.md +8 -2
- data/Rakefile +3 -56
- data/bin/httpdisk +8 -8
- data/bin/httpdisk-grep +9 -9
- data/examples.rb +17 -17
- data/httpdisk.gemspec +17 -16
- data/justfile +59 -0
- data/lib/httpdisk/cache.rb +7 -6
- data/lib/httpdisk/cache_key.rb +19 -19
- data/lib/httpdisk/cli/args.rb +27 -27
- data/lib/httpdisk/cli/main.rb +12 -12
- data/lib/httpdisk/client.rb +12 -12
- data/lib/httpdisk/grep/args.rb +10 -10
- data/lib/httpdisk/grep/main.rb +27 -24
- data/lib/httpdisk/grep/printer.rb +5 -4
- data/lib/httpdisk/payload.rb +3 -3
- data/lib/httpdisk/slop_duration.rb +3 -3
- data/lib/httpdisk/sloptions.rb +4 -4
- data/lib/httpdisk/version.rb +1 -1
- data/lib/httpdisk.rb +13 -13
- metadata +14 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e8bd4c770fe2a79111e7982da74b93e1e88c57621dbb3ea1b35568cdea0fe9e
|
4
|
+
data.tar.gz: f150fa699c26a0fe807e3320686095d380cf87210171d0d4eab5191108b9791a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4e498b766f2ead95de238bb8825946a8ff2e58314ed0323fc384759fe299d73ee9491c54a36f4f2bfe03271175a936c5e6379c0fd3542a8a1d4dc17559c692b
|
7
|
+
data.tar.gz: 7fda2373b05a2103e6df000a2a83042aa5488572ca8c436806b6fbcb8703c8ed235a2a5fe721c064a2e456a280d934d5d68a2717cf44bff2eb54ec87aaa59fef
|
data/.github/workflows/test.yml
CHANGED
@@ -2,11 +2,7 @@ name: test
|
|
2
2
|
|
3
3
|
on:
|
4
4
|
push:
|
5
|
-
paths-ignore:
|
6
|
-
- '**.md'
|
7
5
|
pull_request:
|
8
|
-
paths-ignore:
|
9
|
-
- '**.md'
|
10
6
|
workflow_dispatch:
|
11
7
|
|
12
8
|
jobs:
|
@@ -15,12 +11,12 @@ jobs:
|
|
15
11
|
max-parallel: 3
|
16
12
|
matrix:
|
17
13
|
os: [ubuntu, macos]
|
18
|
-
ruby-version: [head, 3.
|
14
|
+
ruby-version: [head, 3.2, 3.1]
|
19
15
|
runs-on: ${{ matrix.os }}-latest
|
20
16
|
steps:
|
21
|
-
- uses: actions/checkout@
|
17
|
+
- uses: actions/checkout@v3
|
18
|
+
- uses: taiki-e/install-action@just
|
22
19
|
- uses: ruby/setup-ruby@v1
|
23
20
|
with:
|
24
21
|
ruby-version: ${{ matrix.ruby-version }}
|
25
|
-
- run:
|
26
|
-
- run: bundle exec rake test
|
22
|
+
- run: just ci
|
data/.rubocop.yml
CHANGED
@@ -1,28 +1,14 @@
|
|
1
|
+
require:
|
2
|
+
- standard
|
3
|
+
|
4
|
+
inherit_gem:
|
5
|
+
standard: config/base.yml
|
6
|
+
|
1
7
|
AllCops:
|
2
8
|
NewCops: enable
|
3
9
|
SuggestExtensions: false
|
10
|
+
TargetRubyVersion: 3.1
|
4
11
|
|
5
|
-
#
|
6
|
-
Style/
|
7
|
-
|
8
|
-
# minimal personal preference
|
9
|
-
Layout/CaseIndentation: { Enabled: false }
|
10
|
-
Layout/EndAlignment: { EnforcedStyleAlignWith: variable }
|
11
|
-
Lint/AssignmentInCondition: { Enabled: false }
|
12
|
-
Lint/NonLocalExitFromIterator: { Enabled: false }
|
13
|
-
Metrics: { Enabled: false }
|
14
|
-
Naming/MethodParameterName: { Enabled: false }
|
15
|
-
Naming/VariableNumber: { Enabled: false }
|
16
|
-
Style/Documentation: { Enabled: false }
|
17
|
-
Style/DoubleNegation: { Enabled: false }
|
18
|
-
Style/EmptyCaseCondition: { Enabled: false }
|
19
|
-
Style/FrozenStringLiteralComment: { Enabled: false }
|
20
|
-
Style/GuardClause: { Enabled: false }
|
21
|
-
Style/IfUnlessModifier: { Enabled: false }
|
22
|
-
Style/NegatedIf: { Enabled: false }
|
23
|
-
Style/NumericPredicate: { Enabled: false }
|
24
|
-
Style/ParallelAssignment: { Enabled: false }
|
25
|
-
Style/SoleNestedConditional: { Enabled: false }
|
26
|
-
Style/StderrPuts: { Enabled: false }
|
27
|
-
Style/TrailingCommaInArrayLiteral: { EnforcedStyleForMultiline: consistent_comma }
|
28
|
-
Style/TrailingCommaInHashLiteral: { EnforcedStyleForMultiline: consistent_comma }
|
12
|
+
# a couple of overrides
|
13
|
+
Style/RedundantReturn: { Enabled: false }
|
14
|
+
Style/HashSyntax: { EnforcedShorthandSyntax: always }
|
data/Gemfile
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
source
|
1
|
+
source "https://rubygems.org"
|
2
2
|
gemspec
|
3
3
|
|
4
4
|
group :development, :test do
|
5
|
-
gem
|
6
|
-
gem
|
7
|
-
gem
|
8
|
-
gem
|
9
|
-
gem
|
10
|
-
gem
|
5
|
+
gem "minitest"
|
6
|
+
gem "mocha"
|
7
|
+
gem "pry"
|
8
|
+
gem "rake"
|
9
|
+
gem "standard", require: false
|
10
|
+
gem "webmock"
|
11
11
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,87 +1,84 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
httpdisk (0.
|
4
|
+
httpdisk (1.0.0)
|
5
5
|
content-type (~> 0.0)
|
6
|
-
faraday (~>
|
6
|
+
faraday (~> 2.7)
|
7
7
|
faraday-cookie_jar (~> 0.0)
|
8
|
-
|
9
|
-
slop (~> 4.
|
8
|
+
faraday-follow_redirects (~> 0.0)
|
9
|
+
slop (~> 4.10)
|
10
10
|
|
11
11
|
GEM
|
12
12
|
remote: https://rubygems.org/
|
13
13
|
specs:
|
14
|
-
addressable (2.
|
15
|
-
public_suffix (>= 2.0.2, <
|
14
|
+
addressable (2.8.4)
|
15
|
+
public_suffix (>= 2.0.2, < 6.0)
|
16
16
|
ast (2.4.2)
|
17
17
|
coderay (1.1.3)
|
18
|
-
content-type (0.0.
|
19
|
-
parslet (~>
|
18
|
+
content-type (0.0.2)
|
19
|
+
parslet (~> 2.0)
|
20
20
|
crack (0.4.5)
|
21
21
|
rexml
|
22
22
|
domain_name (0.5.20190701)
|
23
23
|
unf (>= 0.0.5, < 1.0.0)
|
24
|
-
faraday (
|
25
|
-
faraday-
|
26
|
-
faraday-em_synchrony (~> 1.0)
|
27
|
-
faraday-excon (~> 1.1)
|
28
|
-
faraday-httpclient (~> 1.0.1)
|
29
|
-
faraday-net_http (~> 1.0)
|
30
|
-
faraday-net_http_persistent (~> 1.1)
|
31
|
-
faraday-patron (~> 1.0)
|
32
|
-
multipart-post (>= 1.2, < 3)
|
24
|
+
faraday (2.7.4)
|
25
|
+
faraday-net_http (>= 2.0, < 3.1)
|
33
26
|
ruby2_keywords (>= 0.0.4)
|
34
27
|
faraday-cookie_jar (0.0.7)
|
35
28
|
faraday (>= 0.8.0)
|
36
29
|
http-cookie (~> 1.0.0)
|
37
|
-
faraday-
|
38
|
-
|
39
|
-
faraday-
|
40
|
-
faraday-httpclient (1.0.1)
|
41
|
-
faraday-net_http (1.0.1)
|
42
|
-
faraday-net_http_persistent (1.1.0)
|
43
|
-
faraday-patron (1.0.0)
|
44
|
-
faraday_middleware (1.0.0)
|
45
|
-
faraday (~> 1.0)
|
30
|
+
faraday-follow_redirects (0.3.0)
|
31
|
+
faraday (>= 1, < 3)
|
32
|
+
faraday-net_http (3.0.2)
|
46
33
|
hashdiff (1.0.1)
|
47
|
-
http-cookie (1.0.
|
34
|
+
http-cookie (1.0.5)
|
48
35
|
domain_name (~> 0.5)
|
36
|
+
json (2.6.3)
|
37
|
+
language_server-protocol (3.17.0.3)
|
49
38
|
method_source (1.0.0)
|
50
|
-
minitest (5.
|
51
|
-
mocha (
|
52
|
-
|
53
|
-
parallel (1.
|
54
|
-
parser (3.
|
39
|
+
minitest (5.18.0)
|
40
|
+
mocha (2.0.2)
|
41
|
+
ruby2_keywords (>= 0.0.5)
|
42
|
+
parallel (1.23.0)
|
43
|
+
parser (3.2.2.1)
|
55
44
|
ast (~> 2.4.1)
|
56
|
-
parslet (
|
57
|
-
pry (0.
|
45
|
+
parslet (2.0.0)
|
46
|
+
pry (0.14.2)
|
58
47
|
coderay (~> 1.1)
|
59
48
|
method_source (~> 1.0)
|
60
|
-
public_suffix (
|
61
|
-
rainbow (3.
|
62
|
-
rake (13.0.
|
63
|
-
regexp_parser (2.
|
49
|
+
public_suffix (5.0.1)
|
50
|
+
rainbow (3.1.1)
|
51
|
+
rake (13.0.6)
|
52
|
+
regexp_parser (2.8.0)
|
64
53
|
rexml (3.2.5)
|
65
|
-
rubocop (1.
|
54
|
+
rubocop (1.44.1)
|
55
|
+
json (~> 2.3)
|
66
56
|
parallel (~> 1.10)
|
67
|
-
parser (>= 3.
|
57
|
+
parser (>= 3.2.0.0)
|
68
58
|
rainbow (>= 2.2.2, < 4.0)
|
69
59
|
regexp_parser (>= 1.8, < 3.0)
|
70
|
-
rexml
|
71
|
-
rubocop-ast (>= 1.
|
60
|
+
rexml (>= 3.2.5, < 4.0)
|
61
|
+
rubocop-ast (>= 1.24.1, < 2.0)
|
72
62
|
ruby-progressbar (~> 1.7)
|
73
|
-
unicode-display_width (>=
|
74
|
-
rubocop-ast (1.
|
75
|
-
parser (>= 3.
|
76
|
-
|
77
|
-
|
78
|
-
|
63
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
64
|
+
rubocop-ast (1.28.1)
|
65
|
+
parser (>= 3.2.1.0)
|
66
|
+
rubocop-performance (1.15.2)
|
67
|
+
rubocop (>= 1.7.0, < 2.0)
|
68
|
+
rubocop-ast (>= 0.4.0)
|
69
|
+
ruby-progressbar (1.13.0)
|
70
|
+
ruby2_keywords (0.0.5)
|
71
|
+
slop (4.10.1)
|
72
|
+
standard (1.24.3)
|
73
|
+
language_server-protocol (~> 3.17.0.2)
|
74
|
+
rubocop (= 1.44.1)
|
75
|
+
rubocop-performance (= 1.15.2)
|
79
76
|
unf (0.1.4)
|
80
77
|
unf_ext
|
81
|
-
unf_ext (0.0.
|
82
|
-
unicode-display_width (2.
|
83
|
-
webmock (3.
|
84
|
-
addressable (>= 2.
|
78
|
+
unf_ext (0.0.8.2)
|
79
|
+
unicode-display_width (2.4.2)
|
80
|
+
webmock (3.18.1)
|
81
|
+
addressable (>= 2.8.0)
|
85
82
|
crack (>= 0.3.2)
|
86
83
|
hashdiff (>= 0.4.0, < 2.0.0)
|
87
84
|
|
@@ -94,8 +91,8 @@ DEPENDENCIES
|
|
94
91
|
mocha
|
95
92
|
pry
|
96
93
|
rake
|
97
|
-
|
94
|
+
standard
|
98
95
|
webmock
|
99
96
|
|
100
97
|
BUNDLED WITH
|
101
|
-
2.
|
98
|
+
2.3.18
|
data/README.md
CHANGED
@@ -171,8 +171,9 @@ Specific to httpdisk:
|
|
171
171
|
|
172
172
|
## Goodies: httpdisk-grep
|
173
173
|
|
174
|
-
The `httpdisk-grep` command makes it easy to search your cache directory.
|
175
|
-
|
174
|
+
The `httpdisk-grep` command makes it easy to search your cache directory. It can be challenging to use grep/ripgrep because cache files are compressed and JSON bodies often lack newlines. httpdisk-grep is the right tool for the job. See `httpdisk-grep --help`.
|
175
|
+
|
176
|
+
An alternative is to use [ripgrep-all](https://github.com/phiresky/ripgrep-all) with the `--rga-accurate` flag. Ripgrep-all works well for large caches, though it lacks some of the niceties of `httpdisk-grep`.
|
176
177
|
|
177
178
|
## Limitations & Gotchas
|
178
179
|
|
@@ -184,6 +185,11 @@ It can be challenging to use grep/ripgrep because cache files are compressed and
|
|
184
185
|
|
185
186
|
## Changelog
|
186
187
|
|
188
|
+
#### 1.0
|
189
|
+
|
190
|
+
- support faraday 2, minimum Ruby is 3.1 now
|
191
|
+
- moved to Justfile and Standard
|
192
|
+
|
187
193
|
#### 0.5
|
188
194
|
|
189
195
|
- honor Content-Type
|
data/Rakefile
CHANGED
@@ -1,58 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "bundler/setup"
|
2
|
+
require "rake/testtask"
|
3
3
|
|
4
|
-
|
5
|
-
spec = Gem::Specification.load('httpdisk.gemspec')
|
6
|
-
|
7
|
-
#
|
8
|
-
# testing
|
9
|
-
# don't forget about TESTOPTS="--verbose" rake
|
10
|
-
#
|
11
|
-
|
12
|
-
# test (default)
|
13
|
-
Rake::TestTask.new do
|
14
|
-
_1.libs << 'test'
|
15
|
-
_1.warning = false # https://github.com/lostisland/faraday/issues/1285
|
16
|
-
end
|
4
|
+
Rake::TestTask.new
|
17
5
|
task default: :test
|
18
|
-
|
19
|
-
# Watch rb files, run tests whenever something changes
|
20
|
-
task :watch do
|
21
|
-
sh "find . -name '*.rb' | entr -c rake"
|
22
|
-
end
|
23
|
-
|
24
|
-
#
|
25
|
-
# pry
|
26
|
-
#
|
27
|
-
|
28
|
-
task :pry do
|
29
|
-
sh 'pry -I lib -r httpdisk.rb'
|
30
|
-
end
|
31
|
-
|
32
|
-
#
|
33
|
-
# rubocop
|
34
|
-
#
|
35
|
-
|
36
|
-
task :rubocop do
|
37
|
-
sh 'bundle exec rubocop -A .'
|
38
|
-
end
|
39
|
-
|
40
|
-
#
|
41
|
-
# gem
|
42
|
-
#
|
43
|
-
|
44
|
-
task :build do
|
45
|
-
sh 'gem build --quiet httpdisk.gemspec'
|
46
|
-
end
|
47
|
-
|
48
|
-
task install: :build do
|
49
|
-
sh "gem install --quiet httpdisk-#{spec.version}.gem"
|
50
|
-
end
|
51
|
-
|
52
|
-
task release: %i[rubocop test build] do
|
53
|
-
raise "looks like git isn't clean" unless `git status --porcelain`.empty?
|
54
|
-
|
55
|
-
sh "git tag -a #{spec.version} -m 'Tagging #{spec.version}'"
|
56
|
-
sh 'git push --tags'
|
57
|
-
sh "gem push httpdisk-#{spec.version}.gem"
|
58
|
-
end
|
data/bin/httpdisk
CHANGED
@@ -4,23 +4,23 @@
|
|
4
4
|
# Main bin. Most of the interesting stuff is in HTTPDisk, for ease of testing.
|
5
5
|
#
|
6
6
|
|
7
|
-
$LOAD_PATH.unshift(File.join(__dir__,
|
7
|
+
$LOAD_PATH.unshift(File.join(__dir__, "../lib"))
|
8
8
|
|
9
9
|
BIN = File.basename($PROGRAM_NAME)
|
10
10
|
|
11
11
|
def puts_error(s)
|
12
|
-
|
12
|
+
warn "#{BIN}: #{s}"
|
13
13
|
end
|
14
14
|
|
15
15
|
#
|
16
16
|
# Load the bare minimum and parse args with slop. We do this separately for speed.
|
17
17
|
#
|
18
18
|
|
19
|
-
require
|
19
|
+
require "httpdisk/cli/args"
|
20
20
|
begin
|
21
21
|
slop = HTTPDisk::Cli::Args.slop(ARGV)
|
22
22
|
rescue Slop::Error => e
|
23
|
-
puts_error(e) if e.message !=
|
23
|
+
puts_error(e) if e.message != ""
|
24
24
|
puts_error("try '#{BIN} --help' for more information")
|
25
25
|
exit 1
|
26
26
|
end
|
@@ -29,15 +29,15 @@ end
|
|
29
29
|
# now load everything and run
|
30
30
|
#
|
31
31
|
|
32
|
-
require
|
32
|
+
require "httpdisk"
|
33
33
|
main = HTTPDisk::Cli::Main.new(slop)
|
34
34
|
begin
|
35
35
|
main.run
|
36
|
-
rescue
|
36
|
+
rescue => e
|
37
37
|
puts_error(e) if !main.options[:silent]
|
38
|
-
if ENV[
|
38
|
+
if ENV["HTTPDISK_DEBUG"]
|
39
39
|
$stderr.puts
|
40
|
-
|
40
|
+
warn e.backtrace.join("\n")
|
41
41
|
end
|
42
42
|
exit 1
|
43
43
|
end
|
data/bin/httpdisk-grep
CHANGED
@@ -4,23 +4,23 @@
|
|
4
4
|
# Search an HTTPDisk cache, similar to grep.
|
5
5
|
#
|
6
6
|
|
7
|
-
$LOAD_PATH.unshift(File.join(__dir__,
|
7
|
+
$LOAD_PATH.unshift(File.join(__dir__, "../lib"))
|
8
8
|
|
9
9
|
BIN = File.basename($PROGRAM_NAME)
|
10
10
|
|
11
11
|
def puts_error(s)
|
12
|
-
|
12
|
+
warn "#{BIN}: #{s}"
|
13
13
|
end
|
14
14
|
|
15
15
|
#
|
16
16
|
# Load the bare minimum and parse args with slop. We do this separately for speed.
|
17
17
|
#
|
18
18
|
|
19
|
-
require
|
19
|
+
require "httpdisk/grep/args"
|
20
20
|
begin
|
21
21
|
slop = HTTPDisk::Grep::Args.slop(ARGV)
|
22
22
|
rescue Slop::Error => e
|
23
|
-
puts_error(e) if e.message !=
|
23
|
+
puts_error(e) if e.message != ""
|
24
24
|
puts_error("try '#{BIN} --help' for more information")
|
25
25
|
exit 1
|
26
26
|
end
|
@@ -29,18 +29,18 @@ end
|
|
29
29
|
# now load everything and run
|
30
30
|
#
|
31
31
|
|
32
|
-
require
|
32
|
+
require "httpdisk"
|
33
33
|
|
34
34
|
main = HTTPDisk::Grep::Main.new(slop)
|
35
35
|
begin
|
36
36
|
success = main.run
|
37
37
|
exit 1 if !success
|
38
|
-
rescue
|
38
|
+
rescue => e
|
39
39
|
puts_error(e)
|
40
|
-
if ENV[
|
40
|
+
if ENV["HTTPDISK_DEBUG"]
|
41
41
|
$stderr.puts
|
42
|
-
|
43
|
-
|
42
|
+
warn e.class
|
43
|
+
warn e.backtrace.join("\n")
|
44
44
|
end
|
45
45
|
exit 2
|
46
46
|
end
|
data/examples.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
$LOAD_PATH.unshift(File.join(__dir__,
|
3
|
+
$LOAD_PATH.unshift(File.join(__dir__, "lib"))
|
4
4
|
|
5
|
-
require
|
6
|
-
require
|
5
|
+
require "httpdisk"
|
6
|
+
require "json"
|
7
7
|
|
8
8
|
class Examples
|
9
9
|
#
|
@@ -15,12 +15,12 @@ class Examples
|
|
15
15
|
_1.use :httpdisk, force: true
|
16
16
|
end
|
17
17
|
|
18
|
-
faraday.get(
|
19
|
-
faraday.get(
|
20
|
-
faraday.post(
|
18
|
+
faraday.get("http://www.google.com", nil, {"User-Agent": "test-agent"})
|
19
|
+
faraday.get("http://www.google.com", {q: "ruby"})
|
20
|
+
faraday.post("http://httpbin.org/post", "name=hello")
|
21
21
|
|
22
22
|
3.times { puts }
|
23
|
-
response = faraday.get(
|
23
|
+
response = faraday.get("http://httpbingo.org/get")
|
24
24
|
puts response.env.url
|
25
25
|
puts JSON.pretty_generate(JSON.parse(response.body))
|
26
26
|
end
|
@@ -33,8 +33,8 @@ class Examples
|
|
33
33
|
def better
|
34
34
|
faraday = Faraday.new do
|
35
35
|
# options
|
36
|
-
_1.headers[
|
37
|
-
_1.params.update(hello:
|
36
|
+
_1.headers["User-Agent"] = "HTTPDisk"
|
37
|
+
_1.params.update(hello: "world")
|
38
38
|
_1.options.timeout = 10
|
39
39
|
|
40
40
|
# middleware
|
@@ -50,26 +50,26 @@ class Examples
|
|
50
50
|
retry_options = {
|
51
51
|
methods: %w[delete get head options patch post put trace],
|
52
52
|
retry_statuses: (400..600).to_a,
|
53
|
-
retry_if: ->(_env, _err) { true }
|
53
|
+
retry_if: ->(_env, _err) { true }
|
54
54
|
}.freeze
|
55
55
|
_1.request :retry, retry_options
|
56
56
|
end
|
57
57
|
|
58
58
|
# get w/ params
|
59
59
|
3.times { puts }
|
60
|
-
response = faraday.get(
|
60
|
+
response = faraday.get("http://httpbingo.org/get", {q: "query"})
|
61
61
|
puts response.env.url
|
62
62
|
puts JSON.pretty_generate(response.body)
|
63
63
|
|
64
64
|
# post w/ encoded form body
|
65
65
|
3.times { puts }
|
66
|
-
response = faraday.post(
|
66
|
+
response = faraday.post("http://httpbingo.org/post", "a=1&b=2")
|
67
67
|
puts response.env.url
|
68
68
|
puts JSON.pretty_generate(response.body)
|
69
69
|
|
70
70
|
# post w/ auto-encoded form hash
|
71
71
|
3.times { puts }
|
72
|
-
response = faraday.post(
|
72
|
+
response = faraday.post("http://httpbingo.org/post", {input: "body"})
|
73
73
|
puts response.env.url
|
74
74
|
puts JSON.pretty_generate(response.body)
|
75
75
|
end
|
@@ -82,8 +82,8 @@ class Examples
|
|
82
82
|
def json
|
83
83
|
faraday = Faraday.new do
|
84
84
|
# options
|
85
|
-
_1.headers[
|
86
|
-
_1.params.update(hello:
|
85
|
+
_1.headers["User-Agent"] = "HTTPDisk"
|
86
|
+
_1.params.update(hello: "world")
|
87
87
|
_1.options.timeout = 10
|
88
88
|
|
89
89
|
# middleware
|
@@ -99,13 +99,13 @@ class Examples
|
|
99
99
|
retry_options = {
|
100
100
|
methods: %w[delete get head options patch post put trace],
|
101
101
|
retry_statuses: (400..600).to_a,
|
102
|
-
retry_if: ->(_env, _err) { true }
|
102
|
+
retry_if: ->(_env, _err) { true }
|
103
103
|
}.freeze
|
104
104
|
_1.request :retry, retry_options
|
105
105
|
end
|
106
106
|
|
107
107
|
3.times { puts }
|
108
|
-
response = faraday.post(
|
108
|
+
response = faraday.post("http://httpbingo.org/post", {this_is: ["json"]})
|
109
109
|
puts response.env.url
|
110
110
|
puts JSON.pretty_generate(response.body)
|
111
111
|
end
|
data/httpdisk.gemspec
CHANGED
@@ -1,29 +1,30 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative "lib/httpdisk/version"
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
|
-
s.name =
|
4
|
+
s.name = "httpdisk"
|
5
5
|
s.version = HTTPDisk::VERSION
|
6
|
-
s.authors = [
|
7
|
-
s.email =
|
6
|
+
s.authors = ["Adam Doppelt"]
|
7
|
+
s.email = "amd@gurge.com"
|
8
8
|
|
9
|
-
s.summary =
|
10
|
-
s.description =
|
11
|
-
s.homepage =
|
12
|
-
s.license =
|
13
|
-
s.required_ruby_version =
|
9
|
+
s.summary = "httpdisk - disk cache for faraday"
|
10
|
+
s.description = "httpdisk works with faraday to aggressively cache responses on disk."
|
11
|
+
s.homepage = "http://github.com/gurgeous/httpdisk"
|
12
|
+
s.license = "MIT"
|
13
|
+
s.required_ruby_version = ">= 3.1.0"
|
14
|
+
s.metadata["rubygems_mfa_required"] = "true"
|
14
15
|
|
15
16
|
# what's in the gem?
|
16
17
|
s.files = Dir.chdir(File.expand_path(__dir__)) do
|
17
18
|
`git ls-files -z`.split("\x0").reject { _1.match(%r{^test/}) }
|
18
19
|
end
|
19
|
-
s.bindir =
|
20
|
+
s.bindir = "bin"
|
20
21
|
s.executables = s.files.grep(%r{^#{s.bindir}/}) { File.basename(_1) }
|
21
|
-
s.require_paths = [
|
22
|
+
s.require_paths = ["lib"]
|
22
23
|
|
23
24
|
# gem dependencies
|
24
|
-
s.add_dependency
|
25
|
-
s.add_dependency
|
26
|
-
s.add_dependency
|
27
|
-
s.add_dependency
|
28
|
-
s.add_dependency
|
25
|
+
s.add_dependency "content-type", "~> 0.0"
|
26
|
+
s.add_dependency "faraday", "~> 2.7"
|
27
|
+
s.add_dependency "faraday-cookie_jar", "~> 0.0"
|
28
|
+
s.add_dependency "faraday-follow_redirects", "~> 0.0"
|
29
|
+
s.add_dependency "slop", "~> 4.10"
|
29
30
|
end
|
data/justfile
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
|
2
|
+
# read gem version
|
3
|
+
gemver := `cat lib/httpdisk/version.rb | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+"`
|
4
|
+
|
5
|
+
#
|
6
|
+
# dev
|
7
|
+
#
|
8
|
+
|
9
|
+
default: test
|
10
|
+
|
11
|
+
check: lint test
|
12
|
+
|
13
|
+
fmt:
|
14
|
+
bundle exec rubocop -a
|
15
|
+
|
16
|
+
lint:
|
17
|
+
@just banner lint...
|
18
|
+
bundle exec rubocop
|
19
|
+
|
20
|
+
pry:
|
21
|
+
bundle exec pry -I lib -r httpdisk.rb
|
22
|
+
|
23
|
+
test:
|
24
|
+
@just banner test...
|
25
|
+
bundle exec rake test
|
26
|
+
|
27
|
+
watch:
|
28
|
+
@watchexec --watch lib --watch test --clear bundle exec rake test
|
29
|
+
|
30
|
+
#
|
31
|
+
# ci
|
32
|
+
#
|
33
|
+
|
34
|
+
ci:
|
35
|
+
bundle install
|
36
|
+
just check
|
37
|
+
|
38
|
+
#
|
39
|
+
# gem tasks
|
40
|
+
#
|
41
|
+
|
42
|
+
gem-push: check-git-status
|
43
|
+
@just banner gem build...
|
44
|
+
gem build httpdisk.gemspec
|
45
|
+
@just banner tag...
|
46
|
+
git tag -a "v{{gemver}}" -m "Tagging {{gemver}}"
|
47
|
+
git push --tags
|
48
|
+
@just banner gem push...
|
49
|
+
gem push "httpdisk-{{gemver}}.gem"
|
50
|
+
|
51
|
+
#
|
52
|
+
# util
|
53
|
+
#
|
54
|
+
|
55
|
+
banner *ARGS:
|
56
|
+
@printf '\e[42;37;1m[%s] %-72s \e[m\n' "$(date +%H:%M:%S)" "{{ARGS}}"
|
57
|
+
|
58
|
+
check-git-status:
|
59
|
+
@if [ ! -z "$(git status --porcelain)" ]; then echo "git status is dirty, bailing."; exit 1; fi
|
data/lib/httpdisk/cache.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
require
|
1
|
+
require "fileutils"
|
2
|
+
require "tempfile"
|
2
3
|
|
3
4
|
module HTTPDisk
|
4
5
|
# Disk cache for cache_keys => response. Files are compressed.
|
@@ -14,8 +15,8 @@ module HTTPDisk
|
|
14
15
|
options[method]
|
15
16
|
end
|
16
17
|
end
|
17
|
-
|
18
|
-
|
18
|
+
alias_method :force?, :force
|
19
|
+
alias_method :force_errors?, :force_errors
|
19
20
|
|
20
21
|
# Get cached response. If there is a cached error it will be raised.
|
21
22
|
def read(cache_key)
|
@@ -72,10 +73,10 @@ module HTTPDisk
|
|
72
73
|
return :force if force?
|
73
74
|
|
74
75
|
begin
|
75
|
-
payload = Zlib::GzipReader.open(path, encoding:
|
76
|
-
Payload.read(_1, peek:
|
76
|
+
payload = Zlib::GzipReader.open(path, encoding: "ASCII-8BIT") do
|
77
|
+
Payload.read(_1, peek:)
|
77
78
|
end
|
78
|
-
rescue
|
79
|
+
rescue => e
|
79
80
|
raise "#{path}: #{e}"
|
80
81
|
end
|
81
82
|
return :force if force_errors? && payload.error?
|