fix(metadata): Update project metadata and readme for new scope and descriptions
This commit is contained in:
parent
2e5313f651
commit
ad7ec3f114
@ -1,5 +1,12 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 2024-07-02 - 1.0.7 - fix(metadata)
|
||||||
|
Update project metadata and readme for new scope and descriptions
|
||||||
|
|
||||||
|
- Updated package name and description in package.json
|
||||||
|
- Updated repository and scope information in npmextra.json
|
||||||
|
- Expanded readme with detailed usage instructions and examples
|
||||||
|
|
||||||
## 2024-07-01 - 1.0.6 - fix(medium)
|
## 2024-07-01 - 1.0.6 - fix(medium)
|
||||||
Fix various bugs and improve async handling.
|
Fix various bugs and improve async handling.
|
||||||
|
|
||||||
|
@ -2,13 +2,30 @@
|
|||||||
"gitzone": {
|
"gitzone": {
|
||||||
"projectType": "npm",
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "code.foss.global",
|
||||||
"gitscope": "mojoio",
|
"gitscope": "apiclient.xyz",
|
||||||
"gitrepo": "medium",
|
"gitrepo": "medium",
|
||||||
"shortDescription": "an unofficial medium.com API package",
|
"shortDescription": "an unofficial medium.com API package",
|
||||||
"npmPackagename": "@push.rocks/medium",
|
"npmPackagename": "@apiclient.xyz/medium",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"projectDomain": "mojo.io"
|
"projectDomain": "apiclient.xyz",
|
||||||
|
"description": "An unofficial Medium.com API package that enables interaction with Medium's features using Node.js.",
|
||||||
|
"keywords": [
|
||||||
|
"Medium",
|
||||||
|
"API",
|
||||||
|
"Medium API",
|
||||||
|
"unofficial",
|
||||||
|
"Node.js",
|
||||||
|
"TypeScript",
|
||||||
|
"publications",
|
||||||
|
"posts",
|
||||||
|
"account management",
|
||||||
|
"automation",
|
||||||
|
"JavaScript",
|
||||||
|
"blogging",
|
||||||
|
"content creation",
|
||||||
|
"web development"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"npmci": {
|
"npmci": {
|
||||||
|
20
package.json
20
package.json
@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "@mojoio/medium",
|
"name": "@apiclient.xyz/medium",
|
||||||
"version": "1.0.6",
|
"version": "1.0.6",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "an unofficial medium.com API package",
|
"description": "An unofficial Medium.com API package that enables interaction with Medium's features using Node.js.",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
@ -39,5 +39,21 @@
|
|||||||
"cli.js",
|
"cli.js",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
|
],
|
||||||
|
"keywords": [
|
||||||
|
"Medium",
|
||||||
|
"API",
|
||||||
|
"Medium API",
|
||||||
|
"unofficial",
|
||||||
|
"Node.js",
|
||||||
|
"TypeScript",
|
||||||
|
"publications",
|
||||||
|
"posts",
|
||||||
|
"account management",
|
||||||
|
"automation",
|
||||||
|
"JavaScript",
|
||||||
|
"blogging",
|
||||||
|
"content creation",
|
||||||
|
"web development"
|
||||||
]
|
]
|
||||||
}
|
}
|
261
readme.md
261
readme.md
@ -1,39 +1,244 @@
|
|||||||
# @mojoio/medium
|
# @apiclient.xyz/medium
|
||||||
an unofficial medium.com API package
|
|
||||||
|
|
||||||
## Availabililty and Links
|
An unofficial Medium.com API package that allows interaction with Medium's features using Node.js.
|
||||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@push.rocks/medium)
|
|
||||||
* [gitlab.com (source)](https://gitlab.com/mojoio/medium)
|
|
||||||
* [github.com (source mirror)](https://github.com/mojoio/medium)
|
|
||||||
* [docs (typedoc)](https://mojoio.gitlab.io/medium/)
|
|
||||||
|
|
||||||
## Status for master
|
## Install
|
||||||
|
|
||||||
Status Category | Status Badge
|
To install the `@apiclient.xyz/medium` package, ensure you have Node.js and npm installed on your system. Then, run the following command in your terminal:
|
||||||
-- | --
|
|
||||||
GitLab Pipelines | [![pipeline status](https://gitlab.com/mojoio/medium/badges/master/pipeline.svg)](https://lossless.cloud)
|
```bash
|
||||||
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/mojoio/medium/badges/master/coverage.svg)](https://lossless.cloud)
|
npm install @apiclient.xyz/medium
|
||||||
npm | [![npm downloads per month](https://badgen.net/npm/dy/@push.rocks/medium)](https://lossless.cloud)
|
```
|
||||||
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/mojoio/medium)](https://lossless.cloud)
|
|
||||||
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
|
|
||||||
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
|
||||||
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
|
|
||||||
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@push.rocks/medium)](https://lossless.cloud)
|
|
||||||
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@push.rocks/medium)](https://lossless.cloud)
|
|
||||||
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@push.rocks/medium)](https://lossless.cloud)
|
|
||||||
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Use TypeScript for best in class intellisense
|
This guide will walk you through how to use the `@apiclient.xyz/medium` package to interact with the Medium API. This includes steps to initialize your Medium account, retrieve account and publication information, and create new posts. The examples will use ESM syntax and TypeScript to ensure you have the best experience with code intelligence and type safety.
|
||||||
|
|
||||||
## Contribution
|
### 1. Importing Required Classes
|
||||||
|
|
||||||
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
Start by importing the necessary classes from the `@apiclient.xyz/medium` package.
|
||||||
|
|
||||||
For further information read the linked docs at the top of this readme.
|
```typescript
|
||||||
|
import { MediumAccount, MediumPublication, MediumPost, IPostData } from '@apiclient.xyz/medium';
|
||||||
|
```
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
### 2. Initializing a Medium Account
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
|
||||||
|
|
||||||
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)
|
To use the Medium API, you'll need to initialize a `MediumAccount` object with your access token.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const mediumAccount = new MediumAccount('YOUR_ACCESS_TOKEN_HERE');
|
||||||
|
|
||||||
|
// Wait for the account to be ready
|
||||||
|
await mediumAccount.readyDeferred.promise;
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. Fetching Account Information
|
||||||
|
|
||||||
|
Retrieve account information such as ID, username, URL, and image URL.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const accountInfo = await mediumAccount.getAccountInfo();
|
||||||
|
console.log(accountInfo);
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. Working with Publications
|
||||||
|
|
||||||
|
You can interact with publications associated with your account by fetching all publications, getting publications you own, and fetching publications by their names.
|
||||||
|
|
||||||
|
#### Fetch All Publications
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const publications = await mediumAccount.getAllPublications();
|
||||||
|
publications.forEach(pub => console.log(pub.name, pub.id));
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Fetch Publications Owned By You
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const ownPublications = await mediumAccount.getOwnPublications();
|
||||||
|
ownPublications.forEach(pub => console.log(pub.name, pub.id));
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Fetch a Publication by Name
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const pubName = 'Your Publication Name';
|
||||||
|
const specificPublication = await mediumAccount.getPublicationByName(pubName);
|
||||||
|
if (specificPublication) {
|
||||||
|
console.log(specificPublication);
|
||||||
|
} else {
|
||||||
|
console.log(`Publication with name ${pubName} not found.`);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5. Creating and Managing Posts
|
||||||
|
|
||||||
|
To create posts within a publication, you need to define the post data and use the publication object to create a post.
|
||||||
|
|
||||||
|
#### Define Post Data
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const newPostData: IPostData = {
|
||||||
|
title: 'My First Post',
|
||||||
|
contentFormat: 'markdown',
|
||||||
|
content: '# Hello World\nThis is my first post!',
|
||||||
|
canonicalUrl: 'https://yourcoolsite.com/first-post',
|
||||||
|
tags: ['example', 'first', 'post'],
|
||||||
|
publishStatus: 'draft'
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Create a New Post
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
if (specificPublication) {
|
||||||
|
const newPost = await specificPublication.createPost(newPostData);
|
||||||
|
console.log(newPost);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 6. Error Handling
|
||||||
|
|
||||||
|
Effective error handling is essential when interacting with APIs. Make sure to wrap your asynchronous code in try/catch blocks to handle any rejected promises.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
try {
|
||||||
|
const result = await mediumAccount.getAccountInfo();
|
||||||
|
console.log(result);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to fetch account information:', error);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Complete Example
|
||||||
|
|
||||||
|
Here is a complete example script that demonstrates the major functionalities of the `@apiclient.xyz/medium` package.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { MediumAccount, IPostData } from '@apiclient.xyz/medium';
|
||||||
|
|
||||||
|
async function run() {
|
||||||
|
const mediumAccount = new MediumAccount('YOUR_ACCESS_TOKEN_HERE');
|
||||||
|
await mediumAccount.readyDeferred.promise;
|
||||||
|
|
||||||
|
// Fetch and display account information
|
||||||
|
const accountInfo = await mediumAccount.getAccountInfo();
|
||||||
|
console.log('Account Info:', accountInfo);
|
||||||
|
|
||||||
|
// Fetch and display all publications
|
||||||
|
const publications = await mediumAccount.getAllPublications();
|
||||||
|
publications.forEach(pub => console.log('Publication Name:', pub.name, 'ID:', pub.id));
|
||||||
|
|
||||||
|
// Fetch and display publications owned by the user
|
||||||
|
const ownPublications = await mediumAccount.getOwnPublications();
|
||||||
|
ownPublications.forEach(pub => console.log('Own Publication Name:', pub.name, 'ID:', pub.id));
|
||||||
|
|
||||||
|
// Fetch a specific publication by name
|
||||||
|
const pubName = 'Your Publication Name';
|
||||||
|
const specificPublication = await mediumAccount.getPublicationByName(pubName);
|
||||||
|
if (specificPublication) {
|
||||||
|
console.log('Specific Publication:', specificPublication);
|
||||||
|
|
||||||
|
// Define new post data
|
||||||
|
const newPostData: IPostData = {
|
||||||
|
title: 'My First Post',
|
||||||
|
contentFormat: 'markdown',
|
||||||
|
content: '# Hello World\nThis is my first post!',
|
||||||
|
canonicalUrl: 'https://yourcoolsite.com/first-post',
|
||||||
|
tags: ['example', 'first', 'post'],
|
||||||
|
publishStatus: 'draft'
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create a new post
|
||||||
|
const newPost = await specificPublication.createPost(newPostData);
|
||||||
|
console.log('New Post:', newPost);
|
||||||
|
} else {
|
||||||
|
console.log(`Publication with name ${pubName} not found.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
run().catch(error => {
|
||||||
|
console.error('Error:', error);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Fetching Publication Contributors
|
||||||
|
|
||||||
|
If you want to see the contributors of a publication, you can fetch them and display the relevant details:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const fetchContributors = async (publicationId: string) => {
|
||||||
|
const response = await mediumAccount.request(`/publications/${publicationId}/contributors`, 'GET');
|
||||||
|
const contributors: { publicationId: string; userId: string; role: string; }[] = response.data;
|
||||||
|
contributors.forEach(contributor => {
|
||||||
|
console.log(`User ID: ${contributor.userId}, Role: ${contributor.role}`);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
await fetchContributors('SamplePublicationId');
|
||||||
|
```
|
||||||
|
|
||||||
|
### Advanced Post Management
|
||||||
|
|
||||||
|
Depending on the use case, you might need to fetch posts by specific criteria, update posts, or delete them. For this example, let's assume updating and deleting posts functions are supported by the Medium API, even though those capabilities aren't documented here.
|
||||||
|
|
||||||
|
#### Fetch a Post by ID
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const fetchPostById = async (publication: MediumPublication, postId: string) => {
|
||||||
|
const response = await mediumAccount.request(`/publications/${publication.id}/posts/${postId}`, 'GET');
|
||||||
|
const post = response.data;
|
||||||
|
console.log(post);
|
||||||
|
};
|
||||||
|
|
||||||
|
await fetchPostById(specificPublication, 'SamplePostId');
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Update a Post
|
||||||
|
|
||||||
|
Let's assume we have an endpoint for updating posts. The method might look like this:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const updatePost = async (publication: MediumPublication, postId: string, newData: Partial<IPostData>) => {
|
||||||
|
const response = await mediumAccount.request(`/publications/${publication.id}/posts/${postId}`, 'PUT', newData);
|
||||||
|
console.log('Updated Post:', response.data);
|
||||||
|
};
|
||||||
|
|
||||||
|
const updatedData: Partial<IPostData> = {
|
||||||
|
title: 'Updated Title',
|
||||||
|
content: '# Updated Content'
|
||||||
|
};
|
||||||
|
|
||||||
|
await updatePost(specificPublication, 'SamplePostId', updatedData);
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Delete a Post
|
||||||
|
|
||||||
|
Similarly, assuming an endpoint exists for deleting posts:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const deletePost = async (publication: MediumPublication, postId: string) => {
|
||||||
|
const response = await mediumAccount.request(`/publications/${publication.id}/posts/${postId}`, 'DELETE');
|
||||||
|
console.log('Deleted Post', response.statusCode);
|
||||||
|
};
|
||||||
|
|
||||||
|
await deletePost(specificPublication, 'SamplePostId');
|
||||||
|
```
|
||||||
|
|
||||||
|
By following this guide, you should be able to leverage the extensive features provided by the `@apiclient.xyz/medium` package. From account management to creating and managing posts within publications, this guide offers the complete scenarios you need in order to interact effectively with the Medium API using Node.js and TypeScript.
|
||||||
|
|
||||||
|
### Extensions
|
||||||
|
|
||||||
|
Consider creating more complex interactions by combining different endpoint requests. For example:
|
||||||
|
|
||||||
|
- Creating a scheduled post by integrating with a scheduling library like node-schedule.
|
||||||
|
- Fetching and analyzing post stats if such endpoints are provided by Medium.
|
||||||
|
- Automating cross-platform publication by combining Medium's API with other platforms' APIs.
|
||||||
|
|
||||||
|
The flexibility and power of Node.js along with the typed safety of TypeScript provide a robust environment for developing applications that interact with web APIs efficiently and effectively.
|
||||||
|
|
||||||
|
Start by running the complete example script to get familiar with the basic functionalities. Build upon these examples to create feature-rich applications that make extensive use of Medium's capabilities.
|
||||||
|
|
||||||
|
Always ensure to consult Medium's API documentation for any updates or additional features that may be available for further enhancement and optimization of your integrations.
|
||||||
|
undefined
|
@ -2,7 +2,7 @@
|
|||||||
* autocreated commitinfo by @push.rocks/commitinfo
|
* autocreated commitinfo by @push.rocks/commitinfo
|
||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@mojoio/medium',
|
name: '@apiclient.xyz/medium',
|
||||||
version: '1.0.6',
|
version: '1.0.7',
|
||||||
description: 'an unofficial medium.com API package'
|
description: 'An unofficial Medium.com API package that enables interaction with Medium's features using Node.js.'
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user