diff --git a/README.md b/README.md index d594709..24c2a3f 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,400 @@ # Dapplo.Confluence -This is a simple REST based Confluence client, written for Greenshot, by using Dapplo.HttpExtension -- Current build status: [](https://dev.azure.com/Dapplo/Dapplo%20framework/_build/latest?definitionId=11&branchName=master) -- Coverage Status: [](https://coveralls.io/github/dapplo/Dapplo.Confluence?branch=master) -- NuGet package: [](https://badge.fury.io/nu/Dapplo.Confluence) +[](https://dev.azure.com/Dapplo/Dapplo%20framework/_build/latest?definitionId=11&branchName=master) +[](https://coveralls.io/github/dapplo/Dapplo.Confluence?branch=master) +[](https://badge.fury.io/nu/Dapplo.Confluence) +[](https://opensource.org/licenses/MIT) -The Confluence client supports most REST methods, and has a fluent API for building a CQL (Confluence Query Language) string to search with. +## Overview -An example on how to use this Confluence client: +**Dapplo.Confluence** is a .NET client library for interacting with Atlassian Confluence via its REST API. Originally developed for [Greenshot](https://getgreenshot.org/), this library provides a clean, intuitive interface for programmatically managing Confluence content, spaces, users, attachments, and more. + +Built on top of [Dapplo.HttpExtensions](https://github.com/dapplo/Dapplo.HttpExtensions), it offers a fluent API for building CQL (Confluence Query Language) queries and supports both Confluence Server and Confluence Cloud deployments. + +## Key Features + +- **Full REST API Support**: Interact with Content, Spaces, Users, Attachments, Groups, and more +- **Fluent CQL Query Builder**: Build type-safe Confluence Query Language queries with IntelliSense support +- **Multiple Authentication Methods**: Basic Authentication, Bearer Token (PAT), and OAuth support +- **Multi-Target Framework Support**: Works with .NET Standard 1.3/2.0, .NET Framework 4.7.1, .NET Core 3.1, and .NET 6.0 +- **Async/Await Pattern**: All API operations are fully asynchronous +- **Extensible Plugin System**: Easily extend the client with custom functionality +- **Cloud & Server Compatible**: Works with both Confluence Cloud and Confluence Server/Data Center + +## Installation + +Install via NuGet Package Manager: + +```bash +dotnet add package Dapplo.Confluence ``` -var confluenceClient = ConfluenceClient.Create(new Uri("https://confluence")); -confluenceClient.SetBasicAuthentication(username, password); + +Or via the Package Manager Console: + +```powershell +Install-Package Dapplo.Confluence +``` + +For OAuth authentication support, also install: + +```bash +dotnet add package Dapplo.Confluence.OAuth +``` + +## Prerequisites + +- .NET Standard 1.3+ compatible runtime, or +- .NET Framework 4.7.1+, or +- .NET Core 3.1+, or +- .NET 6.0+ + +## Quick Start + +### Creating a Client + +```csharp +using Dapplo.Confluence; + +// Create a client instance +var confluenceClient = ConfluenceClient.Create(new Uri("https://your-confluence-url")); +``` + +### Authentication + +**Basic Authentication (Confluence Server):** +```csharp +confluenceClient.SetBasicAuthentication("username", "password"); +``` + +**Basic Authentication (Confluence Cloud):** +```csharp +// For Confluence Cloud, use your email as username and an API token as password +// Generate API token at: https://id.atlassian.com/manage/api-tokens +confluenceClient.SetBasicAuthentication("your-email@example.com", "your-api-token"); +``` + +**Bearer Token / Personal Access Token:** +```csharp +confluenceClient.SetBearerAuthentication("your-personal-access-token"); +``` + +### Basic Usage Example + +```csharp +using Dapplo.Confluence; +using Dapplo.Confluence.Query; + +// Create and authenticate client +var confluenceClient = ConfluenceClient.Create(new Uri("https://your-domain.atlassian.net/wiki")); +confluenceClient.SetBasicAuthentication("email@example.com", "api-token"); + +// Build a CQL query var query = Where.And(Where.Type.IsPage, Where.Text.Contains("Test Home")); -var searchResult = await confluenceClient.Content.SearchAsync(query, limit:1); + +// Search for content +var searchResult = await confluenceClient.Content.SearchAsync(query, limit: 10); + foreach (var contentDigest in searchResult.Results) { - // As the content from the Search is a digest, get the details (it's also possible to get the details during the search) - var content = await confluenceClient.Content.GetAsync(contentDigest, ConfluenceClientConfig.ExpandGetContentWithStorage); - // Output the information - Debug.WriteLine(content.Body); + // Get full content details with body storage format + var content = await confluenceClient.Content.GetAsync( + contentDigest, + ConfluenceClientConfig.ExpandGetContentWithStorage + ); + + Console.WriteLine($"Title: {content.Title}"); + Console.WriteLine($"Body: {content.Body?.Storage?.Value}"); } ``` -If you want to extend the API for a specific use-case where it doesn't make sense to provide it to the rest of the world via a pull-request, for example to add logic for a *plugin*, you can write an extension method to extend the IConfluenceClientPlugins. -Your "plugin" extension will now be available, if the developer has a using statement of your namespace, on the .Plugins property of the IConfluenceClient +## API Domains + +The client is organized into logical domains for different Confluence operations: + +### Content Domain (`confluenceClient.Content`) +- Create, read, update, and delete pages and blog posts +- Search content using CQL queries +- Manage content labels +- Get content history and children +- Copy and move content (Cloud only) + +```csharp +// Create a new page +var page = await confluenceClient.Content.CreateAsync( + ContentTypes.Page, + "Page Title", + "SPACEKEY", + "
Page content in HTML
" +); + +// Get content by ID +var content = await confluenceClient.Content.GetAsync(contentId); + +// Update existing content +content.Body.Storage.Value = "Updated content
"; +// Confluence requires incrementing the version number for updates to prevent conflicts +content.Version.Number++; +await confluenceClient.Content.UpdateAsync(content); + +// Delete content +await confluenceClient.Content.DeleteAsync(contentId); +``` + +### Space Domain (`confluenceClient.Space`) +- Get space information and list spaces +- Access space contents + +```csharp +// Get all spaces +var spaces = await confluenceClient.Space.GetAllAsync(); + +// Get a specific space +var space = await confluenceClient.Space.GetAsync("SPACEKEY"); +``` + +### User Domain (`confluenceClient.User`) +- Get user information +- Search for users + +```csharp +// Get current user +var currentUser = await confluenceClient.User.GetCurrentUserAsync(); + +// Get user by username +var user = await confluenceClient.User.GetAsync("username"); +``` + +### Attachment Domain (`confluenceClient.Attachment`) +- Upload, download, and manage attachments + +```csharp +// Get attachments for content +var attachments = await confluenceClient.Attachment.GetAttachmentsAsync(contentId); + +// Download attachment content +var attachmentData = await confluenceClient.Attachment.GetContentAsync