curlify 1.0.1 → 1.1.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 +21 -9
- data/lib/curlify.rb +22 -4
- metadata +19 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a48b30cfd32c1b91c5a582817d8f14f4591a163d849e4bee0571e9a30b51e616
|
4
|
+
data.tar.gz: ae6700a423572016a5c60ad5130921249d5f63cd8064761408fbce0022e88945
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 856229b5b419e3affd619dcb8844607eb89fe08335f6192171e624c57f304d4b0b4c870d3bc5d9e304ebe9598998c3ccc30198292267029818ff97588d4c1160
|
7
|
+
data.tar.gz: fcc0f724a986b7d7d761dcfa2669c90d0ec5a75c4b627e6e1e8e4a6fa12c5d845a1248c6c5df861ae6750ee4462911eed4f7e28d230b9845534141db85df5546
|
data/README.md
CHANGED
@@ -14,11 +14,27 @@ or bundle:
|
|
14
14
|
$ bundle add curlify
|
15
15
|
```
|
16
16
|
|
17
|
-
## Usage
|
17
|
+
## Usage with faraday
|
18
18
|
|
19
|
-
Import `curlify
|
19
|
+
Import `curlify` and `faraday` and perform curlify, see:
|
20
20
|
|
21
|
-
```
|
21
|
+
```ruby
|
22
|
+
require 'faraday'
|
23
|
+
require 'curlify'
|
24
|
+
|
25
|
+
request = Faraday.new.build_request(:post) do |req|
|
26
|
+
req.url 'http://127.0.0.1'
|
27
|
+
end
|
28
|
+
|
29
|
+
Curlify.new(request).to_curl # "curl -X POST -H 'User-Agent: Faraday v2.9.0' http://127.0.0.1"
|
30
|
+
```
|
31
|
+
|
32
|
+
## Usage with net/http
|
33
|
+
|
34
|
+
Import `curlify`, `uri` and `net/http` and perform curlify, see:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
require 'json'
|
22
38
|
require 'uri'
|
23
39
|
require 'net/http'
|
24
40
|
require 'curlify'
|
@@ -27,14 +43,10 @@ uri = URI('https://httpbin.org/post')
|
|
27
43
|
request = Net::HTTP::Post.new(uri, { 'content-type': 'application/json' })
|
28
44
|
request.body = { title: 'Ruby is great :)' }.to_json
|
29
45
|
|
30
|
-
|
31
|
-
|
32
|
-
puts curlify.to_curl
|
33
|
-
|
34
|
-
# 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
|
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
|
35
47
|
```
|
36
48
|
|
37
|
-
|
49
|
+
Performing this curl command, we can see the following result:
|
38
50
|
|
39
51
|
```bash
|
40
52
|
{
|
data/lib/curlify.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'faraday'
|
4
|
+
|
3
5
|
class Curlify
|
4
6
|
attr_reader :request, :verify, :compressed
|
5
7
|
|
@@ -10,8 +12,8 @@ class Curlify
|
|
10
12
|
end
|
11
13
|
|
12
14
|
def to_curl
|
13
|
-
return curl_request
|
14
|
-
return curl_request
|
15
|
+
return "#{curl_request} --compressed" if compressed
|
16
|
+
return "#{curl_request} --insecure" unless verify
|
15
17
|
|
16
18
|
curl_request
|
17
19
|
end
|
@@ -19,14 +21,30 @@ class Curlify
|
|
19
21
|
private
|
20
22
|
|
21
23
|
def curl_request
|
22
|
-
"curl -X #{
|
24
|
+
"curl -X #{http_method.upcase} #{headers} #{body} #{url}"
|
23
25
|
end
|
24
26
|
|
25
27
|
def headers
|
26
|
-
request.
|
28
|
+
if request.is_a?(Faraday::Request)
|
29
|
+
context_headers(request.headers)
|
30
|
+
else
|
31
|
+
context_headers(request.each_header)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def http_method
|
36
|
+
request.is_a?(Faraday::Request) ? request.http_method : request.method
|
37
|
+
end
|
38
|
+
|
39
|
+
def url
|
40
|
+
request.is_a?(Faraday::Request) ? request.path : request.uri
|
27
41
|
end
|
28
42
|
|
29
43
|
def body
|
30
44
|
"-d '#{request.body}'" unless request.body.nil?
|
31
45
|
end
|
46
|
+
|
47
|
+
def context_headers(headers)
|
48
|
+
headers.map { |k, v| "-H '#{k}: #{v}'" }.join(' ')
|
49
|
+
end
|
32
50
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: curlify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcus Almeida
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
11
|
+
date: 2024-04-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
13
27
|
description: The gem convert python requests object in curl command.
|
14
28
|
email: mpereirassa@gmail.com
|
15
29
|
executables: []
|
@@ -38,14 +52,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
38
52
|
requirements:
|
39
53
|
- - ">="
|
40
54
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
55
|
+
version: 2.7.8
|
42
56
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
57
|
requirements:
|
44
58
|
- - ">="
|
45
59
|
- !ruby/object:Gem::Version
|
46
60
|
version: '0'
|
47
61
|
requirements: []
|
48
|
-
rubygems_version: 3.
|
62
|
+
rubygems_version: 3.5.7
|
49
63
|
signing_key:
|
50
64
|
specification_version: 4
|
51
65
|
summary: Hola!
|