Merge pull request #35 from h3poteto/interface_for_mock

Add an interface for megalodon instance
This commit is contained in:
AkiraFukushima 2019-03-26 22:59:19 +09:00 committed by GitHub
commit 200f23eb11
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View file

@ -1,4 +1,4 @@
import Mastodon from './mastodon'
import Mastodon, { MegalodonInstance } from './mastodon'
import StreamListener from './stream_listener'
import WebSocket from './web_socket'
import Response from './response'
@ -37,6 +37,7 @@ export {
WebSocket,
Response,
OAuth,
MegalodonInstance,
/**
* Entities
*/

View file

@ -10,12 +10,25 @@ const NO_REDIRECT = 'urn:ietf:wg:oauth:2.0:oob'
const DEFAULT_URL = 'https://mastodon.social'
const DEFAULT_SCOPE = 'read write follow'
/**
* Interface
*/
export interface MegalodonInstance {
get<T = any>(path: string, params: object): Promise<Response<T>>
put<T = any>(path: string, params: object): Promise<Response<T>>
patch<T = any>(path: string, params: object): Promise<Response<T>>
post<T = any>(path: string, params: object): Promise<Response<T>>
del(path: string, params: object): Promise<Response<{}>>
stream(path: string, reconnectInterval: number): StreamListener
socket(path: string, strea: string): WebSocket
}
/**
* Mastodon API client.
*
* Using axios for request, you will handle promises.
*/
export default class Mastodon {
export default class Mastodon implements MegalodonInstance {
static DEFAULT_SCOPE = DEFAULT_SCOPE
static DEFAULT_URL = DEFAULT_URL
static NO_REDIRECT = NO_REDIRECT