Merge pull request #290 from h3poteto/migration

Add migration guide for v3.0.0
This commit is contained in:
AkiraFukushima 2020-03-25 22:52:27 +09:00 committed by GitHub
commit d3809e9ddd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 97 additions and 0 deletions

View file

@ -8,6 +8,10 @@
A Mastodon, Pleroma and Misskey API Client library for node.js and browser. It provides REST API and streaming methods.
By using this library, you can take Mastodon, Pleroma and Misskey with the same interface.
## !!Migrate v2.x to v3.0.0
There are some breaking changes, so you can not update megalodon out of the box.
Please refer [migration guide](migration_guide.md) before you update megalodon version.
## Features
- REST API

93
migration_guide.md Normal file
View file

@ -0,0 +1,93 @@
# Upgrade v2.x to v3.0.0
## Overview
`megalodon` start Misskey support in version 3.0.0.
In this update, there are few breaking changes, so please read this migration guide if you are using megalodon v2.x.
There are three changes,
1. Move class methods in Mastodon
2. I prepare methods to call each Mastodon APIs
3. Changed default export function
## Move class methods in Mastodon
In [#180](https://github.com/h3poteto/megalodon/pull/180), these methods are moved and changed to instance methods:
- `registerApp`
- `createApp`
- `generateAuthUrl`
- `fetchAccessToken`
- `refreshToken`
So please call these methods from Mastodon like:
```typescript
import { Mastodon } from 'megalodon'
const client = new Mastodon(...)
client.registerApp('TestApp')
```
## I prepare methods to call each Mastodon APIs
In v2.x, probably you use `megalodon` like:
```typescript
import Mastodon from 'megalodon'
const client = new Mastodon(...)
client.get('/api/v1/timelines/home')
```
But these methods are deprecated, and are not exported from `megalodon` package.
I prepared methods instead of these.
There are all methods to call Mastodon APIs, so please use it.
```typescript
import { Mastodon } from 'megalodon'
const client = new Mastodon(...)
client.getHomeTimeline()
```
Please refer `megalodon` [document](https://h3poteto.github.io/megalodon/) for methods.
## Changed default export function
`megalodon` export `generator` function as default.
This function generate Client API instance for specified SNS.
```typescript
import generator from 'megalodon'
const client = generator(sns_name, url, access_token)
```
Now support `mastodon`, `pleroma` and `misskey` as sns parameter.
And detector function is defined.
This function detect which SNS's URL is provided.
It returns SNS name, `mastodon`, `pleroma` or `misskey`.
```typescript
import { detector } from 'megalodon'
const sns = await detector('https://mastodon.social')
```
These functions are necessary to treat multiple SNS.
The smart way to call multiple SNS endpoint in same interface is:
```typescript
import generator, { detector } from 'megalodon'
const sns = await detector(url)
const client = generator(sns, url, access_token)
client.getHomeTimeline()
```