curlify 1.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 +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +31 -0
  4. data/lib/curlify.rb +32 -0
  5. metadata +52 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 454dce1933ce73ea1d94fb65751136b63ec6db386cc95c7c2617810be4a7f12f
4
+ data.tar.gz: 1d9a016845ea3a4a72bf4dbbe018c1c4ff18021be01949fe760d0beadb8b0056
5
+ SHA512:
6
+ metadata.gz: 90df8f74b718591df6dd9eacc1134207a41cd81f6a9f2ae6b7299a360aaf20b7fd0dd90a48b51c93c086e403ace3cfeb5bd02ad43acb7a278b56440618e59dda
7
+ data.tar.gz: fa2b4a3e6f4b61b20bde6d5641f2d5df8ba84ba81107e859c38ec33ac3cc63e4297f963c1974e1f4ac6fa1a8eabf0665de1b75c53a92e15efdf88fbb425f2a6e
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Marcus Almeida
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ The gem convert ruby requests(net/http) into curl command.
2
+
3
+ ## Installation
4
+
5
+ To install the gem use `bundle` or `gem`, see:
6
+
7
+ ```bash
8
+ $ gem install curlify
9
+ ```
10
+
11
+ or bundle:
12
+
13
+ ```bash
14
+ $ bundle add curlify
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ Import 'curlify', 'uri' and 'net/http' gems and execute curlify, see:
20
+
21
+ ```python
22
+ require 'uri'
23
+ require 'net/http'
24
+ require 'curlify'
25
+
26
+ uri = URI('https://run.mocky.io/v3/b0f4ffd8-6696-4f90-8bab-4a3bcad9ef3f')
27
+ request = Net::HTTP::Get.new(uri, { 'content-type': 'application/json' })
28
+ curlify = Curlify.new(request)
29
+
30
+ puts curlify.to_curl # curl -X GET -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: run.mocky.io' https://run.mocky.io/v3/b0f4ffd8-6696-4f90-8bab-4a3bcad9ef3f
31
+ ```
data/lib/curlify.rb ADDED
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Curlify
4
+ attr_reader :request, :verify, :compressed
5
+
6
+ def initialize(request, compressed: false, verify: true)
7
+ @request = request
8
+ @compressed = compressed
9
+ @verify = verify
10
+ end
11
+
12
+ def to_curl
13
+ return curl_request << ' --compressed' if compressed
14
+ return curl_request << ' --insecure' unless verify
15
+
16
+ curl_request
17
+ end
18
+
19
+ private
20
+
21
+ def curl_request
22
+ "curl -X #{request.method} #{headers} #{body} #{request.uri}"
23
+ end
24
+
25
+ def headers
26
+ request.each_header.map { |key, value| "-H '#{key}: #{value}'" }.join(' ')
27
+ end
28
+
29
+ def body
30
+ "-d #{request.body}" unless request.body.nil?
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: curlify
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Marcus Almeida
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-08-31 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: The gem convert python requests object in curl command.
14
+ email: mpereirassa@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files:
18
+ - README.md
19
+ - LICENSE
20
+ files:
21
+ - LICENSE
22
+ - README.md
23
+ - lib/curlify.rb
24
+ homepage: https://rubygems.org/gems/curlify
25
+ licenses:
26
+ - MIT
27
+ metadata:
28
+ source_code_uri: https://github.com/marcuxyz/curlify
29
+ bug_tracker_uri: https://github.com/marcuxyz/curlify/issues
30
+ changelog_uri: https://github.com/marcuxyz/curlify/releases
31
+ rubygems_mfa_required: 'true'
32
+ post_install_message:
33
+ rdoc_options:
34
+ - "--charset=UTF-8"
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: 3.2.0
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubygems_version: 3.4.1
49
+ signing_key:
50
+ specification_version: 4
51
+ summary: Hola!
52
+ test_files: []