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

Implement Briefkasten API #83

Merged
merged 1 commit into from
Aug 21, 2023
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ mastodon-bookmark-sync supports multiple Mastodon accounts.

**Supported bookmarking services:**

- [Briefkasten]
- [LinkAce]
- [linkding]
- [Pinboard]

[Briefkasten]:https://github.com/ndom91/briefkasten
[LinkAce]:https://linkace.org/
[linkding]:https://github.com/sissbruecker/linkding
[Pinboard]:https://pinboard.in/
Expand Down
3 changes: 2 additions & 1 deletion mastodon-bookmark-sync.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=Briefkasten/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Linkding/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Pinboard/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Raindropio/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=unbookmark/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/UserDictionary/Words/=unbookmark/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Net.Http.Headers;
using System.Net.Mime;
using BookmarkSync.Core;
using BookmarkSync.Infrastructure.Services.Bookmarking.Briefkasten;
using BookmarkSync.Infrastructure.Services.Bookmarking.LinkAce;
using BookmarkSync.Infrastructure.Services.Bookmarking.Linkding;
using BookmarkSync.Infrastructure.Services.Bookmarking.Pinboard;
Expand Down Expand Up @@ -31,6 +32,7 @@ public static IBookmarkingService GetBookmarkingService(IConfigManager configMan
{
return configManager.App.Bookmarking.Service switch
{
"Briefkasten" => new BriefkastenBookmarkingService(configManager),
"LinkAce" => new LinkAceBookmarkingService(configManager),
"Pinboard" => new PinboardBookmarkingService(configManager),
"linkding" => new LinkdingBookmarkingService(configManager),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.Net.Http.Headers;
using System.Net.Mime;
using System.Text;
using Newtonsoft.Json;

namespace BookmarkSync.Infrastructure.Services.Bookmarking.Briefkasten;

public class BriefkastenBookmarkingService : BookmarkingService, IBookmarkingService
{
private static readonly ILogger _logger = Log.ForContext<BriefkastenBookmarkingService>();
public BriefkastenBookmarkingService(IConfigManager configManager)
{
ApiToken = configManager.App.Bookmarking.ApiToken ?? throw new InvalidOperationException("Missing API token");
string briefkastenUri = configManager.GetConfigValue("App:Bookmarking:BriefkastenUri") ??
throw new InvalidOperationException("Missing Briefkasten Uri");
ApiUri = $"{briefkastenUri}/api/bookmarks";
}
/// <inheritdoc />
public async Task<HttpResponseMessage> Save(Bookmark bookmark)
{
// Prep payload
Dictionary<string, object?> payload = new()
{
{
"url", bookmark.Uri
},
{
"title", bookmark.Content
},
{
"tags", bookmark.DefaultTags
},
{
"userId", ApiToken
}
};
var stringContent = new StringContent(JsonConvert.SerializeObject(payload), Encoding.UTF8,
MediaTypeNames.Application.Json);
var response = await Client.PostAsync(ApiUri, stringContent);
response.EnsureSuccessStatusCode();
_logger.Debug("Response status: {StatusCode}", response.StatusCode);
return response;
}
}
1 change: 1 addition & 0 deletions tests/BookmarkSync.Infrastructure.Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

global using BookmarkSync.Core.Configuration;
global using BookmarkSync.Infrastructure.Services.Bookmarking;
global using BookmarkSync.Infrastructure.Services.Bookmarking.Briefkasten;
global using BookmarkSync.Infrastructure.Services.Bookmarking.LinkAce;
global using BookmarkSync.Infrastructure.Services.Bookmarking.Pinboard;
global using Microsoft.Extensions.Configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,35 @@ public void GetBookmarkingService_Exception()
// Assert - Exception
}
[TestMethod]
public void GetBookmarkingService_Briefkasten()
{
// Arrange
var config = new Dictionary<string, string?>
{
{
"App:Bookmarking:Service", "Briefkasten"
},
{
"App:Bookmarking:ApiToken", "ABC123DEF456"
},
{
"App:Bookmarking:BriefkastenUri", "https://briefkastenhq.com"
}
};
var configuration = new ConfigurationBuilder()
.AddInMemoryCollection(config)
.Build();

IConfigManager configManager = new ConfigManager(configuration);

// Act
var obj = BookmarkingService.GetBookmarkingService(configManager);

// Assert
Assert.AreEqual(typeof(BriefkastenBookmarkingService), obj.GetType());
Assert.IsInstanceOfType(obj, typeof(BriefkastenBookmarkingService));
}
[TestMethod]
public void GetBookmarkingService_LinkAce()
{
// Arrange
Expand Down
Loading