yobi-http 0.16.0 → 0.18.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3558906f242a7670158833610ad7b062bf25e308e4985804241bdba30a9d6968
4
- data.tar.gz: d96e600ccdf03ebcddb0c9ce14a3a2c141fb1a1ba2ffe04ee7cdb0a1a5383c7d
3
+ metadata.gz: b5994458b4f28cc4879858782a1dbc26a90f8ab77d7bf97b5a13ee7aaec13092
4
+ data.tar.gz: ac095c048327a1ce8260f388dcc414c647fa9f912f15ab9f43fabb1327225f69
5
5
  SHA512:
6
- metadata.gz: 68ec04f8b731ebc0e9f508ed332d6414292963d1dbbd97aaba96a360e930ce3d1421812d11c1031305126633db9ad012fb2f4efa6e170aba4e09e3eeef37cf3e
7
- data.tar.gz: 61c69a1bfdc761df2c791396fb84a3ce5183bf24b71ffb4073fbebdbd1e86b3e5e6986fbeeb977a7c2225624d72d083270e585e0afe186030066b3dab05f0e6c
6
+ metadata.gz: 9a1db1c25476849b0169d3d535d3ced35f2d14034363617211aff38f7903970d9056269231d83e8617392c66587eae32ef42fd573080bd3f5165d8b7de63f63f
7
+ data.tar.gz: 2ba909e076ccf9a12ff9f624ebe545675d6c540aaa248951a0ff7a5504a38d476c38b07e1fe321e5de921fd693a01be84dcee6169f6a23cde0ce7e01c3020c95
data/README.md CHANGED
@@ -2,29 +2,198 @@
2
2
  [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
3
3
  [![Maintainability](https://qlty.sh/gh/dvinciguerra/projects/yobi-http/maintainability.svg)](https://qlty.sh/gh/dvinciguerra/projects/yobi-http)
4
4
 
5
- # Yobi(呼び) Http Client
5
+ # :zap: Yobi(呼び) Http Client
6
6
 
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
8
- and flexible, allowing you to customize your requests as needed.
9
-
10
- Its a lightweight implementation of the HTTPie tool, which is a command-line HTTP client that allows you to make
11
- HTTP requests and view the responses in a human-friendly format.
7
+ Yobi (呼び) is a modern HTTP client for the command line, written in Ruby, that makes interacting with APIs simple, intuitive, and fun. Inspired by HTTPie, Yobi provides an elegant way to make HTTP requests with formatted and readable output.
12
8
 
13
9
  ![](./screenshot.png)
14
10
 
11
+ #### Main Features
12
+
13
+ * Simple and intuitive interface - Natural and easy-to-remember syntax
14
+ * Automatic formatting - JSON responses with syntax highlighting
15
+ * Multiple authentication types - Basic, Bearer, Digest, and more
16
+ * File download - Save responses directly to files
17
+ * Redirect tracking - Automatically follow HTTP redirects
18
+ * Customizable output - Control exactly what you want to see (headers, body, or both)
19
+ * Full HTTP support - GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS
20
+ * Offline mode - Prepare and review requests without sending them
21
+ * No heavy dependencies - Quick installation via RubyGems
22
+ * Raw mode - Raw output for integration with other tools
23
+
24
+
15
25
  ## Installation
16
26
 
27
+ #### Prerequisites
28
+
29
+ * Ruby >= 3.0.0
30
+ * RubyGems (usually included with Ruby)
31
+
32
+ #### Via RubyGems (Recommended)
33
+
34
+ ```bash
35
+ gem install yobi-http
36
+ ```
37
+
38
+ #### From Source Code
39
+
17
40
  ```bash
41
+ # Clone the repository
42
+ git clone https://github.com/dvinciguerra/yobi-http.git
43
+ cd yobi-http
44
+
45
+ # Install dependencies
46
+ bundle install
47
+
48
+ # Install the gem locally
49
+ bundle exec rake install```bash
18
50
  gem install yobi-http
19
51
  ```
20
52
 
21
- ## Usage
53
+ #### Check Installation
54
+
55
+ ```bash
56
+ yobi --version
57
+ ```
58
+
59
+ If you receive command not found: yobi:
60
+
61
+ * Ensure that the RubyGems bin directory is in your PATH.
62
+ * Try using gem which yobi-http to locate the installation.
63
+
64
+
65
+ ## Quick Guide
66
+
67
+ #### Basic Syntax
68
+
69
+ ```bash
70
+ yobi [METHOD] <url> [HEADER:VALUE] [key=value] [key::value]
71
+ ```
72
+
73
+ ### Instant Examples
74
+
75
+ ```bash
76
+ # Simple GET
77
+ yobi https://api.github.com/users/github
78
+
79
+ # POST with JSON
80
+ yobi POST https://jsonplaceholder.typicode.com/posts \
81
+ title="Hello" \
82
+ body="World" \
83
+ userId=1
84
+
85
+ # With authentication
86
+ yobi -A basic -a username:password https://api.example.com/data
87
+
88
+ # WITH custom header
89
+ yobi GET https://api.example.com/data \
90
+ Authorization:"Bearer your_token_here"
91
+
92
+ # Save response to file
93
+ yobi https://api.example.com/data -o response.json
94
+
95
+ # Use localhost shortcut
96
+ yobi :8080/api/items
97
+ # Expands to: http://localhost:8080/api/items
98
+ ```
99
+
100
+ **JSONPlaceholder API (Testing Service)**
101
+
102
+ ```bash
103
+ # Get all posts
104
+ yobi https://jsonplaceholder.typicode.com/posts
105
+
106
+ # Get specific post
107
+ yobi https://jsonplaceholder.typicode.com/posts/1
108
+
109
+ # Create new post
110
+ yobi POST https://jsonplaceholder.typicode.com/posts \
111
+ title="My new post" \
112
+ body="This is the content" \
113
+ userId=1
114
+
115
+ # Update post
116
+ yobi PUT https://jsonplaceholder.typicode.com/posts/1 \
117
+ title="Updated title"
118
+
119
+ # Delete post
120
+ yobi DELETE https://jsonplaceholder.typicode.com/posts/1
121
+ ```
122
+
123
+ **GitHub API**
124
+
125
+ ```bash
126
+ # User information
127
+ yobi https://api.github.com/users/dvinciguerra
128
+
129
+ # User repositories
130
+ yobi https://api.github.com/users/dvinciguerra/repos
131
+
132
+ # With authentication (personal token)
133
+ yobi -A bearer -a your_github_token https://api.github.com/user
134
+ ```
135
+
136
+ **HTTPBin (API Testing Tool)**
137
+
138
+ ```bash
139
+ # GET with query params
140
+ yobi https://httpbin.org/get name=John age=30
141
+
142
+ # POST with JSON
143
+ yobi POST https://httpbin.org/post name=John age:=30 active:=true
144
+
145
+ # Custom headers
146
+ yobi https://httpbin.org/headers \
147
+ "X-Custom:value" \
148
+ "User-Agent:Yobi/1.0"
149
+
150
+ # Basic authentication test
151
+ yobi https://httpbin.org/basic-auth/username/password \
152
+ -A basic -a username:password
153
+
154
+ # Simulate delay
155
+ yobi https://httpbin.org/delay/5
156
+
157
+ # Test timeout
158
+ yobi --timeout 2 https://httpbin.org/delay/10
159
+ ```
160
+
161
+ **Typical REST API**
162
+
163
+ ```bash
164
+ # List resources
165
+ yobi GET https://api.example.com/v1/users
166
+
167
+ # Create resource
168
+ yobi POST https://api.example.com/v1/users \
169
+ name="John Silva" \
170
+ email="john@example.com" \
171
+ department="IT"
172
+
173
+ # Update resource
174
+ yobi PUT https://api.example.com/v1/users/123 \
175
+ name="John da Silva" \
176
+ department="Development"
177
+
178
+ # Partial update
179
+ yobi PATCH https://api.example.com/v1/users/123 \
180
+ department="Management"
181
+
182
+ # Delete resource
183
+ yobi DELETE https://api.example.com/v1/users/123
184
+
185
+ # With pagination
186
+ yobi GET https://api.example.com/v1/users \
187
+ page:=1 \
188
+ limit:=10
189
+
190
+ # With filters
191
+ yobi GET https://api.example.com/v1/users \
192
+ department="IT" \
193
+ status="active"
194
+ ```
22
195
 
23
- Some examples of how to use yobi:
24
196
 
25
- - `yobi GET https://jsonplaceholder.typicode.com/posts/1` - Makes a GET request to the specified URL and prints the response.
26
- - `yobi POST https://jsonplaceholder.typicode.com/posts title="foo" body="bar" userId=1` - Makes a POST request to the specified URL with the given data and prints the response.
27
- - `yobi GET https://jsonplaceholder.typicode.com/posts/1 Authorization:"Bearer <token>"` - Makes a GET request to the specified URL with the given header and prints the response.
28
197
 
29
198
  ## Development
30
199
 
data/exe/yobi CHANGED
@@ -53,6 +53,21 @@ parser = OptionParser.new do |opts|
53
53
  @options[:raw] = true
54
54
  end
55
55
 
56
+ opts.on("-h", "--headers", "Print only response headers") do
57
+ @options[:raw] = true
58
+ @options[:print] = "H"
59
+ end
60
+
61
+ opts.on("-b", "--body", "Print only response body") do
62
+ @options[:raw] = true
63
+ @options[:print] = "B"
64
+ end
65
+
66
+ opts.on("--status", "Print only response status code") do
67
+ @options[:raw] = true
68
+ @options[:print] = "status"
69
+ end
70
+
56
71
  opts.on("--form", "Send data as application/x-www-form-urlencoded instead of JSON") do
57
72
  @options[:content_type] = :form
58
73
  end
@@ -74,11 +89,6 @@ parser = OptionParser.new do |opts|
74
89
  @options[:content_type] = :json
75
90
  end
76
91
 
77
- opts.on("-h", "--help", "Print this help message") do
78
- puts opts
79
- exit
80
- end
81
-
82
92
  opts.on("--offline", "Run in offline mode (prepare request but do not send)") do
83
93
  @options[:offline] = true
84
94
  end
@@ -112,6 +122,11 @@ parser = OptionParser.new do |opts|
112
122
  puts "#{Yobi.name} v#{Yobi::VERSION}"
113
123
  exit
114
124
  end
125
+
126
+ opts.on("--help", "Print this help message") do
127
+ puts opts
128
+ exit
129
+ end
115
130
  end
116
131
 
117
132
  parser.parse!(ARGV)
@@ -145,7 +160,9 @@ Yobi::Http.request(method, url, data: data, headers: headers, query: query, opti
145
160
  end
146
161
 
147
162
  # render output
148
- if options[:raw]
163
+ if options[:raw] && options[:print].downcase == "status"
164
+ print response.code
165
+ elsif options[:raw]
149
166
  Yobi::Renders::Raw.render(request, response, options)
150
167
  else
151
168
  Yobi::Renders::Colored.render(request, response, options)
data/lib/yobi/http.rb CHANGED
@@ -41,10 +41,16 @@ module Yobi
41
41
  request.body = data.to_json unless data.empty?
42
42
 
43
43
  yield(http, request) if block_given?
44
- rescue Net::OpenTimeout, Net::ReadTimeout => e
45
- warn "Request timed out: #{e.message}"
46
- exit 1
47
44
  end
45
+ rescue Net::OpenTimeout, Net::ReadTimeout => e
46
+ warn "Timeout: #{e.message}"
47
+ exit 1
48
+ rescue SocketError, Socket::ResolutionError => e
49
+ warn "Network error: #{e.message}"
50
+ exit 1
51
+ rescue StandardError => e
52
+ warn "Error: #{e.message}"
53
+ exit 1
48
54
  end
49
55
  # rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/ParameterLists
50
56
 
data/lib/yobi/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Yobi
4
4
  # Yobi gem version
5
- VERSION = "0.16.0"
5
+ VERSION = "0.18.0"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yobi-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.0
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Vinciguerra