relax2 0.1.0 → 0.1.2
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/LICENSE +21 -0
- data/README.md +21 -45
- data/lib/relax2/interceptors.rb +6 -4
- data/lib/relax2/version.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c072b05f258411e87c18e1065cb6ca8a283d528104c0372eea8c4e785bcc871
|
4
|
+
data.tar.gz: 61f05cf1460f2d796c0e90052ebd550514642bf62665ac0bb34d74bf8bc87ab0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1729cb47a19c4f1d9a6a23678cb374f0351316175716ea9853ef755b93ddffb50b57e01473fbb23bab1950a12746a078f5ee8ae298ca22904012038b284a9df8
|
7
|
+
data.tar.gz: 323b17e9d0d6d00588ba543ad428160ca00e0cd19ea546eedff7eb1dd9a8c8d61f3aa8f4b0ab1e48c97034ca1932b4ce10c5c7a947240edaf74fa1cb393d4289
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2022 YusukeIwaki
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -8,56 +8,20 @@ require 'relax2'
|
|
8
8
|
|
9
9
|
base_url 'https://petstore.swagger.io/v2'
|
10
10
|
|
11
|
-
interceptor
|
12
|
-
|
13
|
-
response = perform_request.call(request)
|
14
|
-
puts response.body
|
15
|
-
response
|
16
|
-
end
|
11
|
+
interceptor :json_request
|
12
|
+
interceptor :print_response
|
17
13
|
```
|
18
14
|
|
19
15
|
Then enjoy your API calls.
|
20
16
|
|
21
17
|
```
|
22
18
|
% ruby petstore.rb GET /pet/2
|
23
|
-
{
|
24
|
-
"id": 2,
|
25
|
-
"category": {
|
26
|
-
"id": 5,
|
27
|
-
"name": "Angel"
|
28
|
-
},
|
29
|
-
"name": "DOG",
|
30
|
-
"tags": [
|
31
|
-
{
|
32
|
-
"id": 1,
|
33
|
-
"name": "Armanda Hirthe"
|
34
|
-
}
|
35
|
-
],
|
36
|
-
"status": "available"
|
37
|
-
}
|
19
|
+
{"id":2,"name":"doggie","photoUrls":[],"tags":[],"status":"available"}
|
38
20
|
```
|
39
21
|
|
40
22
|
```
|
41
|
-
|
42
|
-
{
|
43
|
-
"name": "NEW DOG"
|
44
|
-
}
|
45
|
-
|
46
|
-
{
|
47
|
-
"id": 2,
|
48
|
-
"category": {
|
49
|
-
"id": 5,
|
50
|
-
"name": "Angel"
|
51
|
-
},
|
52
|
-
"name": "NEW DOG",
|
53
|
-
"tags": [
|
54
|
-
{
|
55
|
-
"id": 1,
|
56
|
-
"name": "Armanda Hirthe"
|
57
|
-
}
|
58
|
-
],
|
59
|
-
"status": "available"
|
60
|
-
}
|
23
|
+
$ echo '{"id": 2, "name": "NEW DOG", "status": "unavailable"}' | ruby petstore.rb PUT /pet
|
24
|
+
{"id":2,"name":"NEW DOG","photoUrls":[],"tags":[],"status":"unavailable"}
|
61
25
|
```
|
62
26
|
|
63
27
|
If you want to create more detailed client, use the modular style with `Relax2::Base`.
|
@@ -78,12 +42,13 @@ class ExampleApi < Relax2::Base
|
|
78
42
|
end
|
79
43
|
end
|
80
44
|
|
81
|
-
|
45
|
+
# Request manually
|
46
|
+
request = Relax2::Request.from(args: 'GET /hogehoge q=xx USER-Agent: Hoge/1.23'.split(' '))
|
82
47
|
response = ExampleApi.call(request)
|
83
|
-
```
|
84
|
-
|
85
|
-
|
86
48
|
|
49
|
+
# or, simply work with CLI args :)
|
50
|
+
ExampleApi.run
|
51
|
+
```
|
87
52
|
|
88
53
|
## Installation
|
89
54
|
|
@@ -95,6 +60,17 @@ gem 'relax2'
|
|
95
60
|
|
96
61
|
and then `bundle install`
|
97
62
|
|
63
|
+
## References
|
64
|
+
|
65
|
+
### Examples
|
66
|
+
|
67
|
+
* Example of relax2 for [Android Management API](https://developers.google.com/android/management): https://github.com/YusukeIwaki/relax2-androidmanagement-api
|
68
|
+
|
69
|
+
### Other langs
|
70
|
+
|
71
|
+
* rakuda[https://github.com/YusukeIwaki/rakuda]: Dart implementation. Good for distributing in-house API client tool.
|
72
|
+
* [@zatsu/core](https://github.com/YusukeIwaki/zatsu-core): Node.js implementation. Useful for distribution with npx.
|
73
|
+
|
98
74
|
## Development
|
99
75
|
|
100
76
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/relax2/interceptors.rb
CHANGED
@@ -12,8 +12,8 @@ module Relax2
|
|
12
12
|
lines = []
|
13
13
|
lines << "#{request.http_method} #{request.path}"
|
14
14
|
if @print_headers
|
15
|
-
request.headers.each do |
|
16
|
-
lines << "#{
|
15
|
+
request.headers.each do |name, value|
|
16
|
+
lines << "#{name}: #{value}"
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -42,8 +42,8 @@ module Relax2
|
|
42
42
|
lines << "HTTP #{response.status}" if @print_status
|
43
43
|
|
44
44
|
if @print_headers
|
45
|
-
response.headers.each do |
|
46
|
-
lines << "#{
|
45
|
+
response.headers.each do |name, value|
|
46
|
+
lines << "#{name}: #{value}"
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -52,6 +52,8 @@ module Relax2
|
|
52
52
|
lines << response.body
|
53
53
|
end
|
54
54
|
puts lines.join("\n")
|
55
|
+
|
56
|
+
response
|
55
57
|
end
|
56
58
|
end
|
57
59
|
|
data/lib/relax2/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: relax2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- YusukeIwaki
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -150,7 +150,7 @@ dependencies:
|
|
150
150
|
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
|
-
description:
|
153
|
+
description:
|
154
154
|
email:
|
155
155
|
- q7w8e9w8q7w8e9@yahoo.co.jp
|
156
156
|
executables: []
|
@@ -159,6 +159,7 @@ extra_rdoc_files: []
|
|
159
159
|
files:
|
160
160
|
- ".rubocop.yml"
|
161
161
|
- Gemfile
|
162
|
+
- LICENSE
|
162
163
|
- README.md
|
163
164
|
- Rakefile
|
164
165
|
- bin/console
|
@@ -179,7 +180,7 @@ files:
|
|
179
180
|
homepage: https://github.com/YusukeIwaki/relax2
|
180
181
|
licenses: []
|
181
182
|
metadata: {}
|
182
|
-
post_install_message:
|
183
|
+
post_install_message:
|
183
184
|
rdoc_options: []
|
184
185
|
require_paths:
|
185
186
|
- lib
|
@@ -195,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
195
196
|
version: '0'
|
196
197
|
requirements: []
|
197
198
|
rubygems_version: 3.3.7
|
198
|
-
signing_key:
|
199
|
+
signing_key:
|
199
200
|
specification_version: 4
|
200
201
|
summary: A quick and dirty HTTP API client factory for Ruby
|
201
202
|
test_files: []
|