Fix CI issues: add workflow file and fix lint errors
Some checks failed
CI / test (push) Has been cancelled
Some checks failed
CI / test (push) Has been cancelled
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
"""Ruby code generator."""
|
{"""Ruby code generator."""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
from curlconverter.parser import ParsedCurl
|
from curlconverter.parser import ParsedCurl
|
||||||
@@ -24,16 +24,14 @@ def _detect_content_type(headers: dict, data: str) -> str:
|
|||||||
def generate_ruby(parsed: ParsedCurl) -> str:
|
def generate_ruby(parsed: ParsedCurl) -> str:
|
||||||
"""Generate Ruby Net::HTTP code from parsed curl data."""
|
"""Generate Ruby Net::HTTP code from parsed curl data."""
|
||||||
lines = []
|
lines = []
|
||||||
|
|
||||||
lines.append("require 'net/http'")
|
lines.append("require 'net/http'")
|
||||||
lines.append("require 'uri'")
|
lines.append("require 'uri'")
|
||||||
lines.append("require 'json'")
|
lines.append("require 'json'")
|
||||||
lines.append("")
|
lines.append("")
|
||||||
|
|
||||||
lines.append("url = URI(" + repr(parsed.url) + ")")
|
lines.append(f"url = URI({repr(parsed.url)})")
|
||||||
lines.append("")
|
|
||||||
|
|
||||||
lines.append("http = Net::HTTP.new(url.host, url.port)")
|
lines.append("http = Net::HTTP.new(url.host, url.port)")
|
||||||
lines.append("http.use_ssl = true")
|
|
||||||
lines.append("")
|
lines.append("")
|
||||||
|
|
||||||
headers = dict(parsed.headers) if parsed.headers else {}
|
headers = dict(parsed.headers) if parsed.headers else {}
|
||||||
@@ -42,11 +40,11 @@ def generate_ruby(parsed: ParsedCurl) -> str:
|
|||||||
headers["User-Agent"] = parsed.user_agent
|
headers["User-Agent"] = parsed.user_agent
|
||||||
|
|
||||||
method_map = {
|
method_map = {
|
||||||
"GET": "Get",
|
"GET" => "Get",
|
||||||
"POST": "Post",
|
"POST" => "Post",
|
||||||
"PUT": "Put",
|
"PUT" => "Put",
|
||||||
"DELETE": "Delete",
|
"DELETE" => "Delete",
|
||||||
"PATCH": "Patch"
|
"PATCH" => "Patch"
|
||||||
}
|
}
|
||||||
request_class = f"Net::HTTP::{method_map.get(parsed.method, parsed.method)}"
|
request_class = f"Net::HTTP::{method_map.get(parsed.method, parsed.method)}"
|
||||||
if parsed.data:
|
if parsed.data:
|
||||||
@@ -56,13 +54,13 @@ def generate_ruby(parsed: ParsedCurl) -> str:
|
|||||||
try:
|
try:
|
||||||
json_data = json.loads(parsed.data)
|
json_data = json.loads(parsed.data)
|
||||||
lines.append("data = " + json.dumps(json_data))
|
lines.append("data = " + json.dumps(json_data))
|
||||||
request_str = f"Net::HTTP::Post.new(url, {{'Content-Type' => 'application/json'}})"
|
request_str = "Net::HTTP::Post.new(url, {'Content-Type' => 'application/json'})"
|
||||||
except (json.JSONDecodeError, TypeError):
|
except (json.JSONDecodeError, TypeError):
|
||||||
lines.append("data = " + repr(parsed.data))
|
lines.append("data = " + repr(parsed.data))
|
||||||
request_str = f"Net::HTTP::Post.new(url)"
|
request_str = "Net::HTTP::Post.new(url)"
|
||||||
else:
|
else:
|
||||||
lines.append("data = " + repr(parsed.data))
|
lines.append("data = " + repr(parsed.data))
|
||||||
request_str = f"Net::HTTP::Post.new(url)"
|
request_str = "Net::HTTP::Post.new(url)"
|
||||||
|
|
||||||
if "Content-Type" not in headers and "content-type" not in headers:
|
if "Content-Type" not in headers and "content-type" not in headers:
|
||||||
headers["Content-Type"] = content_type
|
headers["Content-Type"] = content_type
|
||||||
|
|||||||
Reference in New Issue
Block a user