To install the @apiclient.xyz/ghost package, you can use npm or yarn. Make sure you're using a package manager that supports ESM and TypeScript.
NPM:
```bash
npm install @apiclient.xyz/ghost
```
Yarn:
```bash
yarn add @apiclient.xyz/ghost
```
## Usage
Below is a detailed guide on how to use the `@apiclient.xyz/ghost` package in your TypeScript projects. We will cover everything from initialization to advanced usage scenarios.
### Initialization
First, you need to import the necessary classes and initialize the Ghost instance with the required API keys.
```typescript
import { Ghost } from '@apiclient.xyz/ghost';
// Initialize the Ghost instance
const ghostInstance = new Ghost({
baseUrl: 'https://your-ghost-url.com',
contentApiKey: 'your-content-api-key',
adminApiKey: 'your-admin-api-key'
});
```
### Basic Usage
#### Fetching Posts
You can fetch posts with the following method. This will give you an array of `Post` instances.
```typescript
// Fetch all posts
const posts = await ghostInstance.getPosts();
// Print titles of all posts
posts.forEach(post => {
console.log(post.getTitle());
});
```
#### Fetching a Single Post by ID
To fetch a single post by its ID:
```typescript
const postId = 'your-post-id';
const post = await ghostInstance.getPostById(postId);
console.log(post.getTitle());
console.log(post.getHtml());
```
### Post Class Methods
The `Post` class has several methods that can be useful for different scenarios.
#### Getting Post Data
These methods allow you to retrieve various parts of the post data.
This package includes unit tests written using the `@push.rocks/tapbundle` and `@push.rocks/qenv` libraries. Here is how you can run them.
1. Install the development dependencies:
```bash
npm install
```
2. Run the tests:
```bash
npm test
```
### Conclusion
The `@apiclient.xyz/ghost` package provides a comprehensive and type-safe way to interact with the Ghost CMS API using TypeScript. The features provided by the `Ghost` and `Post` classes allow for a wide range of interactions, from basic CRUD operations to advanced filtering and error handling.
For more information, please refer to the [documentation](https://apiclient.xyz.gitlab.io/ghost/).