curlify 1.1.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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +133 -1
  3. data/lib/curlify.rb +41 -9
  4. data/lib/settings.rb +24 -0
  5. metadata +8 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a48b30cfd32c1b91c5a582817d8f14f4591a163d849e4bee0571e9a30b51e616
4
- data.tar.gz: ae6700a423572016a5c60ad5130921249d5f63cd8064761408fbce0022e88945
3
+ metadata.gz: 61f726c478086bdbcaddeb6b7854c5436e712d489de412a94d9fc4d11ab64ae8
4
+ data.tar.gz: a61aa42711acf30bfb6ed41e00dc8b9f4731a1a7f296e4dfccd287f70196f4e6
5
5
  SHA512:
6
- metadata.gz: 856229b5b419e3affd619dcb8844607eb89fe08335f6192171e624c57f304d4b0b4c870d3bc5d9e304ebe9598998c3ccc30198292267029818ff97588d4c1160
7
- data.tar.gz: fcc0f724a986b7d7d761dcfa2669c90d0ec5a75c4b627e6e1e8e4a6fa12c5d845a1248c6c5df861ae6750ee4462911eed4f7e28d230b9845534141db85df5546
6
+ metadata.gz: 998ad7457a2f3d50d99dc0481bb58af0e97a25d74ea0edf0d90255971dfee299a6b308a0c39a4b82ada657628fc8510d12a25eb4740f6392ff8b493ce06f05da
7
+ data.tar.gz: 28d7484b3fdeaaffa253885646577db7986735e2938dbb25c7c5f7224af002505548bbb923cdd390387336d22293220a9f3aded5fbb3c2031e0070afedc9a654
data/README.md CHANGED
@@ -1,4 +1,11 @@
1
- The gem convert ruby requests(net/http) into curl command.
1
+ The gem converts ruby requests to curl
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
2
9
 
3
10
  ## Installation
4
11
 
@@ -46,6 +53,131 @@ request.body = { title: 'Ruby is great :)' }.to_json
46
53
  Curlify.new(request).to_curl # curl -X POST -H 'content-type: application/json' -H 'accept-encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3' -H 'accept: */*' -H 'user-agent: Ruby' -H 'host: httpbin.org' -d '{"title":"Ruby is great :)"}' https://httpbin.org/post
47
54
  ```
48
55
 
56
+ ## Clipboard support
57
+
58
+ Curlify can copy the generated curl command directly to the operating system clipboard. To enable this behavior, pass `clipboard: true` when creating the `Curlify` instance. The method still returns the curl string.
59
+
60
+ Supported platforms:
61
+ - macOS: uses `pbcopy`
62
+ - Windows: uses `clip`
63
+ - Linux: uses `xclip` (must be installed and available in `PATH`)
64
+
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:
124
+
125
+ ```ruby
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
135
+ ```
136
+
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
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`
180
+
49
181
  Performing this curl command, we can see the following result:
50
182
 
51
183
  ```bash
data/lib/curlify.rb CHANGED
@@ -2,26 +2,38 @@
2
2
 
3
3
  require 'faraday'
4
4
 
5
+ require_relative 'settings'
6
+
5
7
  class Curlify
6
- attr_reader :request, :verify, :compressed
8
+ attr_reader :request
7
9
 
8
- def initialize(request, compressed: false, verify: true)
10
+ def initialize(request)
9
11
  @request = request
10
- @compressed = compressed
11
- @verify = verify
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
12
17
  end
13
18
 
14
19
  def to_curl
15
- return "#{curl_request} --compressed" if compressed
16
- return "#{curl_request} --insecure" unless verify
17
-
18
- curl_request
20
+ command = build_curl_command
21
+ copy_to_clipboard(command)
22
+ command
19
23
  end
20
24
 
21
25
  private
22
26
 
27
+ def build_curl_command
28
+ [
29
+ curl_request,
30
+ verify ? nil : '--insecure',
31
+ compressed ? '--compressed' : nil
32
+ ].compact.join(' ')
33
+ end
34
+
23
35
  def curl_request
24
- "curl -X #{http_method.upcase} #{headers} #{body} #{url}"
36
+ "curl -X #{http_method.upcase} #{headers} #{body} #{url}".strip
25
37
  end
26
38
 
27
39
  def headers
@@ -47,4 +59,24 @@ class Curlify
47
59
  def context_headers(headers)
48
60
  headers.map { |k, v| "-H '#{k}: #{v}'" }.join(' ')
49
61
  end
62
+
63
+ def copy_to_clipboard(string)
64
+ return unless clipboard
65
+
66
+ command = clipboard_command
67
+ return warn("Curlify Warning: 'xclip' is required for clipboard support on Linux.") unless command
68
+
69
+ IO.popen(command, 'w') { |f| f << string }
70
+ end
71
+
72
+ def clipboard_command
73
+ case RUBY_PLATFORM
74
+ when /darwin/
75
+ 'pbcopy'
76
+ when /mswin|mingw|cygwin/
77
+ 'clip'
78
+ when /linux/
79
+ 'xclip -selection clipboard' if system('which xclip > /dev/null 2>&1')
80
+ end
81
+ end
50
82
  end
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,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: curlify
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcus Almeida
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-04-28 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: faraday
@@ -24,17 +23,19 @@ dependencies:
24
23
  - - ">="
25
24
  - !ruby/object:Gem::Version
26
25
  version: '2.0'
27
- description: The gem convert python requests object in curl command.
26
+ description: Convert Ruby HTTP request and client objects into their equivalent curl
27
+ command. Useful for debugging and sharing HTTP requests.
28
28
  email: mpereirassa@gmail.com
29
29
  executables: []
30
30
  extensions: []
31
31
  extra_rdoc_files:
32
- - README.md
33
32
  - LICENSE
33
+ - README.md
34
34
  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
@@ -43,7 +44,6 @@ metadata:
43
44
  bug_tracker_uri: https://github.com/marcuxyz/curlify/issues
44
45
  changelog_uri: https://github.com/marcuxyz/curlify/releases
45
46
  rubygems_mfa_required: 'true'
46
- post_install_message:
47
47
  rdoc_options:
48
48
  - "--charset=UTF-8"
49
49
  require_paths:
@@ -59,8 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0'
61
61
  requirements: []
62
- rubygems_version: 3.5.7
63
- signing_key:
62
+ rubygems_version: 3.6.7
64
63
  specification_version: 4
65
- summary: Hola!
64
+ summary: Convert Ruby HTTP request objects into curl commands
66
65
  test_files: []