Skip to content

Commit 1f425e7

Browse files
authored
Merge pull request #26 from Amino-NET-Group/feature/add-builder-class
Feature/add builder class
2 parents bb41fc2 + ae4ceca commit 1f425e7

4 files changed

Lines changed: 87 additions & 3 deletions

File tree

Amino.NET/Builders/PostBuilder.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using System.Collections.Generic;
2+
using System.ComponentModel;
3+
using System.IO;
4+
using System.Reflection.Metadata.Ecma335;
5+
6+
namespace Amino.NET.Builders
7+
{
8+
public class PostBuilder
9+
{
10+
public byte[] CoverImage { get; private set; }
11+
public byte[] BackgroundImage { get; private set; }
12+
public string BackgroundColor { get; private set; } = "#ffffff";
13+
public string Content { get; set; }
14+
public string Title { get; set; }
15+
public List<(byte[], string?, string?)> MediaList { get; } = new List<(byte[], string?, string?)>();
16+
public PostTypes PostType { get; set; } = PostTypes.Blog;
17+
public BackgroundTypes BackgroundType { get; set; } = BackgroundTypes.Color;
18+
public bool FansOnly { get; set; }
19+
20+
21+
public void WithCover(byte[] cover)
22+
{
23+
CoverImage = cover;
24+
}
25+
public void WithCover(string coverPath)
26+
{
27+
WithCover(File.ReadAllBytes(coverPath));
28+
}
29+
30+
public void WithBackgroundImage(byte[] media)
31+
{
32+
BackgroundImage = media;
33+
}
34+
35+
public void WithBackgroundImage(string mediaPath)
36+
{
37+
WithBackgroundImage(File.ReadAllBytes(mediaPath));
38+
}
39+
40+
public void AddMedia(byte[] media, string mediaKey = null, string caption = null)
41+
{
42+
MediaList.Add((media, mediaKey, caption));
43+
}
44+
45+
public void AddMedia(string mediaPath, string mediaKey = null, string caption = null)
46+
{
47+
AddMedia(File.ReadAllBytes(mediaPath), mediaKey, caption);
48+
}
49+
50+
public string EmbedImage(string mediaKey) => $"[IMG={mediaKey}]";
51+
52+
public enum PostTypes
53+
{
54+
Blog,
55+
Wiki
56+
}
57+
public enum BackgroundTypes
58+
{
59+
Color,
60+
Image
61+
}
62+
63+
}
64+
}

Amino.NET/Client.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ public Task register(string _name, string _email, string _password, string _veri
456456
{ "clientCallbackURL", "narviiapp://relogin" },
457457
{ "validationContext", new JObject()
458458
{
459-
{ "data", new JObject() { "code", _verificationCode } },
459+
{ "data", new JObject() { {"code", _verificationCode } } },
460460
{ "type", 1 },
461461
{ "identity", _email }
462462
}

Amino.NET/SubClient.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
using Newtonsoft.Json;
1+
using Amino.NET.Builders;
2+
using Newtonsoft.Json;
23
using Newtonsoft.Json.Linq;
34
using RestSharp;
45
using System;
56
using System.Collections.Generic;
67
using System.Diagnostics;
78
using System.Diagnostics.CodeAnalysis;
89
using System.IO;
10+
using System.Linq;
911
using System.Reactive.Subjects;
1012
using System.Runtime.Serialization.Formatters;
1113
using System.Text;
@@ -191,6 +193,24 @@ public Task post_blog(string title, string content, IEnumerable<byte[]> imageLis
191193
return Task.CompletedTask;
192194
}
193195

196+
public Task create_post(PostBuilder post)
197+
{
198+
List<byte[]> _media = new List<byte[]>();
199+
switch(post.PostType)
200+
{
201+
case PostBuilder.PostTypes.Blog:
202+
foreach (var media in post.MediaList) { _media.Add(media.Item1); }
203+
post_blog(post.Title, post.Content, _media, post.FansOnly, post.BackgroundColor);
204+
break;
205+
case PostBuilder.PostTypes.Wiki:
206+
foreach (var media in post.MediaList) { _media.Add(media.Item1); }
207+
post_wiki(post.Title, post.Content, _media, post.FansOnly, post.BackgroundColor);
208+
break;
209+
}
210+
return Task.CompletedTask;
211+
}
212+
213+
194214
/// <summary>
195215
/// Allows you to post a Wiki post on the current Community
196216
/// </summary>

Amino.NET/Types.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public enum User_Types
127127
}
128128
public enum Featured_Types
129129
{
130-
Unfreature,
130+
Unfeature,
131131
User,
132132
Blog,
133133
Wiki,

0 commit comments

Comments
 (0)