Merge pull request #189 from h3poteto/example/generator
Use generator in example
This commit is contained in:
commit
7389268267
|
@ -1,9 +1,9 @@
|
|||
import { Mastodon, Entity, Response } from 'megalodon'
|
||||
import generator, { Entity, Response } from 'megalodon'
|
||||
|
||||
const BASE_URL: string = 'http://mastodon.social'
|
||||
console.log('start')
|
||||
|
||||
const client = new Mastodon(BASE_URL)
|
||||
const client = generator('mastodon', BASE_URL)
|
||||
|
||||
client.getInstance().then((res: Response<Entity.Instance>) => {
|
||||
console.log(res)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import * as readline from 'readline'
|
||||
import { Mastodon, OAuth } from 'megalodon'
|
||||
import generator, { OAuth } from 'megalodon'
|
||||
|
||||
const rl: readline.ReadLine = readline.createInterface({
|
||||
input: process.stdin,
|
||||
|
@ -12,7 +12,7 @@ const BASE_URL: string = 'https://mastodon.social'
|
|||
let clientId: string
|
||||
let clientSecret: string
|
||||
|
||||
const client = new Mastodon(BASE_URL)
|
||||
const client = generator('mastodon', BASE_URL)
|
||||
|
||||
client
|
||||
.registerApp('Test App', {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { Mastodon, Response, Entity, isCancel } from 'megalodon'
|
||||
import generator, { Response, Entity, isCancel } from 'megalodon'
|
||||
|
||||
const BASE_URL: string = 'https://pleroma.io'
|
||||
|
||||
const access_token: string = process.env.PLEROMA_ACCESS_TOKEN!
|
||||
|
||||
const client = new Mastodon(BASE_URL, access_token)
|
||||
const client = generator('pleroma', BASE_URL, access_token)
|
||||
|
||||
client
|
||||
.search('whalebird', 'hashtags', null, null, null, true)
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import { Mastodon, Entity, Response } from 'megalodon'
|
||||
import generator, { Entity, Response } from 'megalodon'
|
||||
|
||||
declare var process: {
|
||||
env: {
|
||||
MASTODON_ACCESS_TOKEN: string
|
||||
SNS: 'mastodon' | 'pleroma'
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,7 +11,7 @@ const BASE_URL: string = 'https://mastodon.social'
|
|||
|
||||
const access_token: string = process.env.MASTODON_ACCESS_TOKEN
|
||||
|
||||
const client = new Mastodon(BASE_URL, access_token)
|
||||
const client = generator(process.env.SNS, BASE_URL, access_token)
|
||||
|
||||
client.getFavourites().then((res: Response<Array<Entity.Status>>) => {
|
||||
console.log(res.headers)
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { Mastodon, Entity, Response } from 'megalodon'
|
||||
import generator, { Entity, Response } from 'megalodon'
|
||||
|
||||
const BASE_URL: string = 'http://mastodon.social'
|
||||
|
||||
const client = new Mastodon(BASE_URL)
|
||||
const client = generator('mastodon', BASE_URL)
|
||||
|
||||
client.getInstance().then((res: Response<Entity.Instance>) => {
|
||||
console.log(res)
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
import { Mastodon, Entity, ProxyConfig, Response } from 'megalodon'
|
||||
import generator, { Entity, ProxyConfig, Response } from 'megalodon'
|
||||
|
||||
declare var process: {
|
||||
env: {
|
||||
PROXY_HOST: string
|
||||
PROXY_PORT: number
|
||||
PROXY_PROTOCOL: 'http' | 'https' | 'socks4' | 'socks4a' | 'socks5' | 'socks5h' | 'socks'
|
||||
SNS: 'mastodon' | 'pleroma'
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,7 +17,7 @@ const proxy: ProxyConfig = {
|
|||
protocol: process.env.PROXY_PROTOCOL
|
||||
}
|
||||
|
||||
const client = new Mastodon(BASE_URL, '', null, proxy)
|
||||
const client = generator(process.env.SNS, BASE_URL, '', null, proxy)
|
||||
|
||||
client.getInstance().then((res: Response<Entity.Instance>) => {
|
||||
console.log(res)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Mastodon, Entity, StreamListener, ProxyConfig } from 'megalodon'
|
||||
import generator, { Entity, StreamListener, ProxyConfig } from 'megalodon'
|
||||
|
||||
declare var process: {
|
||||
env: {
|
||||
|
@ -6,6 +6,7 @@ declare var process: {
|
|||
PROXY_HOST: string
|
||||
PROXY_PORT: number
|
||||
PROXY_PROTOCOL: 'http' | 'https' | 'socks4' | 'socks4a' | 'socks5' | 'socks5h' | 'socks'
|
||||
SNS: 'mastodon' | 'pleroma'
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,7 +20,7 @@ const proxy: ProxyConfig = {
|
|||
protocol: process.env.PROXY_PROTOCOL
|
||||
}
|
||||
|
||||
const client = new Mastodon(BASE_URL, access_token, null, proxy)
|
||||
const client = generator(process.env.SNS, BASE_URL, access_token, null, proxy)
|
||||
|
||||
const stream: StreamListener = client.userStream()
|
||||
stream.on('connect', _ => {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Mastodon, Entity, Response, ProxyConfig } from 'megalodon'
|
||||
import generator, { Entity, Response, ProxyConfig } from 'megalodon'
|
||||
|
||||
declare var process: {
|
||||
env: {
|
||||
|
@ -6,6 +6,7 @@ declare var process: {
|
|||
PROXY_HOST: string
|
||||
PROXY_PORT: number
|
||||
PROXY_PROTOCOL: 'http' | 'https' | 'socks4' | 'socks4a' | 'socks5' | 'socks5h' | 'socks'
|
||||
SNS: 'mastodon' | 'pleroma'
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,7 +20,7 @@ const proxy: ProxyConfig = {
|
|||
protocol: process.env.PROXY_PROTOCOL
|
||||
}
|
||||
|
||||
const client = new Mastodon(BASE_URL, access_token, null, proxy)
|
||||
const client = generator(process.env.SNS, BASE_URL, access_token, null, proxy)
|
||||
|
||||
client.getPublicTimeline().then((resp: Response<Array<Entity.Status>>) => {
|
||||
console.log(resp.data)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Mastodon, Entity, WebSocket, ProxyConfig } from 'megalodon'
|
||||
import generator, { Entity, WebSocket, ProxyConfig } from 'megalodon'
|
||||
import log4js from 'log4js'
|
||||
|
||||
declare var process: {
|
||||
|
@ -8,6 +8,7 @@ declare var process: {
|
|||
PROXY_HOST: string
|
||||
PROXY_PORT: number
|
||||
PROXY_PROTOCOL: 'http' | 'https' | 'socks4' | 'socks4a' | 'socks5' | 'socks5h' | 'socks'
|
||||
SNS: 'mastodon' | 'pleroma'
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,7 +22,7 @@ const proxy: ProxyConfig = {
|
|||
protocol: process.env.PROXY_PROTOCOL
|
||||
}
|
||||
|
||||
const client = new Mastodon(BASE_URL, access_token, null, proxy)
|
||||
const client = generator(process.env.SNS, BASE_URL, access_token, null, proxy)
|
||||
|
||||
const stream: WebSocket = client.userSocket()
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import { Mastodon, Entity, StreamListener } from 'megalodon'
|
||||
import generator, { Entity, StreamListener } from 'megalodon'
|
||||
|
||||
declare var process: {
|
||||
env: {
|
||||
MASTODON_ACCESS_TOKEN: string
|
||||
SNS: 'mastodon' | 'pleroma'
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,7 +11,7 @@ const BASE_URL: string = 'https://mastodon.social'
|
|||
|
||||
const access_token: string = process.env.MASTODON_ACCESS_TOKEN
|
||||
|
||||
const client = new Mastodon(BASE_URL, access_token)
|
||||
const client = generator(process.env.SNS, BASE_URL, access_token)
|
||||
|
||||
const stream: StreamListener = client.publicStream()
|
||||
stream.on('connect', _ => {
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import { Mastodon, Entity, Response } from 'megalodon'
|
||||
import generator, { MegalodonInterface, Entity, Response } from 'megalodon'
|
||||
|
||||
declare var process: {
|
||||
env: {
|
||||
MASTODON_ACCESS_TOKEN: string
|
||||
SNS: 'mastodon' | 'pleroma'
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,7 +11,7 @@ const BASE_URL: string = 'https://mastodon.social'
|
|||
|
||||
const access_token: string = process.env.MASTODON_ACCESS_TOKEN
|
||||
|
||||
const client = new Mastodon(BASE_URL, access_token)
|
||||
const client: MegalodonInterface = generator(process.env.SNS, BASE_URL, access_token)
|
||||
|
||||
client.getPublicTimeline().then((resp: Response<Array<Entity.Status>>) => {
|
||||
console.log(resp.data)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import * as readline from 'readline'
|
||||
import { Mastodon, Entity, Response } from 'megalodon'
|
||||
import generator, { Entity, Response } from 'megalodon'
|
||||
|
||||
const rl: readline.ReadLine = readline.createInterface({
|
||||
input: process.stdin,
|
||||
|
@ -10,7 +10,7 @@ const BASE_URL: string = 'https://pleroma.io'
|
|||
|
||||
const access_token: string = process.env.PLEROMA_ACCESS_TOKEN as string
|
||||
|
||||
const client = new Mastodon(BASE_URL, access_token)
|
||||
const client = generator('pleroma', BASE_URL, access_token)
|
||||
|
||||
new Promise(resolve => {
|
||||
rl.question('Toot: ', status => {
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
import { Mastodon, Entity, WebSocket } from 'megalodon'
|
||||
import generator, { Entity, WebSocket } from 'megalodon'
|
||||
import log4js from 'log4js'
|
||||
|
||||
declare var process: {
|
||||
env: {
|
||||
PLEROMA_ACCESS_TOKEN: string
|
||||
MASTODON_ACCESS_TOKEN: string
|
||||
SNS: 'mastodon' | 'pleroma'
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,7 +13,7 @@ const BASE_URL: string = 'wss://pleroma.io'
|
|||
|
||||
const access_token: string = process.env.PLEROMA_ACCESS_TOKEN
|
||||
|
||||
const client = new Mastodon(BASE_URL, access_token)
|
||||
const client = generator(process.env.SNS, BASE_URL, access_token)
|
||||
|
||||
const stream: WebSocket = client.userSocket()
|
||||
|
||||
|
|
|
@ -561,7 +561,7 @@ export interface MegalodonInterface {
|
|||
*/
|
||||
postStatus(
|
||||
status: string,
|
||||
media_ids: Array<string>,
|
||||
media_ids?: Array<string>,
|
||||
poll?: { options: Array<string>; expires_in: number; multiple?: boolean; hide_totals?: boolean } | null,
|
||||
in_reply_to_id?: string | null,
|
||||
sensitive?: boolean | null,
|
||||
|
|
Loading…
Reference in a new issue