Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add builder class #26

Merged
merged 2 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions Amino.NET/Builders/PostBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Reflection.Metadata.Ecma335;

namespace Amino.NET.Builders
{
public class PostBuilder
{
public byte[] CoverImage { get; private set; }
public byte[] BackgroundImage { get; private set; }
public string BackgroundColor { get; private set; } = "#ffffff";
public string Content { get; set; }
public string Title { get; set; }
public List<(byte[], string?, string?)> MediaList { get; } = new List<(byte[], string?, string?)>();

Check warning on line 15 in Amino.NET/Builders/PostBuilder.cs

View workflow job for this annotation

GitHub Actions / test

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 15 in Amino.NET/Builders/PostBuilder.cs

View workflow job for this annotation

GitHub Actions / test

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
public PostTypes PostType { get; set; } = PostTypes.Blog;
public BackgroundTypes BackgroundType { get; set; } = BackgroundTypes.Color;
public bool FansOnly { get; set; }


public void WithCover(byte[] cover)
{
CoverImage = cover;
}
public void WithCover(string coverPath)
{
WithCover(File.ReadAllBytes(coverPath));
}

public void WithBackgroundImage(byte[] media)
{
BackgroundImage = media;
}

public void WithBackgroundImage(string mediaPath)
{
WithBackgroundImage(File.ReadAllBytes(mediaPath));
}

public void AddMedia(byte[] media, string mediaKey = null, string caption = null)
{
MediaList.Add((media, mediaKey, caption));
}

public void AddMedia(string mediaPath, string mediaKey = null, string caption = null)
{
AddMedia(File.ReadAllBytes(mediaPath), mediaKey, caption);
}

public string EmbedImage(string mediaKey) => $"[IMG={mediaKey}]";

public enum PostTypes
{
Blog,
Wiki
}
public enum BackgroundTypes
{
Color,
Image
}

}
}
2 changes: 1 addition & 1 deletion Amino.NET/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ public Task register(string _name, string _email, string _password, string _veri
{ "clientCallbackURL", "narviiapp://relogin" },
{ "validationContext", new JObject()
{
{ "data", new JObject() { "code", _verificationCode } },
{ "data", new JObject() { {"code", _verificationCode } } },
{ "type", 1 },
{ "identity", _email }
}
Expand Down
22 changes: 21 additions & 1 deletion Amino.NET/SubClient.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using Newtonsoft.Json;
using Amino.NET.Builders;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using RestSharp;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Reactive.Subjects;
using System.Runtime.Serialization.Formatters;
using System.Text;
Expand Down Expand Up @@ -191,6 +193,24 @@ public Task post_blog(string title, string content, IEnumerable<byte[]> imageLis
return Task.CompletedTask;
}

public Task create_post(PostBuilder post)
{
List<byte[]> _media = new List<byte[]>();
switch(post.PostType)
{
case PostBuilder.PostTypes.Blog:
foreach (var media in post.MediaList) { _media.Add(media.Item1); }
post_blog(post.Title, post.Content, _media, post.FansOnly, post.BackgroundColor);
break;
case PostBuilder.PostTypes.Wiki:
foreach (var media in post.MediaList) { _media.Add(media.Item1); }
post_wiki(post.Title, post.Content, _media, post.FansOnly, post.BackgroundColor);
break;
}
return Task.CompletedTask;
}


/// <summary>
/// Allows you to post a Wiki post on the current Community
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Amino.NET/Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public enum User_Types
}
public enum Featured_Types
{
Unfreature,
Unfeature,
User,
Blog,
Wiki,
Expand Down
Loading