Permalink
Cannot retrieve contributors at this time
Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign up
Fetching contributors…
| /* globals OAuth warriorBase64String yellowDuckBase64String */ | |
| /* eslint func-names: "off" */ | |
| /* eslint no-console: "off" */ | |
| var tweet; | |
| var twitterChunkedUpload; | |
| var twitterLogin; | |
| var twitterSimpleUpload; | |
| // Image Sizes | |
| var warriorFileSize = 3999; | |
| var yellowDuckFileSize = 9073; | |
| // Warrior Functions | |
| var warriorChunckedUploadError; // eslint-disable-line no-unused-vars | |
| var warriorChunckedUploadSuccess; // eslint-disable-line no-unused-vars | |
| var warriorSingleUpload; // eslint-disable-line no-unused-vars | |
| // Yellow Duck Functions | |
| var yellowDuckChunckedUploadError; // eslint-disable-line no-unused-vars | |
| var yellowDuckChunckedUploadSuccess; // eslint-disable-line no-unused-vars | |
| var yellowDuckSingleUpload; // eslint-disable-line no-unused-vars | |
| twitterLogin = function () { | |
| var oAuthRequest; | |
| OAuth.initialize('bbii4DU7QS7yQZH55rqC0acFz0s'); | |
| oAuthRequest = OAuth.create('twitter'); | |
| if (!oAuthRequest) { | |
| OAuth.popup( | |
| 'twitter', { cache: true } | |
| ).done(function (oauthResult) { | |
| return oauthResult.get( | |
| 'https://api.twitter.com/1.1/account/verify_credentials.json' | |
| ); | |
| }); | |
| return OAuth.create('twitter'); | |
| } | |
| return oAuthRequest; | |
| }; | |
| tweet = function (oAuthRequest, status, mediaIdString) { | |
| oAuthRequest.post( | |
| '/1.1/statuses/update.json', | |
| { data: { | |
| status: status, | |
| media_ids: mediaIdString | |
| } } | |
| ).done(function (postResponse) { | |
| console.log('Twitter created tweet with media'); | |
| console.log(postResponse); | |
| }).fail(function (err) { | |
| console.log('Twitter could not create tweet'); | |
| console.log(err); | |
| }); | |
| }; | |
| twitterSimpleUpload = function (base64ImageString, fileSize) { | |
| var oAuthRequest = twitterLogin(); | |
| var mediaIdString; | |
| oAuthRequest.post( | |
| 'https://upload.twitter.com/1.1/media/upload.json', | |
| { data: { | |
| command: 'INIT', | |
| media_type: 'image/jpeg', | |
| total_bytes: fileSize | |
| } } | |
| ).done(function (twitterResponse) { | |
| // INIT successfully sent | |
| // upload the one and only chunk to twitter | |
| mediaIdString = twitterResponse.media_id_string; | |
| oAuthRequest.post( | |
| 'https://upload.twitter.com/1.1/media/upload.json', | |
| { | |
| headers: { 'Content-Transfer-Encoding': 'base64' }, | |
| data: { | |
| command: 'APPEND', | |
| media_data: base64ImageString, | |
| media_id: mediaIdString, | |
| segment_index: 0 | |
| } | |
| } | |
| ).done(function () { | |
| // APPEND successful | |
| oAuthRequest.post( | |
| 'https://upload.twitter.com/1.1/media/upload.json', | |
| { data: { | |
| command: 'FINALIZE', | |
| media_id: mediaIdString | |
| } } | |
| ).done(function () { | |
| // FINALIZE successful | |
| tweet(oAuthRequest, 'Single Append!', mediaIdString); | |
| }).fail(function (err) { | |
| console.log('FINALIZE Failed'); | |
| console.log(err); | |
| }); | |
| }).fail(function (err) { | |
| console.log('APPEND Failed'); | |
| console.log(err); | |
| }); | |
| }).fail(function (err) { | |
| console.log('INIT Failed'); | |
| console.log(err); | |
| }); | |
| }; | |
| twitterChunkedUpload = function (base64ImageString, fileSize, chunkSize) { | |
| var mediaIdString; | |
| var oAuthRequest = twitterLogin(); | |
| oAuthRequest.post( | |
| 'https://upload.twitter.com/1.1/media/upload.json', | |
| { data: { | |
| command: 'INIT', | |
| media_type: 'image/jpeg', | |
| total_bytes: fileSize | |
| } } | |
| ).done(function (twitterResponse) { | |
| // INIT successfully sent | |
| // upload the one and only chunk to twitter | |
| mediaIdString = twitterResponse.media_id_string; | |
| oAuthRequest.post( | |
| 'https://upload.twitter.com/1.1/media/upload.json', | |
| { | |
| headers: { 'Content-Transfer-Encoding': 'base64' }, | |
| data: { | |
| command: 'APPEND', | |
| media_data: base64ImageString.slice(0, chunkSize), | |
| media_id: mediaIdString, | |
| segment_index: 0 | |
| } | |
| } | |
| ).done(function () { | |
| // first APPEND successful | |
| oAuthRequest.post( | |
| 'https://upload.twitter.com/1.1/media/upload.json', | |
| { | |
| headers: { 'Content-Transfer-Encoding': 'base64' }, | |
| data: { | |
| command: 'APPEND', | |
| media_data: base64ImageString.slice( | |
| chunkSize, | |
| base64ImageString.length | |
| ), | |
| media_id: mediaIdString, | |
| segment_index: 1 | |
| } | |
| } | |
| ).done(function () { | |
| // second APPEND successful | |
| oAuthRequest.post( | |
| 'https://upload.twitter.com/1.1/media/upload.json', | |
| { data: { | |
| command: 'FINALIZE', | |
| media_id: mediaIdString | |
| } } | |
| ).done(function () { | |
| // FINALIZE successful | |
| tweet( | |
| oAuthRequest, | |
| 'Chunked (size ' + chunkSize + ') Append!', | |
| mediaIdString | |
| ); | |
| }).fail(function (err) { | |
| console.log('FINALIZE Failed'); | |
| console.log(err); | |
| }); | |
| }).fail(function (err) { | |
| console.log('second APPEND Failed'); | |
| console.log(err); | |
| }); | |
| }).fail(function (err) { | |
| console.log('first APPEND Failed'); | |
| console.log(err); | |
| }); | |
| }).fail(function (err) { | |
| console.log('INIT Failed'); | |
| console.log(err); | |
| }); | |
| }; | |
| warriorSingleUpload = function () { | |
| twitterSimpleUpload(warriorBase64String, warriorFileSize); | |
| }; | |
| warriorChunckedUploadError = function () { | |
| twitterChunkedUpload(warriorBase64String, warriorFileSize, 2666); | |
| }; | |
| warriorChunckedUploadSuccess = function () { | |
| twitterChunkedUpload(warriorBase64String, warriorFileSize, 2000); | |
| }; | |
| yellowDuckSingleUpload = function () { | |
| twitterSimpleUpload(yellowDuckBase64String, yellowDuckFileSize); | |
| }; | |
| yellowDuckChunckedUploadError = function () { | |
| twitterChunkedUpload(yellowDuckBase64String, yellowDuckFileSize, 6050); | |
| }; | |
| yellowDuckChunckedUploadSuccess = function () { | |
| twitterChunkedUpload(yellowDuckBase64String, yellowDuckFileSize, 6000); | |
| }; |