yobi-http 0.12.3 → 0.14.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/Examples.md +7 -0
- data/README.md +4 -0
- data/lib/yobi/cli/arguments.rb +29 -2
- data/lib/yobi/version.rb +1 -1
- data/spec/yobi/cli/arguments_spec.rb +47 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 42bdd81cec29bd949acd4b1a96698e219bc6298a71eced3aa36c8cee4b965dc4
|
|
4
|
+
data.tar.gz: f0cf545e7c5d13f5543dbbfa63e72d563d03afc12d74cdbd45c47479f14064a6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bf2635eba8c559e6459d638dd944d315cb571833d60cffa208a7629d4d07110c86a39ac924b18639e3e94381575ea2cdbf039c70e9186006f69f11f889a8ae30
|
|
7
|
+
data.tar.gz: 98f048dbbf3512cb34782e14d26f737a06ea6ce68ca75ab2df13b158d5a8b8f00e9d7a0f7d08b0518254559ca587ee6bc5114bed543b61522816387ccab9a8be
|
data/Examples.md
CHANGED
|
@@ -23,6 +23,13 @@ yobi --debug POST https://httpbin.org/post name=Yobi type="HTTP client"
|
|
|
23
23
|
yobi --debug POST https://httpbin.org/post name=Yobi type="HTTP client" --form
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
+
## HTTP request with complex JSON body
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
yobi --debug POST https://httpbin.org/post name=Yobi meta:='{"category": "HTTP client", "type": "rubygem", "year": 2026 }' released:=true tags:'["ruby", "http", "gem"]'
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
|
|
26
33
|
## HTTP request with query parameters
|
|
27
34
|
|
|
28
35
|
```bash
|
data/README.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
[](https://badge.fury.io/rb/yobi-http)
|
|
2
|
+
[](https://opensource.org/licenses/MIT)
|
|
3
|
+
[](https://qlty.sh/gh/dvinciguerra/projects/yobi-http)
|
|
4
|
+
|
|
1
5
|
# Yobi(呼び) Http Client
|
|
2
6
|
|
|
3
7
|
Yobi is a Ruby gem that provides a simple and efficient way to make HTTP requests. It is designed to be easy to use
|
data/lib/yobi/cli/arguments.rb
CHANGED
|
@@ -22,13 +22,40 @@ module Yobi
|
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
25
26
|
def parse_data(args)
|
|
26
|
-
args.select { |arg| arg.
|
|
27
|
+
args.select { |arg| arg.match?("^.*(=|:=|=@|:=@).*$") }.map.to_h do |arg|
|
|
28
|
+
case arg
|
|
29
|
+
when /:=@/
|
|
30
|
+
arg.split(/:=@/, 2).map do |part|
|
|
31
|
+
part = String(part)&.strip
|
|
32
|
+
File.exist?(part) ? JSON.parse(File.read(part)) : part
|
|
33
|
+
end
|
|
34
|
+
when /:=/
|
|
35
|
+
arg.split(/:=/, 2).map.with_index do |part, index|
|
|
36
|
+
part = String(part)&.strip
|
|
37
|
+
index.zero? ? part : JSON.parse(part)
|
|
38
|
+
rescue JSON::ParserError => e
|
|
39
|
+
warn "Error #{e}: #{part}"
|
|
40
|
+
exit 1
|
|
41
|
+
end
|
|
42
|
+
when /=@/
|
|
43
|
+
arg.split(/=@/, 2).map do |part|
|
|
44
|
+
part = String(part)&.strip
|
|
45
|
+
File.exist?(part) ? File.read(part)&.strip : part
|
|
46
|
+
end
|
|
47
|
+
else
|
|
48
|
+
arg.split("=", 2).map(&:strip)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
27
51
|
end
|
|
52
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
28
53
|
|
|
29
54
|
def parse_headers(args)
|
|
30
55
|
{ "Content-Type" => "application/json", "User-Agent" => "#{Yobi.name}/#{Yobi::VERSION}" }
|
|
31
|
-
.merge(args.select
|
|
56
|
+
.merge(args.select do |arg|
|
|
57
|
+
arg.match?(/:/) && !arg.match?(/:=/)
|
|
58
|
+
end.map.to_h { |arg| arg.split(":", 2).map(&:strip) })
|
|
32
59
|
end
|
|
33
60
|
|
|
34
61
|
def auth_header(headers, options)
|
data/lib/yobi/version.rb
CHANGED
|
@@ -59,6 +59,53 @@ RSpec.describe Yobi::CLI::Arguments do
|
|
|
59
59
|
|
|
60
60
|
expect(described_class.parse_data(args)).to eq({ "name" => "John", "age" => "30" })
|
|
61
61
|
end
|
|
62
|
+
|
|
63
|
+
context "when given an json string" do
|
|
64
|
+
it "parses the json string into a hash" do
|
|
65
|
+
args = ['data:={ "name": "John", "age": 30, "admin": false, "friends": ["Jane", "Doe"] }']
|
|
66
|
+
|
|
67
|
+
expect(described_class.parse_data(args))
|
|
68
|
+
.to eq({ "data" => { "name" => "John", "age" => 30, "admin" => false, "friends" => %w[Jane Doe] } })
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "raises an error if the json string is invalid" do
|
|
72
|
+
args = ['data:={"name": "John", "age": 30, "city": "New York"'] # Missing closing brace
|
|
73
|
+
|
|
74
|
+
expect { described_class.parse_data(args) }.to raise_error(SystemExit)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
context "when given a json file path" do
|
|
79
|
+
let(:json_content) do
|
|
80
|
+
{
|
|
81
|
+
"title" => "Sample JSON",
|
|
82
|
+
"description" => "This is a sample JSON file.",
|
|
83
|
+
"version" => 1.0,
|
|
84
|
+
"tags" => %w[sample json example],
|
|
85
|
+
"metadata" => {
|
|
86
|
+
"author" => "John Doe",
|
|
87
|
+
"created" => "2024-06-01T12:00:00Z",
|
|
88
|
+
"updated" => "2024-06-10T15:30:00Z"
|
|
89
|
+
},
|
|
90
|
+
"published" => true,
|
|
91
|
+
"more_info" => nil
|
|
92
|
+
}
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
before do
|
|
96
|
+
File.write("sample.json", json_content.to_json)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
after do
|
|
100
|
+
File.delete("sample.json") if File.exist?("sample.json")
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it "parses the json file content into a hash" do
|
|
104
|
+
args = ["data:=@sample.json"]
|
|
105
|
+
|
|
106
|
+
expect(described_class.parse_data(args)).to eq({ "data" => json_content })
|
|
107
|
+
end
|
|
108
|
+
end
|
|
62
109
|
end
|
|
63
110
|
|
|
64
111
|
describe ".parse_headers" do
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: yobi-http
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.14.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniel Vinciguerra
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-02-
|
|
10
|
+
date: 2026-02-27 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: base64
|