Skip to content

Commit

Permalink
refs #53 Fix compile target
Browse files Browse the repository at this point in the history
  • Loading branch information
h3poteto committed Aug 24, 2019
1 parent 7dfa9e4 commit 8cb14e0
Show file tree
Hide file tree
Showing 16 changed files with 88 additions and 81 deletions.
45 changes: 25 additions & 20 deletions example/javascript/authorization.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,42 @@
const readline = require('readline')
const Mastodon = require( '../../lib/mastodon')
const Mastodon = require('../../lib/src/mastodon')

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})

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)
Expand All @@ -39,4 +45,3 @@ Mastodon.registerApp('Test App', {
console.log()
})
.catch(err => console.error(err))

20 changes: 8 additions & 12 deletions example/javascript/favourite.js
Original file line number Diff line number Diff line change
@@ -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)
})
2 changes: 1 addition & 1 deletion example/javascript/refresh.js
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
4 changes: 2 additions & 2 deletions example/javascript/streaming.js
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions example/javascript/timeline.js
Original file line number Diff line number Diff line change
@@ -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

Expand Down
16 changes: 7 additions & 9 deletions example/javascript/toot.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion example/javascript/web_socket.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const Mastodon = require('../../lib/mastodon')
const Mastodon = require('../../lib/src/mastodon')

const BASE_URL = 'wss://pleroma.io'

Expand Down
24 changes: 13 additions & 11 deletions example/typescript/favourite.ts
Original file line number Diff line number Diff line change
@@ -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)
})
2 changes: 1 addition & 1 deletion example/typescript/instance.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
13 changes: 8 additions & 5 deletions example/typescript/streaming.ts
Original file line number Diff line number Diff line change
@@ -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', _ => {
Expand Down
8 changes: 7 additions & 1 deletion example/typescript/timeline.ts
Original file line number Diff line number Diff line change
@@ -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')

Expand Down
16 changes: 7 additions & 9 deletions example/typescript/toot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions example/typescript/web_socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion example/typescript/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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"]
}

0 comments on commit 8cb14e0

Please sign in to comment.