curlify 1.2.0 → 2.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/README.md +117 -4
- data/lib/curlify.rb +9 -6
- data/lib/settings.rb +24 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 61f726c478086bdbcaddeb6b7854c5436e712d489de412a94d9fc4d11ab64ae8
|
|
4
|
+
data.tar.gz: a61aa42711acf30bfb6ed41e00dc8b9f4731a1a7f296e4dfccd287f70196f4e6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 998ad7457a2f3d50d99dc0481bb58af0e97a25d74ea0edf0d90255971dfee299a6b308a0c39a4b82ada657628fc8510d12a25eb4740f6392ff8b493ce06f05da
|
|
7
|
+
data.tar.gz: 28d7484b3fdeaaffa253885646577db7986735e2938dbb25c7c5f7224af002505548bbb923cdd390387336d22293220a9f3aded5fbb3c2031e0070afedc9a654
|
data/README.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
The gem converts ruby requests to curl
|
|
2
2
|
|
|
3
|
+
## Features
|
|
4
|
+
|
|
5
|
+
- **Multi-Framework Support**: Works with Faraday and Net::HTTP requests
|
|
6
|
+
- **Clipboard Integration**: Copy generated curl commands directly to clipboard (macOS, Windows, Linux)
|
|
7
|
+
- **Configuration Management**: YAML-based settings for customizing Curlify behavior
|
|
8
|
+
- **Simple API**: Easy-to-use interface with minimal configuration required
|
|
9
|
+
|
|
3
10
|
## Installation
|
|
4
11
|
|
|
5
12
|
To install the gem use `bundle` or `gem`, see:
|
|
@@ -55,15 +62,121 @@ Supported platforms:
|
|
|
55
62
|
- Windows: uses `clip`
|
|
56
63
|
- Linux: uses `xclip` (must be installed and available in `PATH`)
|
|
57
64
|
|
|
58
|
-
|
|
65
|
+
If `xclip` is not available on Linux, Curlify will print a warning: `Curlify Warning: 'xclip' is required for clipboard support on Linux.`
|
|
66
|
+
|
|
67
|
+
## Configuration
|
|
68
|
+
|
|
69
|
+
Curlify supports configuration management through a YAML settings file. You can customize the default behavior by creating a `settings.yml` configuration file in your `config` directory.
|
|
70
|
+
|
|
71
|
+
### Creating Your Configuration File
|
|
72
|
+
|
|
73
|
+
#### Step 1: Create the config directory (if it doesn't exist)
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
mkdir -p config
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
#### Step 2: Create the settings.yml file
|
|
80
|
+
|
|
81
|
+
Create a file named `settings.yml` in the `config` directory:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
touch config/settings.yml
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
#### Step 3: Configure your settings
|
|
88
|
+
|
|
89
|
+
Open `config/settings.yml` and add your Curlify configuration options:
|
|
90
|
+
|
|
91
|
+
```yaml
|
|
92
|
+
# config/settings.yml
|
|
93
|
+
clipboard: false
|
|
94
|
+
verify: true
|
|
95
|
+
compressed: false
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Available Configuration Options
|
|
99
|
+
|
|
100
|
+
- **clipboard** (boolean, default: `false`): Automatically copy generated curl commands to the clipboard
|
|
101
|
+
- `true`: Copy curl command to clipboard
|
|
102
|
+
- `false`: Only return the curl string
|
|
103
|
+
|
|
104
|
+
- **verify** (boolean, default: `true`): Verify SSL certificates when making requests
|
|
105
|
+
- `true`: Verify SSL certificates
|
|
106
|
+
- `false`: Skip SSL verification (use with caution)
|
|
107
|
+
|
|
108
|
+
- **compressed** (boolean, default: `false`): Add compression support to curl commands
|
|
109
|
+
- `true`: Add `--compressed` flag to curl command
|
|
110
|
+
- `false`: No compression flag
|
|
111
|
+
|
|
112
|
+
### Usage Examples
|
|
113
|
+
|
|
114
|
+
#### Example 1: Basic Configuration
|
|
115
|
+
|
|
116
|
+
```yaml
|
|
117
|
+
# config/settings.yml
|
|
118
|
+
clipboard: false
|
|
119
|
+
verify: true
|
|
120
|
+
compressed: false
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Then use Curlify normally:
|
|
59
124
|
|
|
60
125
|
```ruby
|
|
61
|
-
|
|
62
|
-
|
|
126
|
+
require 'faraday'
|
|
127
|
+
require 'curlify'
|
|
128
|
+
|
|
129
|
+
request = Faraday.new.build_request(:post) do |req|
|
|
130
|
+
req.url 'http://127.0.0.1'
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
# Uses settings from config/settings.yml
|
|
134
|
+
Curlify.new(request).to_curl
|
|
63
135
|
```
|
|
64
136
|
|
|
65
|
-
|
|
137
|
+
#### Example 2: Enable Clipboard Support
|
|
138
|
+
|
|
139
|
+
```yaml
|
|
140
|
+
# config/settings.yml
|
|
141
|
+
clipboard: true
|
|
142
|
+
verify: true
|
|
143
|
+
compressed: false
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Now every curl command will be automatically copied to your clipboard:
|
|
147
|
+
|
|
148
|
+
```ruby
|
|
149
|
+
require 'faraday'
|
|
150
|
+
require 'curlify'
|
|
151
|
+
|
|
152
|
+
request = Faraday.new.build_request(:get) do |req|
|
|
153
|
+
req.url 'https://api.example.com/data'
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
curl_command = Curlify.new(request).to_curl
|
|
157
|
+
# curl_command is now in your clipboard!
|
|
158
|
+
puts curl_command
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
#### Example 3: Production Configuration
|
|
162
|
+
|
|
163
|
+
```yaml
|
|
164
|
+
# config/settings.yml
|
|
165
|
+
clipboard: false
|
|
166
|
+
verify: true
|
|
167
|
+
compressed: true
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
This configuration is suitable for production environments where you want:
|
|
171
|
+
- No automatic clipboard operations
|
|
172
|
+
- SSL verification enabled for security
|
|
173
|
+
- Compressed curl commands
|
|
174
|
+
|
|
175
|
+
### Troubleshooting
|
|
66
176
|
|
|
177
|
+
- **Configuration file not found**: Make sure the `config/settings.yml` file exists in your project root directory
|
|
178
|
+
- **Settings not loading**: Verify the YAML syntax is correct (indentation matters in YAML)
|
|
179
|
+
- **Clipboard not working on Linux**: Ensure `xclip` is installed: `sudo apt-get install xclip`
|
|
67
180
|
|
|
68
181
|
Performing this curl command, we can see the following result:
|
|
69
182
|
|
data/lib/curlify.rb
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'faraday'
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
require_relative 'settings'
|
|
5
6
|
|
|
6
7
|
class Curlify
|
|
7
|
-
attr_reader :request
|
|
8
|
+
attr_reader :request
|
|
8
9
|
|
|
9
|
-
def initialize(request
|
|
10
|
+
def initialize(request)
|
|
10
11
|
@request = request
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
|
|
13
|
+
Settings.call.each do |key, value|
|
|
14
|
+
instance_variable_set("@#{key}", value)
|
|
15
|
+
define_singleton_method(key) { instance_variable_get("@#{key}") }
|
|
16
|
+
end
|
|
14
17
|
end
|
|
15
18
|
|
|
16
19
|
def to_curl
|
data/lib/settings.rb
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'yaml'
|
|
2
|
+
|
|
3
|
+
class Settings
|
|
4
|
+
def self.call
|
|
5
|
+
new.send(:params)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
private
|
|
9
|
+
|
|
10
|
+
def params
|
|
11
|
+
YAML.safe_load(
|
|
12
|
+
read_file,
|
|
13
|
+
permitted_classes: [],
|
|
14
|
+
permitted_symbols: [],
|
|
15
|
+
aliases: true
|
|
16
|
+
)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def read_file
|
|
20
|
+
File.read(
|
|
21
|
+
File.join('config', 'settings.yml')
|
|
22
|
+
)
|
|
23
|
+
end
|
|
24
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: curlify
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Marcus Almeida
|
|
@@ -35,6 +35,7 @@ files:
|
|
|
35
35
|
- LICENSE
|
|
36
36
|
- README.md
|
|
37
37
|
- lib/curlify.rb
|
|
38
|
+
- lib/settings.rb
|
|
38
39
|
homepage: https://rubygems.org/gems/curlify
|
|
39
40
|
licenses:
|
|
40
41
|
- MIT
|