Giter VIP home page Giter VIP logo

curl-to-ruby's Introduction

curl-to-ruby

curl-to-ruby is a tool to instantly convert curl commands to ruby code using net/http 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! 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)

Based on curl-to-Go by Matt Holt (mholt6).

curl-to-ruby's People

Contributors

arr-dev avatar chrsblck avatar jhawthorn avatar mholt avatar tcaddy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

curl-to-ruby's Issues

Support -k

Are you interested in a PR which would add support for -k option ?

Command line support

It would be awesome if I can run this as an executable and paste a curl command in to print out the ruby.

Happy to help make this happen if it's not a thing yet! This project is amazing!!! ๐Ÿ˜ป๐Ÿ˜ป ๐Ÿ˜ป

Add support for -G

I am working with the PagerDuty REST API. Here is the command I am trying to convert:

curl -H "Content-type: application/json" -H "Authorization: Token token=$PAGERDUTY_ACCESS_KEY" -X GET -G --data-urlencode "since=2017-01-16" --data-urlencode "until=2017-01-17"  "https://company.pagerduty.com/api/v1/schedules" 

The two --data-urlencode entries do not show up in the converted code. Am I correct in assuming there is no -G support?

Doesn't support POST command and the result is completely wrong.

curl 'http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule' \
  -H 'Connection: keep-alive' \
  -H 'Pragma: no-cache' \
  -H 'Cache-Control: no-cache' \
  -H 'Accept: application/json, text/javascript, */*; q=0.01' \
  -H 'X-Requested-With: XMLHttpRequest' \
  -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36' \
  -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \
  -H 'Origin: http://fanyi.youdao.com' \
  -H 'Referer: http://fanyi.youdao.com/' \
  -H 'Accept-Language: en-US,en;q=0.9' \
  -H 'Cookie: SESSION_FROM_COOKIE=www.google.com; [email protected]; UM_distinctid=17697740fd4170-04dc0273ef4b3b-163b6152-384000-17697740fd5ad9; JSESSIONID=aaakvUkIMF4LE_Ut7nBAx; OUTFOX_SEARCH_USER_ID_NCOO=1853585491.4869733; ___rl__test__cookies=1608921911154' \
  --data-raw 'i=representative&from=AUTO&to=AUTO&smartresult=dict&client=fanyideskweb&salt=16089219111571&sign=a112f16df706f6ed109f690c3cfe5193&lts=1608921911157&bv=351bfce8c0555a52efc8c9f4762d3359&doctype=json&version=2.1&keyfrom=fanyi.web&action=FY_BY_REALTlME' \
  --compressed \
  --insecure

Results

Body is missing, METHOD should be POST not GET

require 'net/http'
require 'uri'
require 'openssl'

uri = URI.parse("http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule")
request = Net::HTTP::Get.new(uri)
request.content_type = "application/x-www-form-urlencoded; charset=UTF-8"
request["Connection"] = "keep-alive"
request["Pragma"] = "no-cache"
request["Cache-Control"] = "no-cache"
request["Accept"] = "application/json, text/javascript, */*; q=0.01"
request["X-Requested-With"] = "XMLHttpRequest"
request["User-Agent"] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"
request["Origin"] = "http://fanyi.youdao.com"
request["Referer"] = "http://fanyi.youdao.com/"
request["Accept-Language"] = "en-US,en;q=0.9"
request["Cookie"] = "SESSION_FROM_COOKIE=www.google.com; [email protected]; UM_distinctid=17697740fd4170-04dc0273ef4b3b-163b6152-384000-17697740fd5ad9; JSESSIONID=aaakvUkIMF4LE_Ut7nBAx; OUTFOX_SEARCH_USER_ID_NCOO=1853585491.4869733; ___rl__test__cookies=1608921911154"

req_options = {
  use_ssl: uri.scheme == "https",
  verify_mode: OpenSSL::SSL::VERIFY_NONE,
}

response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
  http.request(request)
end

# response.code
# response.body

--digest not working

trying to get monero-rpc-cli which use --digest.

curl -s -u username:password --digest -X POST http://192.168.1.226:18081/json_rpc -d '{"jsonrpc":"2.0","id":"0","method": "query_key", "params": {"key_type": "view_key"} }' -H 'Content-Type: application/json'

this request is working, the result of curl-to-ruby will return 401. same issue for HTTParty and RestClient.

it seems that they all do something different then curl does.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.