From f60d528dbefbb1f9edfa994d44a009df337a4cdc Mon Sep 17 00:00:00 2001 From: Mauricio Robayo Date: Thu, 23 Jan 2020 16:07:17 +0000 Subject: [PATCH] fix: remove duplicate code on examples --- examples/post-tweet.js | 10 ++++------ examples/search-tweets.js | 7 +++---- examples/upload-tweet.js | 13 +++++-------- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/examples/post-tweet.js b/examples/post-tweet.js index 355cf62..a38c085 100644 --- a/examples/post-tweet.js +++ b/examples/post-tweet.js @@ -1,22 +1,20 @@ /* eslint-disable no-console */ -const twitterize = require('../src') - -// https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-statuses-update.html - // https://developer.twitter.com/en/apps/ -const twit = twitterize({ +const twitterize = require('../src')({ api_key: process.env.TWITTER_API_KEY, api_secret_key: process.env.TWITTER_API_SECRET_KEY, access_token: process.env.TWITTER_ACCESS_TOKEN, access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET, }) +// https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-statuses-update.html + const options = { requestMethod: 'POST', endpoint: '/statuses/update.json', bodyParams: { status: 'Hello World!' }, } -twit(options) +twitterize(options) .then(console.log) .catch(console.log) diff --git a/examples/search-tweets.js b/examples/search-tweets.js index 96cf7f8..eb7a3c9 100644 --- a/examples/search-tweets.js +++ b/examples/search-tweets.js @@ -1,7 +1,6 @@ /* eslint-disable no-console */ -const twitterize = require('../src') - -const twit = twitterize({ +// https://developer.twitter.com/en/apps/ +const twitterize = require('../src')({ api_key: process.env.TWITTER_API_KEY, api_secret_key: process.env.TWITTER_API_SECRET_KEY, access_token: process.env.TWITTER_ACCESS_TOKEN, @@ -14,6 +13,6 @@ const options = { queryParams: { q: 'twitter bot' }, } -twit(options) +twitterize(options) .then(console.log) .catch(console.log) diff --git a/examples/upload-tweet.js b/examples/upload-tweet.js index e3e13b7..a01180e 100644 --- a/examples/upload-tweet.js +++ b/examples/upload-tweet.js @@ -1,24 +1,21 @@ /* eslint-disable no-console */ const fs = require('fs') const path = require('path') -const twitterize = require('../src') - -// https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-statuses-update.html - // https://developer.twitter.com/en/apps/ - -const twit = twitterize({ +const twitterize = require('../src')({ api_key: process.env.TWITTER_API_KEY, api_secret_key: process.env.TWITTER_API_SECRET_KEY, access_token: process.env.TWITTER_ACCESS_TOKEN, access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET, }) +// https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-statuses-update.html + const imagePath = path.join(__dirname, './cat.jpg') const b64content = fs.readFileSync(imagePath, { encoding: 'base64' }) // Image upload -twit({ +twitterize({ requestMethod: 'POST', subdomain: 'upload', endpoint: '/media/upload.json', @@ -26,7 +23,7 @@ twit({ }) .then(data => // Status update - twit({ + twitterize({ requestMethod: 'POST', endpoint: '/statuses/update.json', bodyParams: {