Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/grantwinney/ghostsharp
A wrapper for the Ghost blog's RESTful JSON API, written in C#
https://github.com/grantwinney/ghostsharp
api api-wrapper csharp ghost ghost-api ghost-blog rest-api restful-api
Last synced: 2 months ago
JSON representation
A wrapper for the Ghost blog's RESTful JSON API, written in C#
- Host: GitHub
- URL: https://github.com/grantwinney/ghostsharp
- Owner: grantwinney
- License: mit
- Created: 2018-02-10T14:09:06.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-08T14:46:51.000Z (about 2 years ago)
- Last Synced: 2023-02-27T16:33:42.337Z (almost 2 years ago)
- Topics: api, api-wrapper, csharp, ghost, ghost-api, ghost-blog, rest-api, restful-api
- Language: C#
- Homepage:
- Size: 694 KB
- Stars: 16
- Watchers: 2
- Forks: 5
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
๏ปฟ[![CI Build](https://github.com/grantwinney/GhostSharp/actions/workflows/dotnet.yml/badge.svg)](https://github.com/grantwinney/GhostSharp/actions/workflows/dotnet.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
[![NuGet](https://img.shields.io/nuget/v/GhostSharp.svg)](https://www.nuget.org/packages/GhostSharp)
[![CodeFactor](https://www.codefactor.io/repository/github/grantwinney/ghostsharp/badge)](https://www.codefactor.io/repository/github/grantwinney/ghostsharp)
[![Open Source Helpers](https://www.codetriage.com/grantwinney/ghostsharp/badges/users.svg)](https://www.codetriage.com/grantwinney/ghostsharp)
![Language](https://img.shields.io/github/languages/top/grantwinney/GhostSharp.svg)
[![Twitter](https://img.shields.io/twitter/url/http/shields.io.svg)](https://twitter.com/intent/tweet?url=https%3A%2F%2Fgithub.com%2Fgrantwinney%2FGhostSharp&text=GhostSharp,%20a%20C%23%20Wrapper%20for%20the%20Ghost%20API&hashtags=tryghost,api)# GhostSharp
This is a [wrapper](https://grantwinney.com/what-is-an-api-wrapper-and-how-do-i-write-one/) around v5.0 of the [Content](https://ghost.org/docs/content-api/) and [Admin](https://ghost.org/docs/admin-api/) APIs. They are RESTful JSON APIs built into the core of the [Ghost blogging platform](https://ghost.org/). Check out the [official Ghost API docs](https://ghost.org/docs/api/) and read [a little about my experience using them](https://grantwinney.com/what-is-the-ghost-api/).
## Usage
### Accessing the Content API
If you need to access the Content API, all you need is the URL of your site and a Content API Key, [available on the "Integrations" page](https://ghost.org/docs/content-api/#key). Once you have those pieces of information, you can access any "public" content.
```csharp
var ghost = new GhostSharp.GhostContentAPI("https://grantwinney.com", "a6d33f1b95ff17adf0f787a70a");
var settings = ghost.GetSettings();Console.WriteLine($"Welcome to {settings.Title}: {settings.Description}\r\n");
Console.WriteLine($"Navigation: {string.Join(", ", settings.Navigation.Select(x => x.Label))}");
```Output:
```
Welcome to Grant Winney: We learn by doing. We've all got something to contribute.Navigation: Home, APIs, Lambda, Rasp PI, About Me, CV
```### Accessing the Admin API
If you need to access the Admin API, all you need is the URL of your site and an Admin API Key, also [available on the "Integrations" page](https://docs.ghost.org/api/content/#key). Once you have those pieces of information, you can access any "private" content.
```csharp
var ghost = new GhostSharp.GhostAdminAPI("https://grantwinney.com",
"5cf706fd7d4a33066550627a:9e5ed2b90e40f68573b0ccaf4aef666b047fc9867ad285b2e219eed5503bae53");
var site = ghost.GetSite();Console.WriteLine($"Welcome to {site.Title}\r\n");
Console.WriteLine($"Running Ghost v{site.Version}");
```Output:
```
Welcome to Grant WinneyRunning Ghost v2.23
```You can optionally pass in a version number for the API (i.e. 4.0), or omit it to default to the latest ([currently 5.0](https://ghost.org/docs/faq/major-versions-lts/)).
I'm only able to support one version (due to there only being 24 hours in a day), but setting that to a lesser value may work in some cases too.## Running the Tests
The tests are setup to run against an actual instance of the Ghost blog, using a valid API key. There are details in the `TestBase.cs` class that you'll need to fill in, such as a valid API key, valid post ID, valid post slug, etc, etc.
## Problems?
[Open an issue](https://github.com/grantwinney/GhostSharp/issues/new), and include errors, unexpected behavior, steps to reproduce, etc. The more details, the better!
Feel free to [open a PR](https://github.com/grantwinney/GhostSharp/compare) if you figure out how to fix it.
## Ideas?
[Open an issue](https://github.com/grantwinney/GhostSharp/issues/new). I can't promise when new features or suggestions will get implemented, but I'll check them out.
## Release Notes
* 2.0.0 - โญ Upgraded to .NET 6 and API v5. Implemented the stable endpoints, except for members.
* 1.0.9 - ๐ Noticed that pages aren't being created; other refactoring.
***Breaking change:** Eliminated Page in favor of a single Post object again, for simplicity. The split wasn't necessary as a Page is just a Post that doesn't end up in feeds. Also, a few fields in a Post don't play nicely when creating pages, but I figured out a different way to omit those.*
* 1.0.8 - ๐ Several fields marked as updateable that aren't. (thx for the heads up @unnanego)
***Breaking change:** This led to a larger refactoring, which might break some current implementations. Properties in the Post class that cannot be changed now have private setters (instead of just an attribute on them). The Page class was completely separated from the Post class, so RestSharp could correctly deserialize objects coming from Ghost.*
* 1.0.7 - โญ Implement the Themes admin endpoint. (thx for pointing me in the right direction @naz)
* 1.0.6 - โญ Implement API v3.
* 1.0.4 - ๐งน Code cleanup. Added license to NuGet package.
* 1.0.3 - โญ Implement Admin API v2 endpoints (posts, pages, images, site)
***Breaking change:** GhostAPI is now split into GhostContentAPI and GhostAdminAPI*
* 1.0.1 - ๐งน Added comments to aid in intellisense.
* 1.0.0 - โญ Implement Content API endpoints.