refs #53 Fix compile target

This commit is contained in:
AkiraFukushima 2019-08-24 21:33:30 +09:00
parent 7dfa9e4704
commit 8cb14e0323
16 changed files with 88 additions and 81 deletions

View file

@ -1,5 +1,5 @@
const readline = require('readline')
const Mastodon = require( '../../lib/mastodon')
const Mastodon = require('../../lib/src/mastodon')
const rl = readline.createInterface({
input: process.stdin,
@ -7,30 +7,36 @@ const rl = readline.createInterface({
})
const SCOPES = 'read write follow'
const BASE_URL = 'https://pleroma.io'
const BASE_URL = 'https://mastodon.social'
let clientId
let clientSecret
Mastodon.registerApp('Test App', {
scopes: SCOPES
}, BASE_URL).then(appData => {
clientId = appData.clientId
clientSecret = appData.clientSecret
console.log('\nclient_id:')
console.log(clientId)
console.log('\nclient_secret:')
console.log(clientSecret)
console.log('\nAuthorization URL is generated.')
console.log(appData.url)
console.log()
return new Promise(resolve => {
rl.question('Enter the authorization code from website: ', code => {
resolve(code)
rl.close()
Mastodon.registerApp(
'Test App',
{
scopes: SCOPES
},
BASE_URL
)
.then(appData => {
clientId = appData.clientId
clientSecret = appData.clientSecret
console.log('\nclient_id:')
console.log(clientId)
console.log('\nclient_secret:')
console.log(clientSecret)
console.log('\nAuthorization URL is generated.')
console.log(appData.url)
console.log()
return new Promise(resolve => {
rl.question('Enter the authorization code from website: ', code => {
resolve(code)
rl.close()
})
})
})
}).then(code => Mastodon.fetchAccessToken(clientId, clientSecret, code, BASE_URL))
.then(code => Mastodon.fetchAccessToken(clientId, clientSecret, code, BASE_URL))
.then(tokenData => {
console.log('\naccess_token:')
console.log(tokenData.accessToken)
@ -39,4 +45,3 @@ Mastodon.registerApp('Test App', {
console.log()
})
.catch(err => console.error(err))

View file

@ -1,16 +1,12 @@
const Mastodon = require( '../../lib/mastodon')
const Mastodon = require('../../lib/src/mastodon')
const BASE_URL = 'https://mstdn.jp'
const BASE_URL = 'https://mastodon.social'
const access_token = '...'
const access_token = process.env.MASTODON_ACCESS_TOKEN
const client = new Mastodon(
access_token,
BASE_URL + '/api/v1'
)
const client = new Mastodon(access_token, BASE_URL + '/api/v1')
client.get('/favourites')
.then((res) => {
console.log(res.headers)
console.log(res.data)
})
client.get('/favourites').then(res => {
console.log(res.headers)
console.log(res.data)
})

View file

@ -1,7 +1,7 @@
// Please use this function after authorization.js
// Now mastodon and pleroma don't have refersh token method.
// So this example is failed.
const Mastodon = require( '../../lib/mastodon')
const Mastodon = require('../../lib/src/mastodon')
const BASE_URL = 'https://pleroma.io'

View file

@ -1,6 +1,6 @@
const Mastodon = require('../../lib/mastodon')
const Mastodon = require('../../lib/src/mastodon')
const BASE_URL = 'https://mstdn.jp'
const BASE_URL = 'https://mastodon.social'
const access_token = process.env.MASTODON_ACCESS_TOKEN

View file

@ -1,6 +1,6 @@
const Mastodon = require('../../lib/mastodon')
const Mastodon = require('../../lib/src/mastodon')
const BASE_URL = 'https://mstdn.jp'
const BASE_URL = 'https://mastodon.social'
const access_token = process.env.MASTODON_ACCESS_TOKEN

View file

@ -1,5 +1,5 @@
const readline = require('readline')
const Mastodon = require('../../lib/mastodon')
const Mastodon = require('../../lib/src/mastodon')
const rl = readline.createInterface({
input: process.stdin,
@ -8,17 +8,15 @@ const rl = readline.createInterface({
const BASE_URL = 'https://mastodon.social'
const access_token = '...'
const access_token = process.env.MASTODON_ACCESS_TOKEN
const client = new Mastodon(
access_token,
BASE_URL + '/api/v1'
)
const client = new Mastodon(access_token, BASE_URL + '/api/v1')
new Promise(resolve => {
rl.question('Toot: ', status => {
client.post('/statuses', {
status: status
})
client
.post('/statuses', {
status: status
})
.then(res => {
console.log(res)
rl.close()

View file

@ -1,4 +1,4 @@
const Mastodon = require('../../lib/mastodon')
const Mastodon = require('../../lib/src/mastodon')
const BASE_URL = 'wss://pleroma.io'

View file

@ -1,16 +1,18 @@
import Mastodon, { Status, Response } from 'megalodon'
const BASE_URL: string = 'https://mstdn.jp'
declare var process: {
env: {
MASTODON_ACCESS_TOKEN: string
}
}
const access_token: string = '...'
const BASE_URL: string = 'https://mastodon.social'
const client = new Mastodon(
access_token,
BASE_URL + '/api/v1'
)
const access_token: string = process.env.MASTODON_ACCESS_TOKEN
client.get<[Status]>('/favourites')
.then((res: Response<[Status]>) => {
console.log(res.headers)
console.log(res.data)
})
const client = new Mastodon(access_token, BASE_URL + '/api/v1')
client.get<[Status]>('/favourites').then((res: Response<[Status]>) => {
console.log(res.headers)
console.log(res.data)
})

View file

@ -1,6 +1,6 @@
import Mastodon, { Instance } from 'megalodon'
const BASE_URL: string = 'http://mstdn.jp'
const BASE_URL: string = 'http://mastodon.social'
Mastodon.get<Instance>('/api/v1/instance', {}, BASE_URL).then(res => {
console.log(res)

View file

@ -1,13 +1,16 @@
import Mastodon, { Status, Notification, StreamListener } from 'megalodon'
declare var process: {
env: {
MASTODON_ACCESS_TOKEN: string
}
}
const BASE_URL: string = 'https://mastodon.social'
const access_token: string = '...'
const access_token: string = process.env.MASTODON_ACCESS_TOKEN
const client = new Mastodon(
access_token,
BASE_URL + '/api/v1'
)
const client = new Mastodon(access_token, BASE_URL + '/api/v1')
const stream: StreamListener = client.stream('/streaming/public')
stream.on('connect', _ => {

View file

@ -1,8 +1,14 @@
import Mastodon, { Status, Response } from 'megalodon'
declare var process: {
env: {
MASTODON_ACCESS_TOKEN: string
}
}
const BASE_URL: string = 'https://mastodon.social'
const access_token: string = '...'
const access_token: string = process.env.MASTODON_ACCESS_TOKEN
const client = new Mastodon(access_token, BASE_URL + '/api/v1')

View file

@ -6,19 +6,17 @@ const rl: readline.ReadLine = readline.createInterface({
output: process.stdout
})
const BASE_URL: string = 'https://mastodon.social'
const BASE_URL: string = 'https://pleroma.io'
const access_token: string = '...'
const access_token: string = process.env.PLEROMA_ACCESS_TOKEN as string
const client = new Mastodon(
access_token,
BASE_URL + '/api/v1'
)
const client = new Mastodon(access_token, BASE_URL + '/api/v1')
new Promise(resolve => {
rl.question('Toot: ', status => {
client.post<Status>('/statuses', {
status: status
})
client
.post<Status>('/statuses', {
status: status
})
.then((res: Response<Status>) => {
console.log(res)
rl.close()

View file

@ -2,12 +2,11 @@ import Mastodon, { Status, Notification, WebSocket } from 'megalodon'
declare var process: {
env: {
PLEROMA_HOST: string
PLEROMA_ACCESS_TOKEN: string
}
}
const BASE_URL: string = process.env.PLEROMA_HOST
const BASE_URL: string = 'wss://pleroma.io'
const access_token: string = process.env.PLEROMA_ACCESS_TOKEN

View file

@ -282,7 +282,7 @@ jsprim@^1.2.2:
verror "1.10.0"
"megalodon@file:../..":
version "0.8.2"
version "0.9.0"
dependencies:
"@types/oauth" "^0.9.0"
"@types/request" "^2.47.0"

View file

@ -2,8 +2,8 @@
"name": "megalodon",
"version": "0.9.0",
"description": "Mastodon API client for node.js",
"main": "./lib/index.js",
"typings": "./lib/index.d.ts",
"main": "./lib/src/index.js",
"typings": "./lib/src/index.d.ts",
"scripts": {
"build": "tsc -p ./",
"lint": "eslint --ext .js,.ts src",

View file

@ -12,7 +12,7 @@
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./lib", /* Redirect output structure to the directory. */
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
"rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
"removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
@ -59,6 +59,6 @@
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
},
"include": ["src/*", "test/*"],
"include": ["./src", "./test"],
"exclude": ["node_modules", "example"]
}