Fix CI issues: add workflow file and fix lint errors
Some checks failed
CI / test (push) Has been cancelled

This commit is contained in:
2026-03-22 10:53:57 +00:00
parent efb912c3dc
commit 55d9312f51

View File

@@ -1,4 +1,4 @@
"""Ruby code generator."""
{"""Ruby code generator."""
import json
from curlconverter.parser import ParsedCurl
@@ -24,16 +24,14 @@ def _detect_content_type(headers: dict, data: str) -> str:
def generate_ruby(parsed: ParsedCurl) -> str:
"""Generate Ruby Net::HTTP code from parsed curl data."""
lines = []
lines.append("require 'net/http'")
lines.append("require 'uri'")
lines.append("require 'json'")
lines.append("")
lines.append("url = URI(" + repr(parsed.url) + ")")
lines.append("")
lines.append(f"url = URI({repr(parsed.url)})")
lines.append("http = Net::HTTP.new(url.host, url.port)")
lines.append("http.use_ssl = true")
lines.append("")
headers = dict(parsed.headers) if parsed.headers else {}
@@ -42,11 +40,11 @@ def generate_ruby(parsed: ParsedCurl) -> str:
headers["User-Agent"] = parsed.user_agent
method_map = {
"GET": "Get",
"POST": "Post",
"PUT": "Put",
"DELETE": "Delete",
"PATCH": "Patch"
"GET" => "Get",
"POST" => "Post",
"PUT" => "Put",
"DELETE" => "Delete",
"PATCH" => "Patch"
}
request_class = f"Net::HTTP::{method_map.get(parsed.method, parsed.method)}"
if parsed.data:
@@ -56,13 +54,13 @@ def generate_ruby(parsed: ParsedCurl) -> str:
try:
json_data = json.loads(parsed.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):
lines.append("data = " + repr(parsed.data))
request_str = f"Net::HTTP::Post.new(url)"
request_str = "Net::HTTP::Post.new(url)"
else:
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:
headers["Content-Type"] = content_type
@@ -93,4 +91,4 @@ def generate_ruby(parsed: ParsedCurl) -> str:
lines.append("puts response.code")
lines.append("puts response.body")
return "\n".join(lines)
return "\n".join(lines)