Merge pull request #189 from h3poteto/example/generator

Use generator in example
This commit is contained in:
AkiraFukushima 2020-02-11 01:17:15 +09:00 committed by GitHub
commit 7389268267
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 35 additions and 27 deletions

View file

@ -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)

View file

@ -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', {

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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', _ => {

View file

@ -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)

View file

@ -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()

View file

@ -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', _ => {

View file

@ -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)

View file

@ -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 => {

View file

@ -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()

View file

@ -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,