curlify 1.1.0 → 1.2.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 (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +20 -1
  3. data/lib/curlify.rb +36 -7
  4. metadata +7 -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: 76a3fea5ff081b12d6de36265e700ca9c6d527672b21be0cd1f4877682e6757b
4
+ data.tar.gz: 6ccab146f35e8649debeb1f04633bae4a32a9e50758247e5fc1926f595f0f9fd
5
5
  SHA512:
6
- metadata.gz: 856229b5b419e3affd619dcb8844607eb89fe08335f6192171e624c57f304d4b0b4c870d3bc5d9e304ebe9598998c3ccc30198292267029818ff97588d4c1160
7
- data.tar.gz: fcc0f724a986b7d7d761dcfa2669c90d0ec5a75c4b627e6e1e8e4a6fa12c5d845a1248c6c5df861ae6750ee4462911eed4f7e28d230b9845534141db85df5546
6
+ metadata.gz: ffb9587d3dad61225f2b2c55498da7605f4a497cb12b35360346421ffa761eac3136b392e6e5db62a6bbf589a087c78284636642b2a08c8781aed367bd193cdf
7
+ data.tar.gz: 3456eb8c4efcd1f5321a7a8656e2fea962f5ed8461cae8ac837093166d91ab6bff0f2388db2bcd40abf63acc05b8ae10bac1e1d2059dc50d37637a5aa8907261
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- The gem convert ruby requests(net/http) into curl command.
1
+ The gem converts ruby requests to curl
2
2
 
3
3
  ## Installation
4
4
 
@@ -46,6 +46,25 @@ request.body = { title: 'Ruby is great :)' }.to_json
46
46
  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
47
  ```
48
48
 
49
+ ## Clipboard support
50
+
51
+ 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.
52
+
53
+ Supported platforms:
54
+ - macOS: uses `pbcopy`
55
+ - Windows: uses `clip`
56
+ - Linux: uses `xclip` (must be installed and available in `PATH`)
57
+
58
+ Example:
59
+
60
+ ```ruby
61
+ # copy to clipboard and return the curl string
62
+ Curlify.new(request, clipboard: true).to_curl
63
+ ```
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
+
49
68
  Performing this curl command, we can see the following result:
50
69
 
51
70
  ```bash
data/lib/curlify.rb CHANGED
@@ -1,27 +1,36 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'faraday'
4
+ require 'byebug'
4
5
 
5
6
  class Curlify
6
- attr_reader :request, :verify, :compressed
7
+ attr_reader :request, :verify, :compressed, :clipboard
7
8
 
8
- def initialize(request, compressed: false, verify: true)
9
+ def initialize(request, compressed: false, verify: true, clipboard: false)
9
10
  @request = request
10
11
  @compressed = compressed
11
12
  @verify = verify
13
+ @clipboard = clipboard
12
14
  end
13
15
 
14
16
  def to_curl
15
- return "#{curl_request} --compressed" if compressed
16
- return "#{curl_request} --insecure" unless verify
17
-
18
- curl_request
17
+ command = build_curl_command
18
+ copy_to_clipboard(command)
19
+ command
19
20
  end
20
21
 
21
22
  private
22
23
 
24
+ def build_curl_command
25
+ [
26
+ curl_request,
27
+ verify ? nil : '--insecure',
28
+ compressed ? '--compressed' : nil
29
+ ].compact.join(' ')
30
+ end
31
+
23
32
  def curl_request
24
- "curl -X #{http_method.upcase} #{headers} #{body} #{url}"
33
+ "curl -X #{http_method.upcase} #{headers} #{body} #{url}".strip
25
34
  end
26
35
 
27
36
  def headers
@@ -47,4 +56,24 @@ class Curlify
47
56
  def context_headers(headers)
48
57
  headers.map { |k, v| "-H '#{k}: #{v}'" }.join(' ')
49
58
  end
59
+
60
+ def copy_to_clipboard(string)
61
+ return unless clipboard
62
+
63
+ command = clipboard_command
64
+ return warn("Curlify Warning: 'xclip' is required for clipboard support on Linux.") unless command
65
+
66
+ IO.popen(command, 'w') { |f| f << string }
67
+ end
68
+
69
+ def clipboard_command
70
+ case RUBY_PLATFORM
71
+ when /darwin/
72
+ 'pbcopy'
73
+ when /mswin|mingw|cygwin/
74
+ 'clip'
75
+ when /linux/
76
+ 'xclip -selection clipboard' if system('which xclip > /dev/null 2>&1')
77
+ end
78
+ end
50
79
  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: 1.2.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,13 +23,14 @@ 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
@@ -43,7 +43,6 @@ metadata:
43
43
  bug_tracker_uri: https://github.com/marcuxyz/curlify/issues
44
44
  changelog_uri: https://github.com/marcuxyz/curlify/releases
45
45
  rubygems_mfa_required: 'true'
46
- post_install_message:
47
46
  rdoc_options:
48
47
  - "--charset=UTF-8"
49
48
  require_paths:
@@ -59,8 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
58
  - !ruby/object:Gem::Version
60
59
  version: '0'
61
60
  requirements: []
62
- rubygems_version: 3.5.7
63
- signing_key:
61
+ rubygems_version: 3.6.7
64
62
  specification_version: 4
65
- summary: Hola!
63
+ summary: Convert Ruby HTTP request objects into curl commands
66
64
  test_files: []