Merge pull request #35 from h3poteto/interface_for_mock
Add an interface for megalodon instance
This commit is contained in:
commit
200f23eb11
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue