Repository: jhawthorn/curl-to-ruby Branch: gh-pages Commit: 24abdb538dd2 Files: 19 Total size: 66.2 KB Directory structure: gitextract_7qxwwb6z/ ├── .github/ │ └── workflows/ │ └── test.yml ├── .gitignore ├── Gemfile ├── LICENSE.txt ├── README.md ├── index.html ├── package.json ├── resources/ │ ├── css/ │ │ ├── color-brewer.css │ │ └── common.css │ └── js/ │ ├── curl-to-ruby.js │ └── default.js ├── src/ │ ├── curl-to-ruby.js │ ├── curlToRuby.js │ ├── default.js │ ├── highlight.pack.js │ ├── jsonToRuby.js │ └── parseCommand.js ├── test.rb └── webpack.config.js ================================================ FILE CONTENTS ================================================ ================================================ FILE: .github/workflows/test.yml ================================================ name: Test on: push: branches: - gh-pages pull_request: branches: - gh-pages jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - name: Set up Ruby 2.6 uses: actions/setup-ruby@v1 with: ruby-version: 2.6.x - name: Set up Node.js 8.x uses: actions/setup-node@v1 with: node-version: 8.x - name: Install dependencies run: | gem install bundler bundle install --jobs 4 --retry 3 yarn - name: Build and run tests run: | yarn run compile bundle exec ruby test.rb ================================================ FILE: .gitignore ================================================ .DS_Store Thumbs.db _gitignore node_modules ================================================ FILE: Gemfile ================================================ source 'https://rubygems.org' gem 'execjs' gem 'execjs-fastnode' gem 'minitest' gem 'pry' ================================================ FILE: LICENSE.txt ================================================ The MIT License (MIT) Copyright (c) 2016 Matthew Holt Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ curl-to-ruby ============ curl-to-ruby is a tool to instantly convert [curl](http://curl.haxx.se) commands to ruby code using [net/http](http://ruby-doc.org/stdlib-2.1.1/libdoc/net/http/rdoc/Net/HTTP.html) in the browser. It does *not* guarantee high-fidelity conversions, but it's good enough for most API docs that have curl samples. ### Try it **[Check it out!](https://jhawthorn.github.io/curl-to-ruby)** It works inside your browser. ### FAQ #### Does any curl command work? Any curl command should work, but only certain flags are understood and converted into ruby code. The rest of the flags will be ignored. #### Which kinds of curl commands are understood? Mostly simple HTTP commands (headers, basic auth, body, etc). #### Will you consider supporting *this-or-that* flag? curl has like a bajillion options, so don't expect all of them to be implemented; just the most common/important ones to stub out code from API samples and docs, etc. But feel free to open an issue or submit a pull request! ### Credits Updated to ruby by John Hawthorn ([jhawthorn](https://twitter.com/jhawthorn)) Based on [curl-to-Go](https://github.com/mholt/curl-to-go) by Matt Holt ([mholt6](https://twitter.com/mholt6)). ================================================ FILE: index.html ================================================
Ruby's net/http is notorious for not having the friendliest API, but it isn't all that bad.
Ruby has great gems like faraday, but in libraries and small utilities it's better to kill your dependencies and use what the stdlib provides.
This tool turns a curl command into ruby (2.0+) code using net/http. Currently, it knows the following options: -d/--data, -H/--header, -I/--head, -u/--user, -k/--insecure, --url, and -X/--request.
There's probably bugs; please contribute on GitHub. Based on curl-to-go.
Simple · Basic Auth · JSON · Complex JSON · Form Data
0)a(s.substring(0,s.indexOf("=")),s.substring(s.indexOf("=")+1,s.length));else a(s,t.shift());else o(s)?r[s]=!0:s.length>1?a(s[0],s.substring(1,s.length)):a(s[0],t.shift());o(s)&&(r[s]=!0)}else a("_",s)}return r;function o(e){if(Array.isArray(n.boolFlags))for(var t=0;t
":l.tabReplace?n.replace(/\t/g,l.tabReplace):""}):e}function w(e){var n,r,a,i,c,u=function(e){var n,t,r,a,s=e.className+" ";if(s+=e.parentNode?e.parentNode.className:"",t=o.exec(s))return R(t[1])?t[1]:"no-highlight";for(n=0,r=(s=s.split(/\s+/)).length;n