Skip to content

Commit

Permalink
✨ : Add new function / Noteを送信できるように。
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruruke committed May 10, 2024
1 parent 77d28f6 commit 769aa13
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
38 changes: 38 additions & 0 deletions MisskeyDotNet/WebAPI/MiWebAPI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.Text;
using System.Text.Json;
using MisskeyDotNet.Object;

namespace MisskeyDotNet.WebAPI;

public class MiWebAPI
{
HttpClient client = new();
string _url = "https://misskey.io/api";
string _token = "";

public MiWebAPI(String token, String baseURL = "misskey.io")
{
_token = token;
_url = $"https://{baseURL}/api";
}

public async Task<string> Note(String token, MiSendNote miSendNote)
{

miSendNote.i = token;
var json_in = JsonSerializer.Serialize(miSendNote);
Console.WriteLine(json_in);

var content = new StringContent(json_in, Encoding.UTF8, @"application/json");

Console.WriteLine("API Call...");

var responce = await client.PostAsync(_url + "/notes/create", content);

Console.WriteLine(responce.StatusCode);

var responce_text = await responce.Content.ReadAsStringAsync();
Console.WriteLine(responce_text);
return responce_text;
}
}
31 changes: 31 additions & 0 deletions MisskeyDotNet/WebAPI/Object/MiSendNote.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Text.Json.Serialization;

namespace MisskeyDotNet.WebAPI;

public class MiSendNote
{
public string i { get; set;}
public string visibility { get; set; } = "public";
public List<string> visibleUserIds { get; set; } = new();
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string cw { get; set; } = null;
public bool localOnly { get; set; } = false;
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public object reactionAcceptance { get; set; } = null;
public bool noExtractMentions { get; set; } = false;
public bool noExtractHashtags { get; set; } = false;
public bool noExtractEmojis { get; set; } = false;
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string replyId { get; set; } = null;
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public object renoteId { get; set; } = null;
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string channelId { get; set; } = null!;
public string text { get; set; } = "";
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public object fileIds { get; set; } = null;
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public object mediaIds { get; set; } = null;
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public object poll { get; set; } = null;
}

0 comments on commit 769aa13

Please sign in to comment.