Skip to content
This repository has been archived by the owner on Jul 7, 2021. It is now read-only.

Commit

Permalink
fix: remove duplicate code on examples
Browse files Browse the repository at this point in the history
  • Loading branch information
MauricioRobayo committed Jan 23, 2020
1 parent 96a9079 commit f60d528
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
10 changes: 4 additions & 6 deletions examples/post-tweet.js
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 3 additions & 4 deletions examples/search-tweets.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -14,6 +13,6 @@ const options = {
queryParams: { q: 'twitter bot' },
}

twit(options)
twitterize(options)
.then(console.log)
.catch(console.log)
13 changes: 5 additions & 8 deletions examples/upload-tweet.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
/* 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',
bodyParams: { media_data: b64content },
})
.then(data =>
// Status update
twit({
twitterize({
requestMethod: 'POST',
endpoint: '/statuses/update.json',
bodyParams: {
Expand Down

0 comments on commit f60d528

Please sign in to comment.