Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mika-f committed Mar 7, 2019
2 parents 0d69ef2 + b8d9670 commit c32e002
Show file tree
Hide file tree
Showing 317 changed files with 1,165 additions and 3,056 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ Collection of fediverse client libraries for .NET Standard 2.0.
| Service | Version | Project | NuGet | Nuget Version |
| -------- | ---------- | ----------------------------------------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| N/A | N/A | [`Disboard`](Source/Disboard) | `Disboard` | [![Disboard](https://img.shields.io/nuget/v/Disboard.svg?style=flat-square)](https://nuget.org/packages/Disboard) |
| Mastodon | 2.6.x | [`Disboard.Mastodon`](Source/Disboard.Mastodon) | `Disboard.Mastodon` | [![Disboard.Mastodon](https://img.shields.io/nuget/v/Disboard.Mastodon.svg?style=flat-square)](https://nuget.org/packages/Disboard.Mastodon) |
| Misskey | 10.38.0 | [`Disboard.Misskey`](Source/Disboard.Misskey) | `Disboard.Misskey` | [![Disboard.Misskey](https://img.shields.io/nuget/v/Disboard.Misskey.svg?style=flat-square)](https://nuget.org/packages/Disboard.Misskey) |
| Mastodon | 2.7.x | [`Disboard.Mastodon`](Source/Disboard.Mastodon) | `Disboard.Mastodon` | [![Disboard.Mastodon](https://img.shields.io/nuget/v/Disboard.Mastodon.svg?style=flat-square)](https://nuget.org/packages/Disboard.Mastodon) |
| Misskey | 10.90.0 | [`Disboard.Misskey`](Source/Disboard.Misskey) | `Disboard.Misskey` | [![Disboard.Misskey](https://img.shields.io/nuget/v/Disboard.Misskey.svg?style=flat-square)](https://nuget.org/packages/Disboard.Misskey) |
| Pleroma | `ad318189` | [`Disboard.Pleroma`](Source/Disboard.Pleroma) | `Disboard.Pleroma` | [![Disboard.Pleroma](https://img.shields.io/nuget/v/Disboard.Pleroma.svg?style=flat-square)](https://nuget.org/packages/Disboard.Pleroma) |


## Tests

| Platform | develop | latest |
| Platform | develop | latest |
| -------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------: |
| Windows | [![AppVeyor branch](https://img.shields.io/appveyor/ci/mika-f/Disboard/develop.svg?style=flat-square)](https://ci.appveyor.com/project/mika-f/Disboard/branch/develop) | [![AppVeyor](https://img.shields.io/appveyor/ci/mika-f/Disboard.svg?style=flat-square)](https://ci.appveyor.com/project/mika-f/Disboard/history) |
| Windows | [![AppVeyor branch](https://img.shields.io/appveyor/ci/mika-f/Disboard/develop.svg?style=flat-square)](https://ci.appveyor.com/project/mika-f/Disboard/branch/develop) | [![AppVeyor](https://img.shields.io/appveyor/ci/mika-f/Disboard.svg?style=flat-square)](https://ci.appveyor.com/project/mika-f/Disboard/history) |
| Debian | [![CircleCI branch](https://img.shields.io/circleci/project/github/OrionDevelop/Disboard/develop.svg?style=flat-square)](https://circleci.com/gh/OrionDevelop/Disboard/tree/develop) | [![CircleCI](https://img.shields.io/circleci/project/github/OrionDevelop/Disboard.svg?style=flat-square)](https://circleci.com/gh/OrionDevelop/Disboard) |


Expand All @@ -31,7 +31,7 @@ Collection of fediverse client libraries for .NET Standard 2.0.

1. Fork it!
2. Create your feature branch (`git checkout -b feature/foobar`)
3. Commit your changes (`git commit -am'Add some foobar`)
3. Commit your changes (`git commit -am'Add some foobar'`)
4. Push to the branch (`git push origin feature/foobar`)
5. Create a new Pull Request

Expand Down
33 changes: 33 additions & 0 deletions Source/Disboard.AutoDocs/articles/misskey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Disboard.Misskey

Disboard.Misskey は、 Disboard の Misskey 拡張です。
REST 形式 API と Streaming (WebSocket) 形式 API の両方をサポートしています。

なお、一部の特権権限な必要な API と、リバーシ (およびゲーム) の API には対応していません。


## REST 形式 API

Disboard では、 Streaming を除く全ての API に対して、 REST での呼び出しが可能です。
REST 形式の API は、`~Async()` なメソッドで提供しており、認証情報さえあれば呼び出しが可能です。


## Streaming (WebSocket) 形式 API

Misskey では、 REST の他に、すでに接続している WebSocket にリクエストをのせて API の呼び出しが可能です。
Disboard ではこの形式の API 呼び出しにも対応しています。

Streaming (WebSocket) 形式での呼び出しには、予め WebSocket コネクションを開いておく必要があります。

```csharp
await misskey.Streaming.ConnectAsync();
```

コネクションを開いたら、 `~WsAsync()` なメソッドを呼び出すことで、 WebSocket コネクションを使ってリクエストを行えます。
ただし、全ての API がサポートされているわけではなく、一部対象外となっている API もあります。

WebSocket コネクションを閉じるには、 `Disconnect()` を呼び出します。

```csharp
misskey.Disconnect();
```
4 changes: 3 additions & 1 deletion Source/Disboard.AutoDocs/articles/toc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
- name: Introduction
href: intro.md
- name: Extend Disboard
href: extend.md
href: extend.md
- name: Misskey
href: misskey.md
19 changes: 17 additions & 2 deletions Source/Disboard.Mastodon/Clients/AccountsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task<CredentialAccount> UpdateCredentialsAsync(string displayName =
parameters.AddIfValidValue("locked", isLocked);
parameters.AddIfValidValue("bot", isBot);
if (fields != null)
foreach (var tuple in fields.Select((w, i) => new {Index = i, Field = w}))
foreach (var tuple in fields.Select((w, i) => new { Index = i, Field = w }))
{
parameters.AddIfValidValue($"fields_attributes[{tuple.Index}][name]", tuple.Field.Name);
parameters.AddIfValidValue($"fields_attributes[{tuple.Index}][value]", tuple.Field.Value);
Expand Down Expand Up @@ -61,7 +61,7 @@ public async Task<List<Relationship>> RelationshipsAsync(List<long> id)
}

public async Task<Pagenator<Status>> StatusesAsync(long id, long? limit = null, long? sinceId = null, long? minId = null, long? maxId = null, bool? isPinned = null, bool? isOnlyMedia = null,
bool? excludeReplies = null)
bool? excludeReplies = null, bool? excludeReblogs = null)
{
var parameters = new List<KeyValuePair<string, object>>();
parameters.AddIfValidValue("limit", limit);
Expand All @@ -71,6 +71,7 @@ public async Task<Pagenator<Status>> StatusesAsync(long id, long? limit = null,
parameters.AddIfValidValue("pinned", isPinned);
parameters.AddIfValidValue("only_media", isOnlyMedia);
parameters.AddIfValidValue("exclude_replies", excludeReplies);
parameters.AddIfValidValue("exclude_reblogs", excludeReblogs);

return await GetAsync<Pagenator<Status>>($"/{id}/statuses", parameters).Stay();
}
Expand Down Expand Up @@ -155,5 +156,19 @@ public async Task<CredentialAccount> VerifyCredentialsAsync()
{
return await GetAsync<CredentialAccount>("/verify_credentials").Stay();
}

public async Task<Tokens> CreateAsync(string username, string email, string password, bool agreement, string locale)
{
var parameters = new List<KeyValuePair<string, object>>
{
new KeyValuePair<string, object>("username", username),
new KeyValuePair<string, object>("email", email),
new KeyValuePair<string, object>("password", password),
new KeyValuePair<string, object>("agreement", agreement),
new KeyValuePair<string, object>("locale", locale)
};

return await PostAsync<Tokens>(parameters: parameters).Stay();
}
}
}
37 changes: 37 additions & 0 deletions Source/Disboard.Mastodon/Clients/ScheduledStatusesClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

using Disboard.Clients;
using Disboard.Extensions;
using Disboard.Mastodon.Models;

namespace Disboard.Mastodon.Clients
{
public class ScheduledStatusesClient : ApiClient<MastodonClient>
{
protected internal ScheduledStatusesClient(MastodonClient client) : base(client, "/api/v1/scheduled_statuses") { }

public async Task<List<ScheduledStatus>> ListAsync()
{
return await GetAsync<List<ScheduledStatus>>().Stay();
}

public async Task<ScheduledStatus> ShowAsync(long id)
{
return await GetAsync<ScheduledStatus>($"/{id}").Stay();
}

public async Task<ScheduledStatus> UpdateAsync(long id, DateTime scheduledAt)
{
var parameters = new List<KeyValuePair<string, object>> { new KeyValuePair<string, object>("scheduled_at", scheduledAt.ToString("O")) }; // ISO 8601}

return await PutAsync<ScheduledStatus>($"/{id}", parameters).Stay();
}

public async Task DeleteAsync(long id)
{
await DeleteAsync($"/{id}").Stay();
}
}
}
24 changes: 23 additions & 1 deletion Source/Disboard.Mastodon/Clients/StatusesClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

using Disboard.Clients;
Expand Down Expand Up @@ -83,6 +84,8 @@ public async Task<Card> CardAsync(long id)
return await GetAsync<Card>($"/{id}/card").Stay();
}

#region UpdateAsync

public async Task<Status> UpdateAsync(string status, long? inReplyToId = null, List<long> mediaIds = null, bool? isSensitive = null, string spoilerText = null,
VisibilityType? visibility = null)
{
Expand All @@ -99,6 +102,25 @@ public async Task<Status> UpdateAsync(string status, long? inReplyToId = null, L
return await PostAsync<Status>(parameters: parameters).Stay();
}

public async Task<ScheduledStatus> UpdateAsync(string status, long? inReplyToId = null, List<long> mediaIds = null, bool? isSensitive = null, string spoilerText = null,
VisibilityType? visibility = null, DateTime? scheduledAt = null)
{
var parameters = new List<KeyValuePair<string, object>>
{
new KeyValuePair<string, object>("status", status)
};
parameters.AddIfValidValue("in_reply_to_id", inReplyToId);
mediaIds?.ForEach(w => parameters.Add(new KeyValuePair<string, object>("media_ids[]", w)));
parameters.AddIfValidValue("sensitive", isSensitive);
parameters.AddIfValidValue("spoiler_text", spoilerText);
parameters.AddIfValidValue("visibility", visibility.ToString().ToLower());
parameters.AddIfValidValue("scheduled_at", scheduledAt);

return await PostAsync<ScheduledStatus>(parameters: parameters).Stay();
}

#endregion

public async Task<Status> ShowAsync(long id)
{
return await GetAsync<Status>($"/{id}").Stay();
Expand Down
6 changes: 4 additions & 2 deletions Source/Disboard.Mastodon/MastodonClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ namespace Disboard.Mastodon
{
public class MastodonClient : AppClient
{
public MastodonClient(string domain, HttpClientHandler innerHandler = null) : this(new Credential {Domain = domain}, innerHandler) { }
public MastodonClient(string domain, HttpClientHandler innerHandler = null) : this(new Credential { Domain = domain }, innerHandler) { }

public MastodonClient(Credential credential, HttpClientHandler innerHandler = null) : base(credential, new OAuth2HttpClientHandler(innerHandler), RequestMode.FormUrlEncoded)
{
BinaryParameters = new List<string> {"avatar", "header", "file"};
BinaryParameters = new List<string> { "avatar", "header", "file" };

Account = new AccountsClient(this);
Apps = new AppsClient(this);
Expand All @@ -33,6 +33,7 @@ public MastodonClient(string domain, HttpClientHandler innerHandler = null) : th
Notifications = new NotificationsClient(this);
Push = new PushClient(this);
Reports = new ReportsClient(this);
ScheduledStatuses = new ScheduledStatusesClient(this);
SearchV1 = new SearchV1Client(this);
SearchV2 = new SearchV2Client(this);
Statuses = new StatusesClient(this);
Expand Down Expand Up @@ -61,6 +62,7 @@ public MastodonClient(string domain, HttpClientHandler innerHandler = null) : th
public NotificationsClient Notifications { get; }
public PushClient Push { get; }
public ReportsClient Reports { get; }
public ScheduledStatusesClient ScheduledStatuses { get; }
public SearchV1Client SearchV1 { get; }
public SearchV2Client SearchV2 { get; }
public StatusesClient Statuses { get; }
Expand Down
26 changes: 26 additions & 0 deletions Source/Disboard.Mastodon/Models/ScheduledStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;

using Disboard.Models;

using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Disboard.Mastodon.Models
{
public class ScheduledStatus : ApiResponse
{
[JsonProperty("id")]
public string Id { get; set; }

[JsonProperty("scheduled_at")]
[JsonConverter(typeof(IsoDateTimeConverter))]
public DateTime ScheduledAt { get; set; }

[JsonProperty("params")]
public StatusParams Params { get; set; }

[JsonProperty("media_attachments")]
public List<Attachment> MediaAttachments { get; set; }
}
}
43 changes: 43 additions & 0 deletions Source/Disboard.Mastodon/Models/StatusParams.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;

using Disboard.Mastodon.Enums;
using Disboard.Models;

using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Disboard.Mastodon.Models
{
public class StatusParams : ApiResponse
{
[JsonProperty("text")]
public string Text { get; set; }

[JsonProperty("in_reply_to_id")]
public string InReplyToId { get; set; }

[JsonProperty("media_ids")]
public List<string> MediaIds { get; set; }

[JsonProperty("sensitive")]
public bool? IsSensitive { get; set; }

[JsonProperty("spoiler_text")]
public string SpoilerText { get; set; }

[JsonProperty("visibility")]
[JsonConverter(typeof(StringEnumConverter))]
public VisibilityType? Visibility { get; set; }

[JsonProperty("scheduled_at")]
[JsonConverter(typeof(IsoDateTimeConverter))]
public DateTime? ScheduledAt { get; set; }

[JsonProperty("application_id")]
public string ApplicationId { get; set; }

[JsonProperty("idempotency")]
public string Idempotency { get; set; }
}
}
6 changes: 3 additions & 3 deletions Source/Disboard.Mastodon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@


Mastodon API wrapper for .NET Standard 2.0.
Based on Mastodon 2.6.x.
Based on Mastodon 2.7.x.


## Note

[Mastodon's documentation](https://github.com/tootsuite/documentation) is not trustworthy.
If you want to contribute to this library, you SHOULD read [Mastodon's source code implementation](https://github.com/tootsuite/mastodon).
Disboard is based on [Mastodon's documentation](https://docs.joinmastodon.org/).
If there is something that not mentioned in the document, Disboard does not support it.

**This is a generic Mastodon API wrapper**, we do not implement features unique to the instance.
For example, pixiv's instance "pawoo.net" implements unique features, we do not support one.
Expand Down
18 changes: 12 additions & 6 deletions Source/Disboard.Misskey/Clients/Aggregation/UsersClient.Ws.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

using Disboard.Extensions;
Expand All @@ -8,38 +9,43 @@ namespace Disboard.Misskey.Clients.Aggregation
{
public partial class UsersClient
{
[Obsolete]
public async Task<List<PostAggregation>> ActivityWsAsync(string userId, int? limit = null)
{
var parameters = new List<KeyValuePair<string, object>> {new KeyValuePair<string, object>("userId", userId)};
var parameters = new List<KeyValuePair<string, object>> { new KeyValuePair<string, object>("userId", userId) };
parameters.AddIfValidValue("limit", limit);

return await SendWsAsync<List<PostAggregation>>("/activity", parameters).Stay();
}

[Obsolete]
public async Task<List<CountAggregation>> FollowersWsAsync(string userId)
{
var parameters = new List<KeyValuePair<string, object>> {new KeyValuePair<string, object>("userId", userId)};
var parameters = new List<KeyValuePair<string, object>> { new KeyValuePair<string, object>("userId", userId) };

return await SendWsAsync<List<CountAggregation>>("/followers", parameters).Stay();
}

[Obsolete]
public async Task<List<CountAggregation>> FollowingWsAsync(string userId)
{
var parameters = new List<KeyValuePair<string, object>> {new KeyValuePair<string, object>("userId", userId)};
var parameters = new List<KeyValuePair<string, object>> { new KeyValuePair<string, object>("userId", userId) };

return await SendWsAsync<List<CountAggregation>>("/following", parameters).Stay();
}

[Obsolete]
public async Task<List<PostAggregation>> PostWsAsync(string userId)
{
var parameters = new List<KeyValuePair<string, object>> {new KeyValuePair<string, object>("userId", userId)};
var parameters = new List<KeyValuePair<string, object>> { new KeyValuePair<string, object>("userId", userId) };

return await SendWsAsync<List<PostAggregation>>("/post", parameters).Stay();
}

[Obsolete]
public async Task<List<CountAggregation>> ReactionWsAsync(string userId)
{
var parameters = new List<KeyValuePair<string, object>> {new KeyValuePair<string, object>("userId", userId)};
var parameters = new List<KeyValuePair<string, object>> { new KeyValuePair<string, object>("userId", userId) };

return await SendWsAsync<List<CountAggregation>>("/reaction", parameters).Stay();
}
Expand Down
Loading

0 comments on commit c32e002

Please sign in to comment.