{"action":"created","comment":{"url":"https://api.github.com/repos/otavanopisto/kunta-api-www/pulls/comments/79324253","id":79324253,"diff_hunk":"@@ -0,0 +1,180 @@\n+(function() {\n+  'use strict';\n+  \n+  var util = require('util');\n+  var _ = require('lodash');\n+  var Twitter = require('twitter');\n+  var FB = require('fb');\n+  var InstagramAPI = require('instagram-api');\n+  \n+  var config = require(__dirname + '/../../config.json');\n+  \n+  class SocialMediaApi {\n+    \n+    constructor(parent) {\n+      this.parent = parent;\n+      if (config.twitter) {\n+        this.twitter = new Twitter({\n+          consumer_key: config.twitter.consumerKey,\n+          consumer_secret: config.twitter.consumerSecret,\n+          access_token_key: config.twitter.accessTokenKey,\n+          access_token_secret: config.twitter.accessTokenSecret\n+        });\n+      }\n+      \n+      if (config.facebook) {\n+        FB.setAccessToken(util.format(\"%s|%s\", config.facebook.appId, config.facebook.appSecret));\n+      }\n+      \n+      if (config.instagram) {\n+        this.instagram = new InstagramAPI(config.instagram.accessToken);\n+      }\n+    }\n+    \n+    latest(count) {\n+      var sourceCount = (config.facebook ? 1 : 0) + (config.twitter ? 1 : 0) + (config.instagram ? 1 : 0); \n+      if (sourceCount == 0) {\n+        this.parent.addPromise(new Promise((resolve) => {\n+          resolve([]);\n+        }));\n+      } else {\n+        var subcount = Math.ceil(count / sourceCount);\n+        \n+        this.parent.addPromise(new Promise((resolve, reject) => {\n+          var calls = [];\n+          if (config.facebook) {\n+            calls.push(this.facebookLatest(subcount));\n+          }\n+          \n+          if (config.twitter) {\n+            calls.push(this.twitterLatest(subcount));\n+          }\n+          \n+          if (config.instagram) {\n+            calls.push(this.instragramLatest(subcount));\n+          }\n+          \n+          Promise.all(calls)\n+            .then((results) => {\n+              resolve(this._sortAndMerge(results));\n+            })\n+            .catch(reject);\n+        }));\n+      }\n+      \n+      return this.parent;\n+    }\n+    \n+    twitterLatest(count) {\n+      var options = {\n+        \"screen_name\": config.twitter.screenName,\n+        \"count\": count,\n+        \"trim_user\": true,\n+        \"exclude_replies\": true\n+      };\n+      \n+      return new Promise((resolve, reject) => {\n+        this.twitter.get('statuses/user_timeline', options, (err, result) => {\n+          if (err) {\n+            reject(err);\n+          } else {\n+            resolve(result.map(result => {\n+              var idStr = result.id_str;\n+              return {\n+                id: result.id,\n+                created: new Date(result.created_at),\n+                text: this._htmlifyLinks(result.text),\n+                source: 'twitter',\n+                link: 'https://twitter.com/statuses/' + idStr,\n+                image: result.entities.media ? result.entities.media[0].media_url_https : null,\n+                tags: result.entities.hashtags.map(function (tag) { return tag.text; })\n+              };\n+            }));\n+          }\n+        });\n+      });\n+    }\n+    \n+    facebookLatest (count) {\n+      var options = {  \n+        limit: count, \n+        fields: [\n+          'id', \n+          'created_time', \n+          'message', \n+          'description', \n+          'full_picture', \n+          'message_tags'] \n+      };\n+      \n+      return new Promise((resolve, reject) => {\n+        FB.api(util.format('%s/posts', config.facebook.username), options, (result) => {\n+          if(!result || result.error) {\n+            reject(!result ? 'error occurred' : result.error);\n+          } else {\n+            resolve((result.data||[]).map(post => {\n+              return {\n+                id: post.id,\n+                created: new Date(post.created_time),\n+                text: this._htmlifyLinks(post.message||post.description),\n+                source: 'facebook',\n+                link: 'http://facebook.com/' + post.id,\n+                image: post.full_picture,\n+                tags: (post.message_tags||[]).map(function (tag) { return tag.name; })\n+              };\n+            }));\n+          }\n+        });\n+      });\n+    }\n+    \n+    instragramLatest (count) {\n+      var parameters = {\n+        count: count\n+      };\n+      \n+      return new Promise((resolve, reject) => {\n+        this.instagram.userMedia(config.instagram.userId, parameters)\n+          .then(result => {\n+            resolve(result.data.map((item) => {\n+              return {\n+                id: item.id,\n+                created: new Date(parseInt(item.created_time, 10) * 1000),","path":"modules/socialmedia/index.js","position":142,"original_position":142,"commit_id":"30ce122da10eeb6677346d957d811f82936f60ad","original_commit_id":"30ce122da10eeb6677346d957d811f82936f60ad","user":{"login":"houndci-bot","id":6697940,"avatar_url":"https://avatars.githubusercontent.com/u/6697940?v=3","gravatar_id":"","url":"https://api.github.com/users/houndci-bot","html_url":"https://github.com/houndci-bot","followers_url":"https://api.github.com/users/houndci-bot/followers","following_url":"https://api.github.com/users/houndci-bot/following{/other_user}","gists_url":"https://api.github.com/users/houndci-bot/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci-bot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci-bot/subscriptions","organizations_url":"https://api.github.com/users/houndci-bot/orgs","repos_url":"https://api.github.com/users/houndci-bot/repos","events_url":"https://api.github.com/users/houndci-bot/events{/privacy}","received_events_url":"https://api.github.com/users/houndci-bot/received_events","type":"User","site_admin":false},"body":"Identifier 'created_time' is not in camel case.","created_at":"2016-09-19T03:13:31Z","updated_at":"2016-09-19T03:13:31Z","html_url":"https://github.com/otavanopisto/kunta-api-www/pull/15#discussion_r79324253","pull_request_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/pulls/15","_links":{"self":{"href":"https://api.github.com/repos/otavanopisto/kunta-api-www/pulls/comments/79324253"},"html":{"href":"https://github.com/otavanopisto/kunta-api-www/pull/15#discussion_r79324253"},"pull_request":{"href":"https://api.github.com/repos/otavanopisto/kunta-api-www/pulls/15"}}},"pull_request":{"url":"https://api.github.com/repos/otavanopisto/kunta-api-www/pulls/15","id":85733909,"html_url":"https://github.com/otavanopisto/kunta-api-www/pull/15","diff_url":"https://github.com/otavanopisto/kunta-api-www/pull/15.diff","patch_url":"https://github.com/otavanopisto/kunta-api-www/pull/15.patch","issue_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/issues/15","number":15,"state":"open","locked":false,"title":"Feature #14 social media","user":{"login":"anttileppa","id":1730736,"avatar_url":"https://avatars.githubusercontent.com/u/1730736?v=3","gravatar_id":"","url":"https://api.github.com/users/anttileppa","html_url":"https://github.com/anttileppa","followers_url":"https://api.github.com/users/anttileppa/followers","following_url":"https://api.github.com/users/anttileppa/following{/other_user}","gists_url":"https://api.github.com/users/anttileppa/gists{/gist_id}","starred_url":"https://api.github.com/users/anttileppa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anttileppa/subscriptions","organizations_url":"https://api.github.com/users/anttileppa/orgs","repos_url":"https://api.github.com/users/anttileppa/repos","events_url":"https://api.github.com/users/anttileppa/events{/privacy}","received_events_url":"https://api.github.com/users/anttileppa/received_events","type":"User","site_admin":false},"body":"Resolves #14 ","created_at":"2016-09-19T03:13:24Z","updated_at":"2016-09-19T03:13:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c8cf83fbc570d2fdc1ce56df8ae014a71e2b304a","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/pulls/15/commits","review_comments_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/pulls/15/comments","review_comment_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/pulls/comments{/number}","comments_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/issues/15/comments","statuses_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/statuses/30ce122da10eeb6677346d957d811f82936f60ad","head":{"label":"otavanopisto:feature-#14-social-media","ref":"feature-#14-social-media","sha":"30ce122da10eeb6677346d957d811f82936f60ad","user":{"login":"otavanopisto","id":3909061,"avatar_url":"https://avatars.githubusercontent.com/u/3909061?v=3","gravatar_id":"","url":"https://api.github.com/users/otavanopisto","html_url":"https://github.com/otavanopisto","followers_url":"https://api.github.com/users/otavanopisto/followers","following_url":"https://api.github.com/users/otavanopisto/following{/other_user}","gists_url":"https://api.github.com/users/otavanopisto/gists{/gist_id}","starred_url":"https://api.github.com/users/otavanopisto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/otavanopisto/subscriptions","organizations_url":"https://api.github.com/users/otavanopisto/orgs","repos_url":"https://api.github.com/users/otavanopisto/repos","events_url":"https://api.github.com/users/otavanopisto/events{/privacy}","received_events_url":"https://api.github.com/users/otavanopisto/received_events","type":"Organization","site_admin":false},"repo":{"id":67469248,"name":"kunta-api-www","full_name":"otavanopisto/kunta-api-www","owner":{"login":"otavanopisto","id":3909061,"avatar_url":"https://avatars.githubusercontent.com/u/3909061?v=3","gravatar_id":"","url":"https://api.github.com/users/otavanopisto","html_url":"https://github.com/otavanopisto","followers_url":"https://api.github.com/users/otavanopisto/followers","following_url":"https://api.github.com/users/otavanopisto/following{/other_user}","gists_url":"https://api.github.com/users/otavanopisto/gists{/gist_id}","starred_url":"https://api.github.com/users/otavanopisto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/otavanopisto/subscriptions","organizations_url":"https://api.github.com/users/otavanopisto/orgs","repos_url":"https://api.github.com/users/otavanopisto/repos","events_url":"https://api.github.com/users/otavanopisto/events{/privacy}","received_events_url":"https://api.github.com/users/otavanopisto/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/otavanopisto/kunta-api-www","description":"Visualization layer of kunta-api","fork":false,"url":"https://api.github.com/repos/otavanopisto/kunta-api-www","forks_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/forks","keys_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/keys{/key_id}","collaborators_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/teams","hooks_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/hooks","issue_events_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/issues/events{/number}","events_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/events","assignees_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/assignees{/user}","branches_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/branches{/branch}","tags_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/tags","blobs_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/git/refs{/sha}","trees_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/git/trees{/sha}","statuses_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/statuses/{sha}","languages_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/languages","stargazers_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/stargazers","contributors_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/contributors","subscribers_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/subscribers","subscription_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/subscription","commits_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/commits{/sha}","git_commits_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/git/commits{/sha}","comments_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/comments{/number}","issue_comment_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/issues/comments{/number}","contents_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/contents/{+path}","compare_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/compare/{base}...{head}","merges_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/merges","archive_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/downloads","issues_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/issues{/number}","pulls_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/pulls{/number}","milestones_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/milestones{/number}","notifications_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/labels{/name}","releases_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/releases{/id}","deployments_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/deployments","created_at":"2016-09-06T03:13:55Z","updated_at":"2016-09-06T09:38:38Z","pushed_at":"2016-09-19T03:13:24Z","git_url":"git://github.com/otavanopisto/kunta-api-www.git","ssh_url":"git@github.com:otavanopisto/kunta-api-www.git","clone_url":"https://github.com/otavanopisto/kunta-api-www.git","svn_url":"https://github.com/otavanopisto/kunta-api-www","homepage":null,"size":170,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"develop"}},"base":{"label":"otavanopisto:develop","ref":"develop","sha":"7d10674d4aa6c36b3d8928cdc0057c74402c2a28","user":{"login":"otavanopisto","id":3909061,"avatar_url":"https://avatars.githubusercontent.com/u/3909061?v=3","gravatar_id":"","url":"https://api.github.com/users/otavanopisto","html_url":"https://github.com/otavanopisto","followers_url":"https://api.github.com/users/otavanopisto/followers","following_url":"https://api.github.com/users/otavanopisto/following{/other_user}","gists_url":"https://api.github.com/users/otavanopisto/gists{/gist_id}","starred_url":"https://api.github.com/users/otavanopisto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/otavanopisto/subscriptions","organizations_url":"https://api.github.com/users/otavanopisto/orgs","repos_url":"https://api.github.com/users/otavanopisto/repos","events_url":"https://api.github.com/users/otavanopisto/events{/privacy}","received_events_url":"https://api.github.com/users/otavanopisto/received_events","type":"Organization","site_admin":false},"repo":{"id":67469248,"name":"kunta-api-www","full_name":"otavanopisto/kunta-api-www","owner":{"login":"otavanopisto","id":3909061,"avatar_url":"https://avatars.githubusercontent.com/u/3909061?v=3","gravatar_id":"","url":"https://api.github.com/users/otavanopisto","html_url":"https://github.com/otavanopisto","followers_url":"https://api.github.com/users/otavanopisto/followers","following_url":"https://api.github.com/users/otavanopisto/following{/other_user}","gists_url":"https://api.github.com/users/otavanopisto/gists{/gist_id}","starred_url":"https://api.github.com/users/otavanopisto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/otavanopisto/subscriptions","organizations_url":"https://api.github.com/users/otavanopisto/orgs","repos_url":"https://api.github.com/users/otavanopisto/repos","events_url":"https://api.github.com/users/otavanopisto/events{/privacy}","received_events_url":"https://api.github.com/users/otavanopisto/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/otavanopisto/kunta-api-www","description":"Visualization layer of kunta-api","fork":false,"url":"https://api.github.com/repos/otavanopisto/kunta-api-www","forks_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/forks","keys_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/keys{/key_id}","collaborators_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/teams","hooks_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/hooks","issue_events_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/issues/events{/number}","events_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/events","assignees_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/assignees{/user}","branches_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/branches{/branch}","tags_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/tags","blobs_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/git/refs{/sha}","trees_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/git/trees{/sha}","statuses_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/statuses/{sha}","languages_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/languages","stargazers_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/stargazers","contributors_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/contributors","subscribers_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/subscribers","subscription_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/subscription","commits_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/commits{/sha}","git_commits_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/git/commits{/sha}","comments_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/comments{/number}","issue_comment_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/issues/comments{/number}","contents_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/contents/{+path}","compare_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/compare/{base}...{head}","merges_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/merges","archive_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/downloads","issues_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/issues{/number}","pulls_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/pulls{/number}","milestones_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/milestones{/number}","notifications_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/labels{/name}","releases_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/releases{/id}","deployments_url":"https://api.github.com/repos/otavanopisto/kunta-api-www/deployments","created_at":"2016-09-06T03:13:55Z","updated_at":"2016-09-06T09:38:38Z","pushed_at":"2016-09-19T03:13:24Z","git_url":"git://github.com/otavanopisto/kunta-api-www.git","ssh_url":"git@github.com:otavanopisto/kunta-api-www.git","clone_url":"https://github.com/otavanopisto/kunta-api-www.git","svn_url":"https://github.com/otavanopisto/kunta-api-www","homepage":null,"size":170,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/otavanopisto/kunta-api-www/pulls/15"},"html":{"href":"https://github.com/otavanopisto/kunta-api-www/pull/15"},"issue":{"href":"https://api.github.com/repos/otavanopisto/kunta-api-www/issues/15"},"comments":{"href":"https://api.github.com/repos/otavanopisto/kunta-api-www/issues/15/comments"},"review_comments":{"href":"https://api.github.com/repos/otavanopisto/kunta-api-www/pulls/15/comments"},"review_comment":{"href":"https://api.github.com/repos/otavanopisto/kunta-api-www/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/otavanopisto/kunta-api-www/pulls/15/commits"},"statuses":{"href":"https://api.github.com/repos/otavanopisto/kunta-api-www/statuses/30ce122da10eeb6677346d957d811f82936f60ad"}}}}
{"actor":{"display_login":"houndci-bot"}}