Skip to content

Commit

Permalink
more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Feralthedogg committed Jan 17, 2025
1 parent eb2fcee commit 8f33027
Show file tree
Hide file tree
Showing 20 changed files with 555 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .idea/korcen-api.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions example/example.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
url <- "https://korcen.shibadogs.net/api/v1/korcen"
json_data <- '{"input": "욕설이 포함될수 있는 메시지",
"replace_front": "감지된 욕설 앞부분에 넣을 메시지 (옵션)",
"replace_end": "감지된 욕설 뒷부분에 넣을 메시지 (옵션)"}'

headers <- c("Accept: application/json", "Content-Type: application/json")
con <- url(url, "rb")
write(json_data, con)
response <- readLines(con, warn=FALSE)
close(con)

cat("Response:", response, "\n")
19 changes: 19 additions & 0 deletions example/example.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <stdio.h>
#include <stdlib.h>

int main() {
const char *json_data =
"{"
"\"input\":\"욕설이 포함될수 있는 메시지\","
"\"replace_front\":\"감지된 욕설 앞부분에 넣을 메시지 (옵션)\","
"\"replace_end\":\"감지된 욕설 뒷부분에 넣을 메시지 (옵션)\""
"}";

char command[1024];
snprintf(command, sizeof(command),
"echo '%s' | curl -X POST -H \"Accept: application/json\" -H \"Content-Type: application/json\" -d @- \"https://korcen.shibadogs.net/api/v1/korcen\"",
json_data);

system(command);
return 0;
}
17 changes: 17 additions & 0 deletions example/example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <iostream>
#include <cstdlib>

int main() {
std::string json_data =
"{"
"\"input\": \"욕설이 포함될수 있는 메시지\","
"\"replace_front\": \"감지된 욕설 앞부분에 넣을 메시지 (옵션)\","
"\"replace_end\": \"감지된 욕설 뒷부분에 넣을 메시지 (옵션)\""
"}";

std::string command = "echo \"" + json_data + "\" | curl -X POST -H \"Accept: application/json\" -H \"Content-Type: application/json\" -d @- \"https://korcen.shibadogs.net/api/v1/korcen\"";

system(command.c_str());

return 0;
}
23 changes: 23 additions & 0 deletions example/example.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-module(example).
-export([call_api/0]).

call_api() ->
URL = "https://korcen.shibadogs.net/api/v1/korcen",
Headers = [
{"Accept", "application/json"},
{"Content-Type", "application/json"}
],
Body = "{"
"\"input\":\"욕설이 포함될수 있는 메시지\","
"\"replace_front\":\"감지된 욕설 앞부분에 넣을 메시지 (옵션)\","
"\"replace_end\":\"감지된 욕설 뒷부분에 넣을 메시지 (옵션)\""
"}",

case httpc:request(post, {URL, Headers, "application/json", Body}, [], []) of
{ok, {{_, 200, _}, _, ResponseBody}} ->
io:format("Response: ~s~n", [ResponseBody]);
{ok, {{_, StatusCode, _}, _, _}} ->
io:format("Error: HTTP ~p~n", [StatusCode]);
{error, Reason} ->
io:format("Request failed: ~p~n", [Reason])
end.
38 changes: 38 additions & 0 deletions example/example.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# mix.exs
#
# defp deps do
# [
# {:httpoison, "~> 1.8"},
# {:jason, "~> 1.4"}
# ]
#end

defmodule KorcenClient do
@url "https://korcen.shibadogs.net/api/v1/korcen"
@headers [
{"Accept", "application/json"},
{"Content-Type", "application/json"}
]

def call_api do
body = %{
"input" => "욕설이 포함될수 있는 메시지",
"replace_front" => "감지된 욕설 앞부분에 넣을 메시지 (옵션)",
"repace_end" => "감지된 욕설 뒷부분에 넣을 메시지 (옵션)"
}
|> Jason.endcode!()

case HTTPoison.post(@url, body, @headers) do
{:ok, %HTTPoison.Response{status_code: 200, body: response_body}} ->
IO.puts("Response: #{response_body}")

{:ok, %HTTPoison.Response{status_code: status_code}} ->
IO.puts("Error: Received HTTP status #{status_code}")

{:error, HTTPoison.Response{reason: reason}} ->
IO.puts("HTTP Request failed: #{inspect(reason)}")
end
end
end

KorcenClient.call_api()
27 changes: 27 additions & 0 deletions example/example.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
program korcen_api
use iso_fortran_env, only: output_unit
implicit none
character(len=1024) :: json_data, response
integer :: status

json_data = '{' // &
'"input": "욕설이 포함될수 있는 메시지",' // &
'"replace_front": "감지된 욕설 앞부분에 넣을 메시지 (옵션)",' // &
'"replace_end": "감지된 욕설 뒷부분에 넣을 메시지 (옵션)"' // &
'}'

call execute_command_line('curl -s -X POST ' // &
'-H "Accept: application/json" ' // &
'-H "Content-Type: application/json" ' // &
'-d ''' // trim(json_data) // ''' ' // &
'"https://korcen.shibadogs.net/api/v1/korcen" > response.json', status)

open(unit=10, file="response.json", status="old", action="read", iostat=status)
if (status == 0) then
read(10, '(A)') response
print *, "Response:", trim(response)
close(10)
else
print *, "Error: Failed to read response."
end if
end program korcen_api
18 changes: 18 additions & 0 deletions example/example.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Network.HTTP
import Network.URI

main :: IO ()
main = do
let url = "https://korcen.shibadogs.net/api/v1/korcen"
let jsonData = "{\"input\": \"욕설이 포함될수 있는 메시지\", \"replace_front\": \"감지된 욕설 앞부분에 넣을 메시지 (옵션)\", \"replace_end\": \"감지된 욕설 뒷부분에 넣을 메시지 (옵션)\"}"
case parseURI url of
Nothing -> putStrLn "Invalid URL"
Just uri -> do
let req = Request {
rqURI = uri,
rqMethod = POST,
rqHeaders = [mkHeader HdrContentType "application/json"],
rqBody = jsonData
}
response <- simpleHTTP req >>= getResponseBody
putStrLn ("Response: " ++ response)
48 changes: 48 additions & 0 deletions example/example.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;

public class example {
public static void main(String[] args) {
try {
URL url = new URL("https://korcen.shibadogs.net/api/v1/korcen");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Accept", "application/json");
connection.setRequestProperty("Content-Type", "application/json");
connection.setDoOutput(true);

String jsonInput = "{"
+ "\"input\":\"욕설이 포함될수 있는 메시지\","
+ "\"replace_front\":\"감지된 욕설 앞부분에 넣을 메시지 (옵션)\","
+ "\"replace_end\":\"감지된 욕설 뒷부분에 넣을 메시지 (옵션)\""
+ "}";

try (OutputStream outputStream = connection.getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"))) {
writer.write(jsonInput);
writer.flush();
}

int responseCode = connection.getResponseCode();
System.out.println("Response Code: " + responseCode);

if (responseCode == HttpURLConnection.HTTP_OK) {
try (BufferedReader inputStream = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringWriter response = new StringWriter()) {
String inputLine;
while ((inputLine = inputStream.readLine()) != null) {
response.write(inputLine);
}
System.out.println("Response: " + response.toString());
}
} else {
System.out.println("Error: " + responseCode);
}

connection.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
}
}
33 changes: 33 additions & 0 deletions example/example.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Sockets

function call_api()
url = "https://korcen.shibadogs.net/api/v1/korcen"
json_data = """
{
"input": "욕설이 포함될수 있는 메시지",
"replace_front": "감지된 욕설 앞부분에 넣을 메시지 (옵션)",
"replace_end": "감지된 욕설 뒷부분에 넣을 메시지 (옵션)"
}
"""

host, port = split(url[9:end], "/")[1], 443
socket = connect(host, port)

request = """
POST /api/v1/korcen HTTP/1.1
Host: korcen.shibadogs.net
Accept: application/json
Content-Type: application/json
Content-Length: $(length(json_data))
$(json_data)
"""

write(socket, request)
response = read(socket, String)
close(socket)

println("Response: ", response)
end

call_api()
19 changes: 19 additions & 0 deletions example/example.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
local json_data = [[
{
"input": "욕설이 포함될수 있는 메시지",
"replace_front": "감지된 욕설 앞부분에 넣을 메시지 (옵션)",
"replace_end": "감지된 욕설 뒷부분에 넣을 메시지 (옵션)"
}
]]

local command = "curl -s -X POST " ..
"-H \"Accept: application/json\" "
"-H \"Content-Type: application/json\" "
"-d '" .. json_data:gsub("'", "\\'") .. "' " ..
"\"https://korcen.shibadogs.net/api/v1/korcen\""

local handle = io.popen(command)
local response = handle:read("*a")
handle:close()

print("Response: " .. response)
26 changes: 26 additions & 0 deletions example/example.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
program KorcenAPI;
uses fphttpclient, fpjson, jsonparser;

var
Client: TFPHTTPClient;
Response: String;
JsonData: String;
begin
JsonData := '{' +
'"input": "욕설이 포함될수 있는 메시지",' +
'"replace_front": "감지된 욕설 앞부분에 넣을 메시지 (옵션)",' +
'"replace_end": "감지된 욕설 뒷부분에 넣을 메시지 (옵션)"' +
'}';

Client := TFPHTTPClient.Create(nil);
try
Client.AddHeader('Content-Type', 'application/json');
Client.AddHeader('Accept', 'application/json');
Response := Client.SimplePost('https://korcen.shibadogs.net/api/v1/korcen', JsonData);
Writeln('Response: ', Response);
except
on E: Exception do
Writeln('Error: ', E.Message);
end;
Client.Free;
end.
Loading

0 comments on commit 8f33027

Please sign in to comment.