Merge pull request #719 from h3poteto/interfaces
User interface for api_client
This commit is contained in:
commit
46ae259232
|
@ -10,7 +10,7 @@ import { ProxyConfig } from './proxy_config'
|
|||
import OAuth from './oauth'
|
||||
|
||||
export default class Mastodon implements MegalodonInterface {
|
||||
public client: MastodonAPI.Client
|
||||
public client: MastodonAPI.Interface
|
||||
public baseUrl: string
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,14 +16,14 @@ namespace MastodonAPI {
|
|||
* Interface
|
||||
*/
|
||||
export interface Interface {
|
||||
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<{}>>
|
||||
get<T = any>(path: string, params?: any): Promise<Response<T>>
|
||||
put<T = any>(path: string, params?: any): Promise<Response<T>>
|
||||
patch<T = any>(path: string, params?: any): Promise<Response<T>>
|
||||
post<T = any>(path: string, params?: any): Promise<Response<T>>
|
||||
del<T = any>(path: string, params?: any): Promise<Response<T>>
|
||||
cancel(): void
|
||||
stream(path: string, reconnectInterval: number): StreamListener
|
||||
socket(path: string, stream: string): WebSocket
|
||||
stream(path: string, reconnectInterval?: number): StreamListener
|
||||
socket(path: string, stream: string, params?: string): WebSocket
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -280,7 +280,7 @@ namespace MastodonAPI {
|
|||
* @param reconnectInterval interval of reconnect
|
||||
* @returns streamListener, which inherits from EventEmitter
|
||||
*/
|
||||
public stream(path: string, reconnectInterval = 1000): StreamListener {
|
||||
public stream(path: string, reconnectInterval: number = 1000): StreamListener {
|
||||
if (!this.accessToken) {
|
||||
throw new Error('accessToken is required')
|
||||
}
|
||||
|
@ -306,7 +306,7 @@ namespace MastodonAPI {
|
|||
* @param stream Stream name, please refer: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/web/mastodon_api/mastodon_socket.ex#L19-28
|
||||
* @returns WebSocket, which inherits from EventEmitter
|
||||
*/
|
||||
public socket(path: string, stream: string, params: string | null = null): WebSocket {
|
||||
public socket(path: string, stream: string, params?: string): WebSocket {
|
||||
if (!this.accessToken) {
|
||||
throw new Error('accessToken is required')
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ export default class WebSocket extends EventEmitter implements WebSocketInterfac
|
|||
constructor(
|
||||
url: string,
|
||||
stream: string,
|
||||
params: string | null,
|
||||
params: string | undefined,
|
||||
accessToken: string,
|
||||
userAgent: string,
|
||||
proxyConfig: ProxyConfig | false = false
|
||||
|
@ -45,7 +45,11 @@ export default class WebSocket extends EventEmitter implements WebSocketInterfac
|
|||
super()
|
||||
this.url = url
|
||||
this.stream = stream
|
||||
this.params = params
|
||||
if (params === undefined) {
|
||||
this.params = null
|
||||
} else {
|
||||
this.params = params
|
||||
}
|
||||
this.parser = new Parser()
|
||||
this.headers = {
|
||||
'User-Agent': userAgent
|
||||
|
|
|
@ -13,7 +13,7 @@ import {
|
|||
} from './megalodon'
|
||||
|
||||
export default class Misskey implements MegalodonInterface {
|
||||
public client: MisskeyAPI.Client
|
||||
public client: MisskeyAPI.Interface
|
||||
public baseUrl: string
|
||||
public proxyConfig: ProxyConfig | false
|
||||
|
||||
|
|
|
@ -413,7 +413,11 @@ namespace MisskeyAPI {
|
|||
/**
|
||||
* Interface
|
||||
*/
|
||||
export interface Interface {}
|
||||
export interface Interface {
|
||||
post<T = any>(path: string, params?: any): Promise<Response<T>>
|
||||
cancel(): void
|
||||
socket(channel: 'user' | 'localTimeline' | 'hybridTimeline' | 'globalTimeline' | 'conversation' | 'list', listId?: string): WebSocket
|
||||
}
|
||||
|
||||
/**
|
||||
* Misskey API client.
|
||||
|
@ -489,7 +493,7 @@ namespace MisskeyAPI {
|
|||
*/
|
||||
public socket(
|
||||
channel: 'user' | 'localTimeline' | 'hybridTimeline' | 'globalTimeline' | 'conversation' | 'list',
|
||||
listId: string | null = null
|
||||
listId?: string
|
||||
): WebSocket {
|
||||
if (!this.accessToken) {
|
||||
throw new Error('accessToken is required')
|
||||
|
|
|
@ -39,7 +39,7 @@ export default class WebSocket extends EventEmitter implements WebSocketInterfac
|
|||
url: string,
|
||||
channel: 'user' | 'localTimeline' | 'hybridTimeline' | 'globalTimeline' | 'conversation' | 'list',
|
||||
accessToken: string,
|
||||
listId: string | null,
|
||||
listId: string | undefined,
|
||||
userAgent: string,
|
||||
proxyConfig: ProxyConfig | false = false
|
||||
) {
|
||||
|
@ -50,7 +50,11 @@ export default class WebSocket extends EventEmitter implements WebSocketInterfac
|
|||
this.headers = {
|
||||
'User-Agent': userAgent
|
||||
}
|
||||
this.listId = listId
|
||||
if (listId === undefined) {
|
||||
this.listId = null
|
||||
} else {
|
||||
this.listId = listId
|
||||
}
|
||||
this.proxyConfig = proxyConfig
|
||||
this._accessToken = accessToken
|
||||
this._reconnectInterval = 10000
|
||||
|
|
|
@ -10,7 +10,7 @@ import { ProxyConfig } from './proxy_config'
|
|||
import OAuth from './oauth'
|
||||
|
||||
export default class Pleroma implements MegalodonInterface {
|
||||
public client: PleromaAPI.Client
|
||||
public client: PleromaAPI.Interface
|
||||
public baseUrl: string
|
||||
|
||||
/**
|
||||
|
|
|
@ -217,13 +217,13 @@ namespace PleromaAPI {
|
|||
* Interface
|
||||
*/
|
||||
export interface Interface {
|
||||
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<{}>>
|
||||
get<T = any>(path: string, params?: any): Promise<Response<T>>
|
||||
put<T = any>(path: string, params?: any): Promise<Response<T>>
|
||||
patch<T = any>(path: string, params?: any): Promise<Response<T>>
|
||||
post<T = any>(path: string, params?: any): Promise<Response<T>>
|
||||
del<T = any>(path: string, params?: any): Promise<Response<T>>
|
||||
cancel(): void
|
||||
socket(path: string, stream: string): WebSocket
|
||||
socket(path: string, stream: string, params?: string): WebSocket
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -479,7 +479,7 @@ namespace PleromaAPI {
|
|||
* @param stream Stream name, please refer: https://git.pleroma.social/pleroma/pleroma/blob/develop/lib/pleroma/web/mastodon_api/mastodon_socket.ex#L19-28
|
||||
* @returns WebSocket, which inherits from EventEmitter
|
||||
*/
|
||||
public socket(path: string, stream: string, params: string | null = null): WebSocket {
|
||||
public socket(path: string, stream: string, params?: string): WebSocket {
|
||||
if (!this.accessToken) {
|
||||
throw new Error('accessToken is required')
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ export default class WebSocket extends EventEmitter implements WebSocketInterfac
|
|||
constructor(
|
||||
url: string,
|
||||
stream: string,
|
||||
params: string | null,
|
||||
params: string | undefined,
|
||||
accessToken: string,
|
||||
userAgent: string,
|
||||
proxyConfig: ProxyConfig | false = false
|
||||
|
@ -46,7 +46,11 @@ export default class WebSocket extends EventEmitter implements WebSocketInterfac
|
|||
super()
|
||||
this.url = url
|
||||
this.stream = stream
|
||||
this.params = params
|
||||
if (params === undefined) {
|
||||
this.params = null
|
||||
} else {
|
||||
this.params = params
|
||||
}
|
||||
this.parser = new Parser()
|
||||
this.headers = {
|
||||
'User-Agent': userAgent
|
||||
|
|
Loading…
Reference in a new issue