relax2 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -44
- data/lib/relax2/interceptors.rb +4 -4
- data/lib/relax2/version.rb +1 -1
- 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: b1d4754cf78cfd9cd14ad07199bf060cb7acc8a42f9a0421ad1e9dc6cc0e6e28
|
4
|
+
data.tar.gz: ac42d0f018143b035d0a63be94f7e4bdbdff0e3a15712e04b18551bf33453f33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c90cf246bda20a707020e8f2b08764b457e0d22d3a8fe758c16e80f3a00ba3facd7f328b5a4e8f2290810e66fae4bbea4661f708b3c5fa7cc4ea597600d7e4fa
|
7
|
+
data.tar.gz: 62e13d0fe05f8091773f0ea6db7471e20686af49980b2c10707355db9e5068aa997b1a7c087787ae13f0ead4bd4e28f03df3528595c5732336049a907d6be147
|
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
|
|
45
|
+
# Request manually
|
81
46
|
request = Relax2::Request.from_string('GET /hogehoge q=xx USER-Agent: Hoge/1.23')
|
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
|
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- YusukeIwaki
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-07-
|
11
|
+
date: 2022-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|