From 43eb4193b427a60e71595b2a3d44a25438c84145 Mon Sep 17 00:00:00 2001 From: Jonathan Hornung Date: Sat, 19 Dec 2015 13:35:43 +0100 Subject: [PATCH] refac: created requestObject --- bower.json | 2 +- demo/aping-config.js | 1 + demo/index.html | 2 +- dist/aping-plugin-codebird.min.js | 4 ++-- package.json | 2 +- src/aping-codebird-directive.js | 32 +++++++++++++++++++------------ 6 files changed, 26 insertions(+), 17 deletions(-) diff --git a/bower.json b/bower.json index 7a12def..f4d5366 100644 --- a/bower.json +++ b/bower.json @@ -4,7 +4,7 @@ "authors": [ "Jonathan Hornung " ], - "version": "0.1.10", + "version": "0.1.11", "description": "twitter plugin for apiNG", "main": "dist/apiNG-plugin-codebird.min.js", "moduleType": [], diff --git a/demo/aping-config.js b/demo/aping-config.js index 272c7bf..0ed7a25 100644 --- a/demo/aping-config.js +++ b/demo/aping-config.js @@ -14,6 +14,7 @@ apingApp.config(['$provide', function ($provide) { orderBy : "timestamp", orderReverse : "true", model: "social", + getNativeData: false, }); }]); \ No newline at end of file diff --git a/demo/index.html b/demo/index.html index d7e22cd..4ba9d7c 100644 --- a/demo/index.html +++ b/demo/index.html @@ -16,7 +16,7 @@

{'search':'münchen', 'result_type':'recent', 'language':'de'}

- +

{'search':'münchen', 'result_type':'recent', 'lat':'48.1374300', 'lng':'11.5754900', 'distance':5}

diff --git a/dist/aping-plugin-codebird.min.js b/dist/aping-plugin-codebird.min.js index af83af5..ba13b67 100644 --- a/dist/aping-plugin-codebird.min.js +++ b/dist/aping-plugin-codebird.min.js @@ -1,3 +1,3 @@ -/*! aping-plugin-codebird v0.1.10 (19-12-2015) by Jonathan Hornung */ -"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};if("undefined"!=typeof h.getNativeData?c.getNativeData=h.getNativeData:c.getNativeData=!1,b.search){var d={q:b.search,result_type:b.result_type||"mixed",count:b.items||h.items};"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;var d={screen_name:b.user,contributor_details:!0,count:b.items||h.items};(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)}return!1},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)}return!1},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());return $.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,c.img_url=this.getImageUrlFromMediaObject(b.entities.media[0])),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 +/*! aping-plugin-codebird v0.1.11 (19-12-2015) by Jonathan Hornung */ +"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,b.search){d.q=b.search,d.result_type=b.result_type||"mixed";var d={q:b.search,result_type:b.result_type||"mixed",count:b.items||h.items};"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)}return!1},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)}return!1},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());return $.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,c.img_url=this.getImageUrlFromMediaObject(b.entities.media[0])),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 faac5e8..3455866 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aping-plugin-codebird", - "version": "0.1.10", + "version": "0.1.11", "description": "twitter plugin for apiNG", "main": "Gruntfile.js", "scripts": { diff --git a/src/aping-codebird-directive.js b/src/aping-codebird-directive.js index 7cc40be..3a850ae 100644 --- a/src/aping-codebird-directive.js +++ b/src/aping-codebird-directive.js @@ -35,26 +35,36 @@ var jjtApingCodebird = angular.module("jtt_aping_codebird", []) helperObject.getNativeData = false; } + //create requestObject for api request call + var requestObject = {}; + if(typeof request.items !== "undefined") { + requestObject.count = request.items; + } else { + requestObject.count = appSettings.items; + } + if(request.search) { + requestObject.q = request.search; + requestObject.result_type = request.result_type || "mixed"; //https://dev.twitter.com/rest/reference/get/search/tweets - var params = { + var requestObject = { q: request.search, result_type: request.result_type || "mixed", count:request.items || appSettings.items, }; if(typeof request.lat !== "undefined" && typeof request.lng !== "undefined") { - params.geocode = request.lat+","+request.lng+","+(request.distance || "1" )+"km"; + requestObject.geocode = request.lat+","+request.lng+","+(request.distance || "1" )+"km"; } if(typeof request.language !== "undefined") { - params.lang = request.language; + requestObject.lang = request.language; } cb.__call( "search_tweets", - params, + requestObject, function (_data) { apingController.concatToResults(apingCodebirdHelper.getObjectByJsonData(_data, helperObject)); apingController.apply(); @@ -64,23 +74,21 @@ var jjtApingCodebird = angular.module("jtt_aping_codebird", []) } else if(request.user) { //https://dev.twitter.com/rest/reference/get/statuses/user_timeline - var params = { - screen_name: request.user, - contributor_details: true, - count: request.items || appSettings.items - }; + + requestObject.screen_name = request.user; + requestObject.contributor_details = true; if(request.exclude_replies === true || request.exclude_replies === "true"){ - params.exclude_replies = true; + requestObject.exclude_replies = true; } if(request.include_rts === false || request.include_rts === "false"){ - params.include_rts = false; + requestObject.include_rts = false; } cb.__call( "statuses_userTimeline", - params, + requestObject, function (_data, rate, err) { apingController.concatToResults(apingCodebirdHelper.getObjectByJsonData(_data, helperObject)); apingController.apply();