Skip to content

Commit

Permalink
Merge pull request #50 from h3poteto/fix/ua
Browse files Browse the repository at this point in the history
refs #48 Remove User Agent in REST API call because it is guarded
  • Loading branch information
h3poteto authored Jun 12, 2019
2 parents bcb32be + fff02a3 commit e18cbe8
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 25 deletions.
14 changes: 5 additions & 9 deletions example/javascript/timeline.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
const Mastodon = require( '../../lib/mastodon')
const Mastodon = require('../../lib/mastodon')

const BASE_URL = 'https://mastodon.social'
const BASE_URL = 'https://mstdn.jp'

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('/timelines/home')
.then(res => console.log(res.data))
client.get('/timelines/home').then(res => console.log(res.data))
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Mastodon API client for node.js",
"main": "./lib/index.js",
"typings": "./lib/index.d.ts",
"scripts": {
"scripts": {
"build": "tsc -p ./",
"lint": "eslint --ext .js,.ts src",
"test": "echo \"Error: no test specified\" && exit 1"
Expand All @@ -30,7 +30,7 @@
"@types/oauth": "^0.9.0",
"@types/request": "^2.47.0",
"@types/websocket": "0.0.40",
"axios": "^0.18.1",
"axios": "^0.19.0",
"oauth": "^0.9.15",
"request": "^2.87.0",
"typescript": "^3.4.5",
Expand All @@ -39,6 +39,7 @@
"devDependencies": {
"@types/core-js": "^2.5.0",
"@typescript-eslint/eslint-plugin": "^1.9.0",
"@typescript-eslint/parser": "^1.10.2",
"eslint": "^5.16.0",
"eslint-config-prettier": "^4.3.0",
"eslint-config-standard": "^12.0.0",
Expand Down
15 changes: 5 additions & 10 deletions src/mastodon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ export default class Mastodon implements MegalodonInstance {
return axios
.get<T>(this.baseUrl + path, {
headers: {
Authorization: `Bearer ${this.accessToken}`,
'User-Agent': this.userAgent
Authorization: `Bearer ${this.accessToken}`
},
params
})
Expand All @@ -271,8 +270,7 @@ export default class Mastodon implements MegalodonInstance {
return axios
.put<T>(this.baseUrl + path, params, {
headers: {
Authorization: `Bearer ${this.accessToken}`,
'User-Agent': this.userAgent
Authorization: `Bearer ${this.accessToken}`
}
})
.then((resp: AxiosResponse<T>) => {
Expand All @@ -295,8 +293,7 @@ export default class Mastodon implements MegalodonInstance {
return axios
.patch<T>(this.baseUrl + path, params, {
headers: {
Authorization: `Bearer ${this.accessToken}`,
'User-Agent': this.userAgent
Authorization: `Bearer ${this.accessToken}`
}
})
.then((resp: AxiosResponse<T>) => {
Expand All @@ -319,8 +316,7 @@ export default class Mastodon implements MegalodonInstance {
return axios
.post<T>(this.baseUrl + path, params, {
headers: {
Authorization: `Bearer ${this.accessToken}`,
'User-Agent': this.userAgent
Authorization: `Bearer ${this.accessToken}`
}
})
.then((resp: AxiosResponse<T>) => {
Expand All @@ -344,8 +340,7 @@ export default class Mastodon implements MegalodonInstance {
.delete(this.baseUrl + path, {
data: params,
headers: {
Authorization: `Bearer ${this.accessToken}`,
'User-Agent': this.userAgent
Authorization: `Bearer ${this.accessToken}`
}
})
.then((resp: AxiosResponse) => {
Expand Down
39 changes: 35 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
resolved "https://registry.yarnpkg.com/@types/core-js/-/core-js-2.5.0.tgz#35cc282488de6f10af1d92902899a3b8ca3fbc47"
integrity sha512-qjkHL3wF0JMHMqgm/kmL8Pf8rIiqvueEiZ0g6NVTcBX1WN46GWDr+V5z+gsHUeL0n8TfAmXnYmF7ajsxmBp4PQ==

"@types/eslint-visitor-keys@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#1ee30d79544ca84d68d4b3cdb0af4f205663dd2d"
integrity sha512-OCutwjDZ4aFS6PB1UZ988C4YgwlBHJd6wCeQqaLdmadZ/7e+w79+hbMUFC1QXDNCmdyoRfAFdm0RypzwR+Qpag==

"@types/events@*":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@types/events/-/events-1.2.0.tgz#81a6731ce4df43619e5c8c945383b3e62a89ea86"
Expand Down Expand Up @@ -88,6 +93,14 @@
requireindex "^1.2.0"
tsutils "^3.7.0"

"@typescript-eslint/[email protected]":
version "1.10.2"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-1.10.2.tgz#cd548c03fc1a2b3ba5c136d1599001a1ede24215"
integrity sha512-Hf5lYcrnTH5Oc67SRrQUA7KuHErMvCf5RlZsyxXPIT6AXa8fKTyfFO6vaEnUmlz48RpbxO4f0fY3QtWkuHZNjg==
dependencies:
"@typescript-eslint/typescript-estree" "1.10.2"
eslint-scope "^4.0.0"

"@typescript-eslint/[email protected]":
version "1.9.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-1.9.0.tgz#a92777d0c92d7bc8627abd7cdb06cdbcaf2b39e8"
Expand All @@ -105,6 +118,24 @@
eslint-scope "^4.0.0"
eslint-visitor-keys "^1.0.0"

"@typescript-eslint/parser@^1.10.2":
version "1.10.2"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-1.10.2.tgz#36cfe8c6bf1b6c1dd81da56f88c8588f4b1a852b"
integrity sha512-xWDWPfZfV0ENU17ermIUVEVSseBBJxKfqBcRCMZ8nAjJbfA5R7NWMZmFFHYnars5MjK4fPjhu4gwQv526oZIPQ==
dependencies:
"@types/eslint-visitor-keys" "^1.0.0"
"@typescript-eslint/experimental-utils" "1.10.2"
"@typescript-eslint/typescript-estree" "1.10.2"
eslint-visitor-keys "^1.0.0"

"@typescript-eslint/[email protected]":
version "1.10.2"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-1.10.2.tgz#8403585dd74b6cfb6f78aa98b6958de158b5897b"
integrity sha512-Kutjz0i69qraOsWeI8ETqYJ07tRLvD9URmdrMoF10bG8y8ucLmPtSxROvVejWvlJUGl2et/plnMiKRDW+rhEhw==
dependencies:
lodash.unescape "4.0.1"
semver "5.5.0"

"@typescript-eslint/[email protected]":
version "1.9.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-1.9.0.tgz#5d6d49be936e96fb0f859673480f89b070a5dd9b"
Expand Down Expand Up @@ -222,10 +253,10 @@ aws4@^1.8.0:
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.8.0.tgz#f0e003d9ca9e7f59c7a508945d7b2ef9a04a542f"
integrity sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==

axios@^0.18.1:
version "0.18.1"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.18.1.tgz#ff3f0de2e7b5d180e757ad98000f1081b87bcea3"
integrity sha512-0BfJq4NSfQXd+SkFdrvFbG7addhYSBA2mQwISr46pD6E5iqkWg02RAs8vyTT/j0RTnoYmeXauBuSv1qKwR179g==
axios@^0.19.0:
version "0.19.0"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.0.tgz#8e09bff3d9122e133f7b8101c8fbdd00ed3d2ab8"
integrity sha512-1uvKqKQta3KBxIz14F2v06AEHZ/dIoeKfbTRkK1E5oqjDnuEerLmYTgJB5AiQZHJcljpg1TuRzdjDR06qNk0DQ==
dependencies:
follow-redirects "1.5.10"
is-buffer "^2.0.2"
Expand Down

0 comments on commit e18cbe8

Please sign in to comment.