From a7a8e1f29996dabf010a0881f4a318503b73af70 Mon Sep 17 00:00:00 2001 From: Jonathan Hornung Date: Sun, 10 Jan 2016 11:26:48 +0100 Subject: [PATCH] small updates --- LICENSE | 2 +- README.md | 2 +- bower.json | 4 +- dist/aping-plugin-codebird.js | 82 +++++++++++++++---------------- dist/aping-plugin-codebird.min.js | 6 +-- package.json | 8 +-- src/aping-codebird-directive.js | 26 +++++----- src/aping-codebird-helper.js | 50 +++++++++---------- 8 files changed, 90 insertions(+), 90 deletions(-) diff --git a/LICENSE b/LICENSE index 3e2a740..935d635 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015 Jonathan Hornung +Copyright (c) 2016 Jonathan Hornung Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 26dfa0f..b0ef081 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ var app = angular.module('app', ['jtt_aping', 'jtt_aping_codebird']); ``` ### IV. Add the plugin -Add the plugin's directive `aping-codebird="[]"` to your apiNG directive and configure your requests [configure your requests](#ii-requests) +Add the plugin's directive `aping-codebird="[]"` to your apiNG directive and [configure your requests](#ii-requests) ```html " ], - "version": "0.7.0", - "description": "twitter plugin for apiNG", + "version": "0.7.5", + "description": "Twitter plugin for apiNG", "main": "dist/aping-plugin-codebird.min.js", "moduleType": [], "keywords": [ diff --git a/dist/aping-plugin-codebird.js b/dist/aping-plugin-codebird.js index 14e44da..3b502be 100644 --- a/dist/aping-plugin-codebird.js +++ b/dist/aping-plugin-codebird.js @@ -1,8 +1,8 @@ /** @name: aping-plugin-codebird - @version: 0.7.0 (09-01-2016) - @author: Jonathan Hornung - @url: https://github.com/JohnnyTheTank/apiNG-plugin-codebird#readme + @version: 0.7.5 (10-01-2016) + @author: Jonathan Hornung + @url: https://github.com/JohnnyTheTank/apiNG-plugin-codebird @license: MIT */ "use strict"; @@ -28,9 +28,9 @@ var jjtApingCodebird = angular.module("jtt_aping_codebird", []) //create helperObject for helper function call var helperObject = { model: appSettings.model, - showAvatar : request.showAvatar || false, + showAvatar: request.showAvatar || false, }; - if(typeof appSettings.getNativeData !== "undefined") { + if (typeof appSettings.getNativeData !== "undefined") { helperObject.getNativeData = appSettings.getNativeData; } else { helperObject.getNativeData = false; @@ -38,36 +38,36 @@ var jjtApingCodebird = angular.module("jtt_aping_codebird", []) //create requestObject for api request call var requestObject = {}; - if(typeof request.items !== "undefined") { + if (typeof request.items !== "undefined") { requestObject.count = request.items; } else { requestObject.count = appSettings.items; } - if(requestObject.count == 0) { + if (requestObject.count == 0) { return false; } // -1 is "no explicit limit". same for NaN value - if(requestObject.count < 0 || isNaN(requestObject.count)) { + if (requestObject.count < 0 || isNaN(requestObject.count)) { requestObject.count = undefined; } // the api has a limit of 100 items per request - if(requestObject.count > 100) { + if (requestObject.count > 100) { requestObject.count = 100; } - if(request.search) { + if (request.search) { // https://dev.twitter.com/rest/reference/get/search/tweets requestObject.q = request.search; requestObject.result_type = request.result_type || "mixed"; - if(typeof request.lat !== "undefined" && typeof request.lng !== "undefined") { - requestObject.geocode = request.lat+","+request.lng+","+(request.distance || "1" )+"km"; + if (typeof request.lat !== "undefined" && typeof request.lng !== "undefined") { + requestObject.geocode = request.lat + "," + request.lng + "," + (request.distance || "1" ) + "km"; } - if(typeof request.language !== "undefined") { + if (typeof request.language !== "undefined") { requestObject.lang = request.language; } @@ -81,17 +81,17 @@ var jjtApingCodebird = angular.module("jtt_aping_codebird", []) true ); - } else if(request.user) { + } else if (request.user) { // https://dev.twitter.com/rest/reference/get/statuses/user_timeline requestObject.screen_name = request.user; requestObject.contributor_details = true; - if(request.exclude_replies === true || request.exclude_replies === "true"){ + if (request.exclude_replies === true || request.exclude_replies === "true") { requestObject.exclude_replies = true; } - if(request.include_rts === false || request.include_rts === "false"){ + if (request.include_rts === false || request.include_rts === "false") { requestObject.include_rts = false; } @@ -124,22 +124,22 @@ jjtApingCodebird.service('apingCodebirdHelper', ['apingModels', 'apingTimeHelper return _smallImageUrl.replace("_normal", ""); }; this.getImageUrlFromMediaObject = function (_item) { - if(_item) { - if(_item.media_url_https) { + if (_item) { + if (_item.media_url_https) { return this.getBigImageUrlFromSmallImageUrl(_item.media_url_https); } - if(_item.media_url) { + if (_item.media_url) { return this.getBigImageUrlFromSmallImageUrl(_item.media_url); } } return undefined; }; this.getImageUrlFromUserObject = function (_item) { - if(_item) { - if(_item.profile_image_url_https) { + if (_item) { + if (_item.profile_image_url_https) { return this.getBigImageUrlFromSmallImageUrl(_item.profile_image_url_https); } - if(_item.profile_image_url) { + if (_item.profile_image_url) { return this.getBigImageUrlFromSmallImageUrl(_item.profile_image_url); } } @@ -161,25 +161,25 @@ jjtApingCodebird.service('apingCodebirdHelper', ['apingModels', 'apingTimeHelper var baseUrl = this.getImageUrlFromMediaObject(_item); - if(_item.sizes) { - if(typeof _item.sizes['small'] !== "undefined") { - returnObject.thumb_url = baseUrl+":small"; + if (_item.sizes) { + if (typeof _item.sizes['small'] !== "undefined") { + returnObject.thumb_url = baseUrl + ":small"; returnObject.thumb_width = _item.sizes['small'].w || undefined; returnObject.thumb_height = _item.sizes['small'].h || undefined; } else { returnObject.thumb_url = baseUrl; } - if(typeof _item.sizes['medium'] !== "undefined") { - returnObject.img_url = baseUrl+":medium"; + if (typeof _item.sizes['medium'] !== "undefined") { + returnObject.img_url = baseUrl + ":medium"; returnObject.img_width = _item.sizes['medium'].w || undefined; returnObject.img_height = _item.sizes['medium'].h || undefined; } else { returnObject.img_url = baseUrl; } - if(typeof _item.sizes['large'] !== "undefined") { - returnObject.native_url = baseUrl+":large"; + if (typeof _item.sizes['large'] !== "undefined") { + returnObject.native_url = baseUrl + ":large"; returnObject.native_width = _item.sizes['large'].w || undefined; returnObject.native_height = _item.sizes['large'].h || undefined; } else { @@ -200,14 +200,14 @@ jjtApingCodebird.service('apingCodebirdHelper', ['apingModels', 'apingTimeHelper angular.forEach(_data.statuses, function (value, key) { var tempResult = _this.getItemByJsonData(value, _helperObject); - if(tempResult) { + if (tempResult) { requestResults.push(tempResult); } }); } else if (_data.length > 0) { angular.forEach(_data, function (value, key) { var tempResult = _this.getItemByJsonData(value, _helperObject); - if(tempResult) { + if (tempResult) { requestResults.push(tempResult); } }); @@ -222,7 +222,7 @@ jjtApingCodebird.service('apingCodebirdHelper', ['apingModels', 'apingTimeHelper var returnObject = {}; if (_item && _helperObject.model) { - if(_helperObject.getNativeData === true || _helperObject.getNativeData === "true") { + if (_helperObject.getNativeData === true || _helperObject.getNativeData === "true") { returnObject = this.getNativeItemByJsonData(_item, _helperObject.model); } else { switch (_helperObject.model) { @@ -258,21 +258,21 @@ jjtApingCodebird.service('apingCodebirdHelper', ['apingModels', 'apingTimeHelper socialObject.date_time = new Date(socialObject.timestamp); - if(_item.entities && _item.entities.media && _item.entities.media.length>0) { + if (_item.entities && _item.entities.media && _item.entities.media.length > 0) { socialObject.source = _item.entities.media; socialObject.img_url = this.getImageUrlFromMediaObject(_item.entities.media[0]); } - if(socialObject.img_url) { + if (socialObject.img_url) { socialObject.type = "image"; } else { socialObject.type = "tweet"; - if(_item.user && (_helperObject.showAvatar === true || _helperObject.showAvatar === 'true' ) ) { + if (_item.user && (_helperObject.showAvatar === true || _helperObject.showAvatar === 'true' )) { socialObject.img_url = this.getImageUrlFromUserObject(_item.user); } } - socialObject.post_url = socialObject.blog_link+"status/"+socialObject.intern_id; + socialObject.post_url = socialObject.blog_link + "status/" + socialObject.intern_id; return socialObject; }; @@ -293,23 +293,23 @@ jjtApingCodebird.service('apingCodebirdHelper', ['apingModels', 'apingTimeHelper imageObject.date_time = new Date(imageObject.timestamp); - if(_item.entities && _item.entities.media && _item.entities.media.length>0) { + if (_item.entities && _item.entities.media && _item.entities.media.length > 0) { imageObject.source = _item.entities.media; var tempImageArray = this.getImagesObjectFromMediaObject(_item.entities.media[0]); $.extend(true, imageObject, tempImageArray); - if(!imageObject.img_url) { + if (!imageObject.img_url) { imageObject.img_url = this.getImageUrlFromMediaObject(_item.entities.media[0]); } } - if(!imageObject.img_url) { + if (!imageObject.img_url) { return false; } - imageObject.post_url = imageObject.blog_link+"status/"+imageObject.intern_id; + imageObject.post_url = imageObject.blog_link + "status/" + imageObject.intern_id; return imageObject; }; @@ -320,7 +320,7 @@ jjtApingCodebird.service('apingCodebirdHelper', ['apingModels', 'apingTimeHelper switch (_model) { case "image": - if(!_item.entities || !_item.entities.media || !_item.entities.media.length>0 || !this.getImageUrlFromMediaObject(_item.entities.media[0])) { + if (!_item.entities || !_item.entities.media || !_item.entities.media.length > 0 || !this.getImageUrlFromMediaObject(_item.entities.media[0])) { return false; } else { nativeItem = _item; diff --git a/dist/aping-plugin-codebird.min.js b/dist/aping-plugin-codebird.min.js index 346b278..06cd684 100644 --- a/dist/aping-plugin-codebird.min.js +++ b/dist/aping-plugin-codebird.min.js @@ -1,8 +1,8 @@ /** @name: aping-plugin-codebird - @version: 0.7.0 (09-01-2016) - @author: Jonathan Hornung - @url: https://github.com/JohnnyTheTank/apiNG-plugin-codebird#readme + @version: 0.7.5 (10-01-2016) + @author: Jonathan Hornung + @url: https://github.com/JohnnyTheTank/apiNG-plugin-codebird @license: MIT */ "use strict";var jjtApingCodebird=angular.module("jtt_aping_codebird",[]).directive("apingCodebird",["apingCodebirdHelper","apingUtilityHelper",function(a,b){return{require:"?aping",restrict:"A",replace:"false",link:function(c,d,e,f,g){var h=f.getAppSettings(),i=b.parseJsonFromAttributes(e.apingCodebird,a.getThisPlattformString(),h),j=new Codebird;j.setBearerToken(b.getApiCredentials(a.getThisPlattformString(),"bearer_token")),i.forEach(function(b){var c={model:h.model,showAvatar:b.showAvatar||!1};"undefined"!=typeof h.getNativeData?c.getNativeData=h.getNativeData:c.getNativeData=!1;var d={};if("undefined"!=typeof b.items?d.count=b.items:d.count=h.items,0==d.count)return!1;if((d.count<0||isNaN(d.count))&&(d.count=void 0),d.count>100&&(d.count=100),b.search)d.q=b.search,d.result_type=b.result_type||"mixed","undefined"!=typeof b.lat&&"undefined"!=typeof b.lng&&(d.geocode=b.lat+","+b.lng+","+(b.distance||"1")+"km"),"undefined"!=typeof b.language&&(d.lang=b.language),j.__call("search_tweets",d,function(b){f.concatToResults(a.getObjectByJsonData(b,c)),f.apply()},!0);else{if(!b.user)return!1;d.screen_name=b.user,d.contributor_details=!0,(b.exclude_replies===!0||"true"===b.exclude_replies)&&(d.exclude_replies=!0),(b.include_rts===!1||"false"===b.include_rts)&&(d.include_rts=!1),j.__call("statuses_userTimeline",d,function(b,d,e){f.concatToResults(a.getObjectByJsonData(b,c)),f.apply()},!0)}})}}}]);jjtApingCodebird.service("apingCodebirdHelper",["apingModels","apingTimeHelper","apingUtilityHelper",function(a,b,c){this.getThisPlattformString=function(){return"twitter"},this.getThisPlattformLink=function(){return"https://twitter.com/"},this.getBigImageUrlFromSmallImageUrl=function(a){return a.replace("_normal","")},this.getImageUrlFromMediaObject=function(a){if(a){if(a.media_url_https)return this.getBigImageUrlFromSmallImageUrl(a.media_url_https);if(a.media_url)return this.getBigImageUrlFromSmallImageUrl(a.media_url)}},this.getImageUrlFromUserObject=function(a){if(a){if(a.profile_image_url_https)return this.getBigImageUrlFromSmallImageUrl(a.profile_image_url_https);if(a.profile_image_url)return this.getBigImageUrlFromSmallImageUrl(a.profile_image_url)}},this.getImagesObjectFromMediaObject=function(a){var b={thumb_url:void 0,thumb_width:void 0,thumb_height:void 0,img_url:void 0,img_width:void 0,img_height:void 0,native_url:void 0,native_width:void 0,native_height:void 0},c=this.getImageUrlFromMediaObject(a);return a.sizes&&("undefined"!=typeof a.sizes.small?(b.thumb_url=c+":small",b.thumb_width=a.sizes.small.w||void 0,b.thumb_height=a.sizes.small.h||void 0):b.thumb_url=c,"undefined"!=typeof a.sizes.medium?(b.img_url=c+":medium",b.img_width=a.sizes.medium.w||void 0,b.img_height=a.sizes.medium.h||void 0):b.img_url=c,"undefined"!=typeof a.sizes.large?(b.native_url=c+":large",b.native_width=a.sizes.large.w||void 0,b.native_height=a.sizes.large.h||void 0):b.native_url=c),b},this.getObjectByJsonData=function(a,b){var c=[];if(a){var d=this;a.statuses?angular.forEach(a.statuses,function(a,e){var f=d.getItemByJsonData(a,b);f&&c.push(f)}):a.length>0&&angular.forEach(a,function(a,e){var f=d.getItemByJsonData(a,b);f&&c.push(f)})}return c},this.getItemByJsonData=function(a,b){var c={};if(a&&b.model)if(b.getNativeData===!0||"true"===b.getNativeData)c=this.getNativeItemByJsonData(a,b.model);else switch(b.model){case"social":c=this.getSocialItemByJsonData(a,b);break;case"image":c=this.getImageItemByJsonData(a,b);break;default:return!1}return c},this.getSocialItemByJsonData=function(b,c){var d=a.getNew("social",this.getThisPlattformString());return $.extend(!0,d,{blog_name:b.user.screen_name,blog_id:b.user.id_str,blog_link:this.getThisPlattformLink()+b.user.screen_name+"/",intern_id:b.id_str,timestamp:new Date(Date.parse(b.created_at.replace(/( \+)/," UTC$1"))).getTime(),text:b.text,shares:b.retweet_count,likes:b.favorite_count}),d.date_time=new Date(d.timestamp),b.entities&&b.entities.media&&b.entities.media.length>0&&(d.source=b.entities.media,d.img_url=this.getImageUrlFromMediaObject(b.entities.media[0])),d.img_url?d.type="image":(d.type="tweet",!b.user||c.showAvatar!==!0&&"true"!==c.showAvatar||(d.img_url=this.getImageUrlFromUserObject(b.user))),d.post_url=d.blog_link+"status/"+d.intern_id,d},this.getImageItemByJsonData=function(b){var c=a.getNew("image",this.getThisPlattformString());if($.extend(!0,c,{blog_name:b.user.screen_name,blog_id:b.user.id_str,blog_link:this.getThisPlattformLink()+b.user.screen_name+"/",intern_id:b.id_str,timestamp:new Date(Date.parse(b.created_at.replace(/( \+)/," UTC$1"))).getTime(),text:b.text,shares:b.retweet_count,likes:b.favorite_count}),c.date_time=new Date(c.timestamp),b.entities&&b.entities.media&&b.entities.media.length>0){c.source=b.entities.media;var d=this.getImagesObjectFromMediaObject(b.entities.media[0]);$.extend(!0,c,d),c.img_url||(c.img_url=this.getImageUrlFromMediaObject(b.entities.media[0]))}return c.img_url?(c.post_url=c.blog_link+"status/"+c.intern_id,c):!1},this.getNativeItemByJsonData=function(a,b){var c={};switch(b){case"image":if(!a.entities||!a.entities.media||!a.entities.media.length>0||!this.getImageUrlFromMediaObject(a.entities.media[0]))return!1;c=a}return c=a}}]),function(undefined){Array.prototype.indexOf||(Array.prototype.indexOf=function(a,b){for(var c=b||0;c-1||navigator.userAgent.indexOf("Trident/5")>-1||navigator.userAgent.indexOf("MSIE 7.0")>-1),_use_proxy="undefined"!=typeof navigator&&"undefined"!=typeof navigator.userAgent,_oauth_token=null,_oauth_token_secret=null,_version="2.6.0",setConsumerKey=function(a,b){_oauth_consumer_key=a,_oauth_consumer_secret=b},setBearerToken=function(a){_oauth_bearer_token=a},getVersion=function(){return _version},setToken=function(a,b){_oauth_token=a,_oauth_token_secret=b},setUseProxy=function(a){_use_proxy=!!a},setProxy=function(a){a.match(/\/$/)||(a+="/"),_endpoint_proxy=a},_parse_str=function(str,array){var glue1="=",glue2="&",array2=String(str).replace(/^&?([\s\S]*?)&?$/,"$1").split(glue2),i,j,chr,tmp,key,value,bracket,keys,evalStr,fixStr=function(a){return decodeURIComponent(a).replace(/([\\"'])/g,"\\$1").replace(/\n/g,"\\n").replace(/\r/g,"\\r")};for(array||(array=this.window),i=0;i0&&(i+="/"),i+=j[g];var k=["screen_name","place_id"];for(g=0;gh;h++)m=m.split(String.fromCharCode(65+h)).join("_"+String.fromCharCode(97+h));console.warn('To call the templated method "'+m+'", specify the parameter value for "'+o+'".')}i=i.split(f).join(e[o]),delete e[o]}for(g=0;26>g;g++)i=i.split(String.fromCharCode(65+g)).join("_"+String.fromCharCode(97+g)),m=m.split(String.fromCharCode(65+g)).join("_"+String.fromCharCode(97+g));var p=_detectMethod(m,e),q=_detectMultipart(m),r=_detectInternal(m);return _callApi(p,i,e,q,d,r,c)},oauth_authenticate=function(a,b){"undefined"==typeof a.force_login&&(a.force_login=null),"undefined"==typeof a.screen_name&&(a.screen_name=null),null===_oauth_token&&console.warn("To get the authenticate URL, the OAuth token must be set.");var c=_endpoint_oauth+"oauth/authenticate?oauth_token="+_url(_oauth_token);return a.force_login===!0&&(c+="&force_login=1",null!==a.screen_name&&(c+="&screen_name="+a.screen_name)),b(c),!0},oauth_authorize=function(a,b){"undefined"==typeof a.force_login&&(a.force_login=null),"undefined"==typeof a.screen_name&&(a.screen_name=null),null===_oauth_token&&console.warn("To get the authorize URL, the OAuth token must be set.");var c=_endpoint_oauth+"oauth/authorize?oauth_token="+_url(_oauth_token);return a.force_login===!0&&(c+="&force_login=1",null!==a.screen_name&&(c+="&screen_name="+a.screen_name)),b(c),!0},oauth2_token=function(a){null===_oauth_consumer_key&&console.warn("To obtain a bearer token, the consumer key must be set."),"undefined"==typeof a&&(a=function(){});var b="grant_type=client_credentials",c=_endpoint_oauth+"oauth2/token";_use_proxy&&(c=c.replace(_endpoint_base,_endpoint_proxy));var d=_getXmlRequestObject();null!==d&&(d.open("POST",c,!0),d.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),d.setRequestHeader((_use_proxy?"X-":"")+"Authorization","Basic "+_base64_encode(_oauth_consumer_key+":"+_oauth_consumer_secret)),d.onreadystatechange=function(){if(d.readyState>=4){var b=12027;try{b=d.status}catch(c){}var e="";try{e=d.responseText}catch(c){}var f=_parseApiReply(e);f.httpstatus=b,200===b&&setBearerToken(f.access_token),a(f)}},d.send(b))},_url=function(a){return/boolean|number|string/.test(typeof a)?encodeURIComponent(a).replace(/!/g,"%21").replace(/'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29").replace(/\*/g,"%2A"):""},_sha1=function(){function a(a,c){a[c>>5]|=128<<24-c%32,a[(c+64>>9<<4)+15]=c;for(var d=new Array(80),e=1732584193,f=-271733879,g=-1732584194,h=271733878,i=-1009589776,j=0;jp;p++){var q;16>p?q=a[j+p]:(q=d[p-3]^d[p-8]^d[p-14]^d[p-16],q=q<<1|q>>>31),d[p]=q,q=b(b(e<<5|e>>>27,20>p?f&g|~f&h:40>p?f^g^h:60>p?f&g|f&h|g&h:f^g^h),b(b(i,d[p]),20>p?1518500249:40>p?1859775393:60>p?-1894007588:-899497514)),i=h,h=g,g=f<<30|f>>>2,f=e,e=q}e=b(e,k),f=b(f,l),g=b(g,m),h=b(h,n),i=b(i,o)}return[e,f,g,h,i]}function b(a,b){var c=(65535&a)+(65535&b);return(a>>16)+(b>>16)+(c>>16)<<16|65535&c}function c(a){for(var b=[],c=(1<>5]|=(a.charCodeAt(e/d)&c)<<24-e%32;return b}var d=8;return function(b){var e=_oauth_consumer_secret+"&"+(null!==_oauth_token_secret?_oauth_token_secret:"");null===_oauth_consumer_secret&&console.warn("To generate a hash, the consumer secret must be set.");var f=c(e);f.length>16&&(f=a(f,e.length*d)),e=new Array(16);for(var g=new Array(16),h=0;16>h;h++)g[h]=909522486^f[h],e[h]=1549556828^f[h];for(f=a(g.concat(c(b)),512+b.length*d),e=a(e.concat(f),672),f="",g=0;g<4*e.length;g+=3)for(h=(e[g>>2]>>8*(3-g%4)&255)<<16|(e[g+1>>2]>>8*(3-(g+1)%4)&255)<<8|e[g+2>>2]>>8*(3-(g+2)%4)&255,b=0;4>b;b++)f=8*g+6*b>32*e.length?f+"=":f+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(h>>6*(3-b)&63);return f}}(),_base64_encode=function(a){var b,c,d,e,f=0,g=0,h="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",i=[];if(!a)return a;do b=a.charCodeAt(f++),c=a.charCodeAt(f++),d=a.charCodeAt(f++),e=b<<16|c<<8|d,b=e>>18&63,c=e>>12&63,d=e>>6&63,e&=63,i[g++]=h.charAt(b)+h.charAt(c)+h.charAt(d)+h.charAt(e);while(fa&&console.warn("Invalid nonce length.");for(var b="",c=0;a>c;c++){var d=Math.floor(61*Math.random());b+="0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz".substring(d,d+1)}return b},_ksort=function(a){var b,c,d=[];b=function(a,b){var c=parseFloat(a),d=parseFloat(b),e=c+""===a,f=d+""===b;return e&&f?c>d?1:d>c?-1:0:e&&!f?1:!e&&f?-1:a>b?1:b>a?-1:0};for(c in a)a.hasOwnProperty(c)&&d.push(c);return d.sort(b),d},_clone=function(a){var b={};for(var c in a)"object"==typeof a[c]?b[c]=_clone(a[c]):b[c]=a[c];return b},_sign=function(a,b,c,d){"undefined"==typeof c&&(c={}),"undefined"==typeof d&&(d=!1),null===_oauth_consumer_key&&console.warn("To generate a signature, the consumer key must be set.");var e,f={consumer_key:_oauth_consumer_key,version:"1.0",timestamp:Math.round((new Date).getTime()/1e3),nonce:_nonce(),signature_method:"HMAC-SHA1"},g={};for(var h in f)e=f[h],g["oauth_"+h]=_url(e);null!==_oauth_token&&(g.oauth_token=_url(_oauth_token));var i=_clone(g);for(h in c)e=c[h],g[h]=e;for(var j=_ksort(g),k="",l=0;l-1)return d;console.warn("Can't find HTTP method to use for \""+a+'".')},_detectMultipart=function(a){var b=["statuses/update_with_media","account/update_profile_background_image","account/update_profile_image","account/update_profile_banner"];return b.indexOf(a)>-1},_buildMultipart=function(a,b){if(_detectMultipart(a)){var c=["statuses/update_with_media","account/update_profile_background_image","account/update_profile_image","account/update_profile_banner"],d={"statuses/update_with_media":"media[]","account/update_profile_background_image":"image","account/update_profile_image":"image","account/update_profile_banner":"banner"};if(-1!==c.indexOf(a)){d=d[a].split(" ");var e="--------------------"+_nonce(),f="";for(var g in b)f+="--"+e+'\r\nContent-Disposition: form-data; name="'+g+'"',d.indexOf(g)>-1&&(f+="\r\nContent-Transfer-Encoding: base64"),f+="\r\n\r\n"+b[g]+"\r\n";return f+="--"+e+"--"}}},_detectInternal=function(a){var b=["users/recommendations"];return b.join(" ").indexOf(a)>-1},_detectMedia=function(a){var b=["media/upload"];return b.join(" ").indexOf(a)>-1},_detectOld=function(a){var b=["account/push_destinations/device"];return b.join(" ").indexOf(a)>-1},_getEndpoint=function(a){var b;return b="oauth"===a.substring(0,5)?_endpoint_oauth+a:_detectMedia(a)?_endpoint_media+a+".json":_detectOld(a)?_endpoint_old+a+".json":_endpoint+a+".json"},_getXmlRequestObject=function(){var a=null;if("object"==typeof window&&window&&"undefined"!=typeof window.XMLHttpRequest)a=new window.XMLHttpRequest;else if("object"==typeof Ti&&Ti&&"undefined"!=typeof Ti.Network.createHTTPClient)a=Ti.Network.createHTTPClient();else if("undefined"!=typeof ActiveXObject)try{a=new ActiveXObject("Microsoft.XMLHTTP")}catch(b){console.error("ActiveXObject object not defined.")}else if("function"==typeof require&&require)try{var c=require("xmlhttprequest").XMLHttpRequest;a=new c}catch(d){try{var c=require("xhr2");a=new c}catch(e){console.error("xhr2 object not defined, cancelling.")}}return a},_callApi=function(a,b,c,d,e,f,g){"undefined"==typeof c&&(c={}),"undefined"==typeof d&&(d=!1),"undefined"==typeof e&&(e=!1),"function"!=typeof g&&(g=function(){}),f&&(c.adc="phone",c.application_id=333903271);var h=_getEndpoint(b),i=null,j=_getXmlRequestObject();if(null!==j){var k;if("GET"===a){var l=h;if("{}"!==JSON.stringify(c)&&(l+="?"+_http_build_query(c)),e||(i=_sign(a,h,c)),_use_jsonp){l+="{}"!==JSON.stringify(c)?"&":"?";var m=_nonce();window[m]=function(a){a.httpstatus=200;var b=null;"undefined"!=typeof j.getResponseHeader&&""!==j.getResponseHeader("x-rate-limit-limit")&&(b={limit:j.getResponseHeader("x-rate-limit-limit"),remaining:j.getResponseHeader("x-rate-limit-remaining"),reset:j.getResponseHeader("x-rate-limit-reset")}),g(a,b)},c.callback=m,l=h+"?"+_sign(a,h,c,!0);var n=document.createElement("script");n.type="text/javascript",n.src=l;var o=document.getElementsByTagName("body")[0];return void o.appendChild(n)}_use_proxy&&(l=l.replace(_endpoint_base,_endpoint_proxy).replace(_endpoint_base_media,_endpoint_proxy)),j.open(a,l,!0)}else{if(_use_jsonp)return void console.warn("Sending POST requests is not supported for IE7-9.");d?(e||(i=_sign(a,h,{})),c=_buildMultipart(b,c)):(e||(i=_sign(a,h,c)),c=_http_build_query(c)),k=c,(_use_proxy||d)&&(h=h.replace(_endpoint_base,_endpoint_proxy).replace(_endpoint_base_media,_endpoint_proxy)),j.open(a,h,!0),d?j.setRequestHeader("Content-Type","multipart/form-data; boundary="+k.split("\r\n")[0].substring(2)):j.setRequestHeader("Content-Type","application/x-www-form-urlencoded")}if(e){if(null===_oauth_consumer_key&&null===_oauth_bearer_token&&console.warn("To make an app-only auth API request, consumer key or bearer token must be set."),null===_oauth_bearer_token)return oauth2_token(function(){_callApi(a,b,c,d,e,!1,g)});i="Bearer "+_oauth_bearer_token}return null!==i&&j.setRequestHeader((_use_proxy?"X-":"")+"Authorization",i),j.onreadystatechange=function(){if(j.readyState>=4){var a=12027;try{a=j.status}catch(b){}var c="";try{c=j.responseText}catch(b){}var d=_parseApiReply(c);d.httpstatus=a;var e=null;"undefined"!=typeof j.getResponseHeader&&""!==j.getResponseHeader("x-rate-limit-limit")&&(e={limit:j.getResponseHeader("x-rate-limit-limit"),remaining:j.getResponseHeader("x-rate-limit-remaining"),reset:j.getResponseHeader("x-rate-limit-reset")}),g(d,e)}},j.send("GET"===a?null:k),!0}},_parseApiReply=function(a){if("string"!=typeof a||""===a)return{};if("[]"===a)return[];var b;try{b=JSON.parse(a)}catch(c){if(b={},0===a.indexOf(''))b.request=a.match(/(.*)<\/request>/)[1],b.error=a.match(/(.*)<\/error>/)[1];else for(var d=a.split("&"),e=0;e1?b[f[0]]=decodeURIComponent(f[1]):b[f[0]]=null}}return b};return{setConsumerKey:setConsumerKey,getVersion:getVersion,setToken:setToken,setBearerToken:setBearerToken,setUseProxy:setUseProxy,setProxy:setProxy,getApiMethods:getApiMethods,__call:__call,oauth_authenticate:oauth_authenticate,oauth_authorize:oauth_authorize,oauth2_token:oauth2_token}};"object"==typeof module&&module&&"object"==typeof module.exports?module.exports=Codebird:("object"==typeof window&&window&&(window.Codebird=Codebird),"function"==typeof define&&define.amd&&define("codebird",[],function(){return Codebird}))}(); \ No newline at end of file diff --git a/package.json b/package.json index db0670c..807774d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "aping-plugin-codebird", - "version": "0.7.0", - "description": "twitter plugin for apiNG", + "version": "0.7.5", + "description": "Twitter plugin for apiNG", "main": "dist/aping-plugin-codebird.min.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" @@ -19,12 +19,12 @@ "json", "angular" ], - "author": "Jonathan Hornung", + "author": "Jonathan Hornung ", "license": "MIT", "bugs": { "url": "https://github.com/JohnnyTheTank/apiNG-plugin-codebird/issues" }, - "homepage": "https://github.com/JohnnyTheTank/apiNG-plugin-codebird#readme", + "homepage": "https://github.com/JohnnyTheTank/apiNG-plugin-codebird", "devDependencies": { "codebird": "*", "grunt": "^0.4.5", diff --git a/src/aping-codebird-directive.js b/src/aping-codebird-directive.js index fa56a91..d956ddf 100644 --- a/src/aping-codebird-directive.js +++ b/src/aping-codebird-directive.js @@ -21,9 +21,9 @@ var jjtApingCodebird = angular.module("jtt_aping_codebird", []) //create helperObject for helper function call var helperObject = { model: appSettings.model, - showAvatar : request.showAvatar || false, + showAvatar: request.showAvatar || false, }; - if(typeof appSettings.getNativeData !== "undefined") { + if (typeof appSettings.getNativeData !== "undefined") { helperObject.getNativeData = appSettings.getNativeData; } else { helperObject.getNativeData = false; @@ -31,36 +31,36 @@ var jjtApingCodebird = angular.module("jtt_aping_codebird", []) //create requestObject for api request call var requestObject = {}; - if(typeof request.items !== "undefined") { + if (typeof request.items !== "undefined") { requestObject.count = request.items; } else { requestObject.count = appSettings.items; } - if(requestObject.count == 0) { + if (requestObject.count == 0) { return false; } // -1 is "no explicit limit". same for NaN value - if(requestObject.count < 0 || isNaN(requestObject.count)) { + if (requestObject.count < 0 || isNaN(requestObject.count)) { requestObject.count = undefined; } // the api has a limit of 100 items per request - if(requestObject.count > 100) { + if (requestObject.count > 100) { requestObject.count = 100; } - if(request.search) { + if (request.search) { // https://dev.twitter.com/rest/reference/get/search/tweets requestObject.q = request.search; requestObject.result_type = request.result_type || "mixed"; - if(typeof request.lat !== "undefined" && typeof request.lng !== "undefined") { - requestObject.geocode = request.lat+","+request.lng+","+(request.distance || "1" )+"km"; + if (typeof request.lat !== "undefined" && typeof request.lng !== "undefined") { + requestObject.geocode = request.lat + "," + request.lng + "," + (request.distance || "1" ) + "km"; } - if(typeof request.language !== "undefined") { + if (typeof request.language !== "undefined") { requestObject.lang = request.language; } @@ -74,17 +74,17 @@ var jjtApingCodebird = angular.module("jtt_aping_codebird", []) true ); - } else if(request.user) { + } else if (request.user) { // https://dev.twitter.com/rest/reference/get/statuses/user_timeline requestObject.screen_name = request.user; requestObject.contributor_details = true; - if(request.exclude_replies === true || request.exclude_replies === "true"){ + if (request.exclude_replies === true || request.exclude_replies === "true") { requestObject.exclude_replies = true; } - if(request.include_rts === false || request.include_rts === "false"){ + if (request.include_rts === false || request.include_rts === "false") { requestObject.include_rts = false; } diff --git a/src/aping-codebird-helper.js b/src/aping-codebird-helper.js index cd23669..6fa6f34 100644 --- a/src/aping-codebird-helper.js +++ b/src/aping-codebird-helper.js @@ -12,22 +12,22 @@ jjtApingCodebird.service('apingCodebirdHelper', ['apingModels', 'apingTimeHelper return _smallImageUrl.replace("_normal", ""); }; this.getImageUrlFromMediaObject = function (_item) { - if(_item) { - if(_item.media_url_https) { + if (_item) { + if (_item.media_url_https) { return this.getBigImageUrlFromSmallImageUrl(_item.media_url_https); } - if(_item.media_url) { + if (_item.media_url) { return this.getBigImageUrlFromSmallImageUrl(_item.media_url); } } return undefined; }; this.getImageUrlFromUserObject = function (_item) { - if(_item) { - if(_item.profile_image_url_https) { + if (_item) { + if (_item.profile_image_url_https) { return this.getBigImageUrlFromSmallImageUrl(_item.profile_image_url_https); } - if(_item.profile_image_url) { + if (_item.profile_image_url) { return this.getBigImageUrlFromSmallImageUrl(_item.profile_image_url); } } @@ -49,25 +49,25 @@ jjtApingCodebird.service('apingCodebirdHelper', ['apingModels', 'apingTimeHelper var baseUrl = this.getImageUrlFromMediaObject(_item); - if(_item.sizes) { - if(typeof _item.sizes['small'] !== "undefined") { - returnObject.thumb_url = baseUrl+":small"; + if (_item.sizes) { + if (typeof _item.sizes['small'] !== "undefined") { + returnObject.thumb_url = baseUrl + ":small"; returnObject.thumb_width = _item.sizes['small'].w || undefined; returnObject.thumb_height = _item.sizes['small'].h || undefined; } else { returnObject.thumb_url = baseUrl; } - if(typeof _item.sizes['medium'] !== "undefined") { - returnObject.img_url = baseUrl+":medium"; + if (typeof _item.sizes['medium'] !== "undefined") { + returnObject.img_url = baseUrl + ":medium"; returnObject.img_width = _item.sizes['medium'].w || undefined; returnObject.img_height = _item.sizes['medium'].h || undefined; } else { returnObject.img_url = baseUrl; } - if(typeof _item.sizes['large'] !== "undefined") { - returnObject.native_url = baseUrl+":large"; + if (typeof _item.sizes['large'] !== "undefined") { + returnObject.native_url = baseUrl + ":large"; returnObject.native_width = _item.sizes['large'].w || undefined; returnObject.native_height = _item.sizes['large'].h || undefined; } else { @@ -88,14 +88,14 @@ jjtApingCodebird.service('apingCodebirdHelper', ['apingModels', 'apingTimeHelper angular.forEach(_data.statuses, function (value, key) { var tempResult = _this.getItemByJsonData(value, _helperObject); - if(tempResult) { + if (tempResult) { requestResults.push(tempResult); } }); } else if (_data.length > 0) { angular.forEach(_data, function (value, key) { var tempResult = _this.getItemByJsonData(value, _helperObject); - if(tempResult) { + if (tempResult) { requestResults.push(tempResult); } }); @@ -110,7 +110,7 @@ jjtApingCodebird.service('apingCodebirdHelper', ['apingModels', 'apingTimeHelper var returnObject = {}; if (_item && _helperObject.model) { - if(_helperObject.getNativeData === true || _helperObject.getNativeData === "true") { + if (_helperObject.getNativeData === true || _helperObject.getNativeData === "true") { returnObject = this.getNativeItemByJsonData(_item, _helperObject.model); } else { switch (_helperObject.model) { @@ -146,21 +146,21 @@ jjtApingCodebird.service('apingCodebirdHelper', ['apingModels', 'apingTimeHelper socialObject.date_time = new Date(socialObject.timestamp); - if(_item.entities && _item.entities.media && _item.entities.media.length>0) { + if (_item.entities && _item.entities.media && _item.entities.media.length > 0) { socialObject.source = _item.entities.media; socialObject.img_url = this.getImageUrlFromMediaObject(_item.entities.media[0]); } - if(socialObject.img_url) { + if (socialObject.img_url) { socialObject.type = "image"; } else { socialObject.type = "tweet"; - if(_item.user && (_helperObject.showAvatar === true || _helperObject.showAvatar === 'true' ) ) { + if (_item.user && (_helperObject.showAvatar === true || _helperObject.showAvatar === 'true' )) { socialObject.img_url = this.getImageUrlFromUserObject(_item.user); } } - socialObject.post_url = socialObject.blog_link+"status/"+socialObject.intern_id; + socialObject.post_url = socialObject.blog_link + "status/" + socialObject.intern_id; return socialObject; }; @@ -181,23 +181,23 @@ jjtApingCodebird.service('apingCodebirdHelper', ['apingModels', 'apingTimeHelper imageObject.date_time = new Date(imageObject.timestamp); - if(_item.entities && _item.entities.media && _item.entities.media.length>0) { + if (_item.entities && _item.entities.media && _item.entities.media.length > 0) { imageObject.source = _item.entities.media; var tempImageArray = this.getImagesObjectFromMediaObject(_item.entities.media[0]); $.extend(true, imageObject, tempImageArray); - if(!imageObject.img_url) { + if (!imageObject.img_url) { imageObject.img_url = this.getImageUrlFromMediaObject(_item.entities.media[0]); } } - if(!imageObject.img_url) { + if (!imageObject.img_url) { return false; } - imageObject.post_url = imageObject.blog_link+"status/"+imageObject.intern_id; + imageObject.post_url = imageObject.blog_link + "status/" + imageObject.intern_id; return imageObject; }; @@ -208,7 +208,7 @@ jjtApingCodebird.service('apingCodebirdHelper', ['apingModels', 'apingTimeHelper switch (_model) { case "image": - if(!_item.entities || !_item.entities.media || !_item.entities.media.length>0 || !this.getImageUrlFromMediaObject(_item.entities.media[0])) { + if (!_item.entities || !_item.entities.media || !_item.entities.media.length > 0 || !this.getImageUrlFromMediaObject(_item.entities.media[0])) { return false; } else { nativeItem = _item;