Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnnyTheTank committed Nov 22, 2015
1 parent abe1f84 commit 34128ac
Show file tree
Hide file tree
Showing 11 changed files with 344 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/config.codekit
/bower_components
/.idea/
/.codekit-cache/
/node_modules
40 changes: 40 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module.exports = function(grunt) {

grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
uglify: {
js: {
files : {
'dist/aping-plugin-codebird.min.js' : [
'src/aping-codebird-directive.js',
'src/aping-codebird-helper.js',
'bower_components/codebird-js/codebird.js'
]
}
},
options: {
banner: '\n/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n',
}
},
watch: {
minifiyJs: {
files: [
'src/aping-codebird-directive.js',
'src/aping-codebird-helper.js',
'bower_components/codebird-js/codebird.js'
],
tasks: ['uglify'],
options: {
spawn: true,
}
}
}
});

grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');

grunt.registerTask('default', ['watch']);

};

32 changes: 32 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "apiNG-plugin-codebird",
"homepage": "https://github.com/JohnnyTheTank/apiNG-plugin-codebird",
"authors": [
"Jonathan Hornung <[email protected]>"
],
"version": "0.1.0",
"description": "twitter plugin for apiNG",
"main": "dist/apiNG-plugin-codebird.min.js",
"moduleType": [],
"keywords": [
"aping",
"twitter",
"codebird",
"angularjs",
"rest",
"api",
"json"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
"apiNG": "*",
"codebird-js": "*"
}
}
17 changes: 17 additions & 0 deletions demo/aping-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use strict";
apingApp.config(['$provide', function ($provide) {

$provide.constant("apingApiKeys", {
twitter : "AAAAAAAAAAAAAAAAAAAAACs3iwAAAAAA%2BH8LdT7YfKIzk8fvQvqKvoePuxo%3DMKfXX2ojtacGL8aOLAhlBDUrEFpy0DUuiyebet22Wa2YVrX7cc",
});

$provide.constant("apingDefaultSettings", {
templateUrl : "aping_design_sample.html",
items : 20, //items per request
maxItems: 100, //max items per aping
orderBy : "timestamp",
orderReverse : "true",
type: "social",
});

}]);
7 changes: 7 additions & 0 deletions demo/aping_design_sample.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="aping-design-sample">
<div>
<div ng-repeat="item in results">
<pre>{{item | json}}</pre>
</div>
</div>
</div>
1 change: 1 addition & 0 deletions demo/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
angular.module('app', ['jtt_aping', 'jtt_aping_codebird']);
26 changes: 26 additions & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Codebird Demo</title>

<script src="../bower_components/jquery/dist/jquery.min.js"></script>
<script src="../bower_components/angular/angular.min.js"></script>
<script src="../bower_components/angular-sanitize/angular-sanitize.min.js"></script>
<!--
<script src="../bower_components/apiNG/dist/aping.min.js"></script>
-->
<script src="../bower_components/apiNG/src/aping-directive.js"></script>
<script src="../bower_components/apiNG/src/aping-helpers.js"></script>
<script src="../bower_components/apiNG/src/aping-inputObjects.js"></script>
<script src="../bower_components/apiNG/src/aping-models.js"></script>
<script src="aping-config.js"></script>
<script src="app.js"></script>
<script src="../bower_components/codebird-js/codebird.js"></script>
<script src="../src/aping-codebird-directive.js"></script>
<script src="../src/aping-codebird-helper.js"></script>
</head>
<body ng-app="app">
<aping type="social" aping-codebird="[{'user':'ARD_Presse', 'result_type':'recent'}]"></aping>
</body>
</html>
3 changes: 3 additions & 0 deletions dist/aping-plugin-codebird.min.js

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "aping-plugin-codebird",
"version": "0.1.0",
"description": "twitter plugin for apiNG",
"main": "Gruntfile.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/JohnnyTheTank/apiNG-plugin-codebird.git"
},
"keywords": [
"aping",
"twitter",
"angularjs",
"rest",
"api",
"json",
"angular"
],
"author": "Jonathan Hornung",
"license": "MIT",
"bugs": {
"url": "https://github.com/JohnnyTheTank/apiNG-plugin-codebird/issues"
},
"homepage": "https://github.com/JohnnyTheTank/apiNG-plugin-codebird#readme",
"devDependencies": {
"grunt": "^0.4.5",
"grunt-contrib-uglify": "^0.10.1",
"grunt-contrib-watch": "^0.6.1"
}
}
70 changes: 70 additions & 0 deletions src/aping-codebird-directive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"use strict";

/**
@author Jonathan Hornung (https://github.com/JohnnyTheTank)
@url https://github.com/JohnnyTheTank/apiNG-plugin-codebird
@licence MIT
*/

var jjtApingCodebird = angular.module("jtt_aping_codebird", [])
.directive('apingCodebird', ['apingApiKeys', 'apingCodebirdHelper', 'apingUtilityHelper', function (apingApiKeys, apingCodebirdHelper, apingUtilityHelper) {
return {
require: '?aping',
restrict: 'A',
replace: 'false',
link: function (scope, element, attrs, apingController, interval) {

var appSettings = apingController.getAppSettings();

var requests = apingUtilityHelper.parseJsonFromAttributes(attrs.apingCodebird, apingCodebirdHelper.getThisPlattformString());

var cb = new Codebird;
cb.setBearerToken(apingApiKeys.twitter);

requests.forEach(function (request) {

if(request.search) {

//https://dev.twitter.com/rest/reference/get/search/tweets
var params = {
q: request.search,
result_type: request.result_type || "mixed",
count:request.items || appSettings.items,
};

cb.__call(
"search_tweets",
params,
function (_data) {
apingController.concatToResults(apingCodebirdHelper.getObjectByJsonData(_data, request.type));
apingController.apply();
},
true
);



} 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
};
cb.__call(
"statuses_userTimeline",
params,
function (_data, rate, err) {
apingController.concatToResults(apingCodebirdHelper.getObjectByJsonData(_data, request.type));
apingController.apply();
},
true
);
} else {
return false;
}

});
}
}
}]);
110 changes: 110 additions & 0 deletions src/aping-codebird-helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
"use strict";

/**
@author Jonathan Hornung (https://github.com/JohnnyTheTank)
@url https://github.com/JohnnyTheTank/apiNG-plugin-codebird
@licence MIT
*/

jjtApingCodebird.service('apingCodebirdHelper', ['apingModels', 'apingTimeHelper', 'apingUtilityHelper', function (apingModels, apingTimeHelper, apingUtilityHelper) {
this.getThisPlattformString = function () {
return "twitter";
};

this.getThisPlattformLink = function () {
return "https://twitter.com/";
};
this.getBigImageUrlFromSmallImageUrl = function (_smallImageUrl) {
return _smallImageUrl.replace("_normal", "");
};
this.getImageUrlFromMediaObject = function (_item) {
if(_item) {
if(_item.media_url_https) {
return this.getBigImageUrlFromSmallImageUrl(_item.media_url_https);
}
if(_item.media_url) {
return this.getBigImageUrlFromSmallImageUrl(_item.media_url);
}
}
return false;
};
this.getImageUrlFromUserObject = function (_item) {
if(_item) {
if(_item.profile_image_url_https) {
return this.getBigImageUrlFromSmallImageUrl(_item.profile_image_url_https);
}
if(_item.profile_image_url) {
return this.getBigImageUrlFromSmallImageUrl(_item.profile_image_url);
}
}
return false;
};

this.getObjectByJsonData = function (_data, _type) {

var requestResults = [];
if (_data) {
var _this = this;

if (_data.statuses) {

angular.forEach(_data.statuses, function (value, key) {
requestResults.push(_this.getItemByJsonData(value, _type));
});
} else if (_data.length > 0) {
angular.forEach(_data, function (value, key) {
requestResults.push(_this.getItemByJsonData(value, _type));
});
}

}

return requestResults;
};

this.getItemByJsonData = function (_item, _type) {
var returnObject = {};
if (_item && _type) {
switch (_type) {
case "social":
returnObject = this.getSocialItemByJsonData(_item);
break;
}
}
return returnObject;
};

this.getSocialItemByJsonData = function (_item) {
var socialObject = apingModels.getNew("social", this.getThisPlattformString());

$.extend(true, socialObject, {
blog_name: _item.user.screen_name,
blog_id: _item.user.id_str,
blog_link: this.getThisPlattformLink() + _item.user.screen_name + "/",
intern_id: _item.id_str,
timestamp: new Date(Date.parse(_item.created_at.replace(/( \+)/, ' UTC$1'))).getTime(),
text: _item.text,
shares: _item.retweet_count,
likes: _item.favorite_count,
});

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) {
socialObject.type = "image";
} else {
socialObject.type = "tweet";
if(_item.user) {
socialObject.img_url = this.getImageUrlFromUserObject(_item.user);
}
}

socialObject.post_url = socialObject.blog_link+"status/"+socialObject.intern_id;

return socialObject;
};

}]);

0 comments on commit 34128ac

Please sign in to comment.