{"action":"created","comment":{"url":"https://api.github.com/repos/iceddev/chromeback/pulls/comments/30925091","id":30925091,"diff_hunk":"@@ -0,0 +1,56 @@\n+'use strict';\n+\n+var _ = require('lodash');\n+\n+function buildApi(newApi, chromeApi){\n+  // Recursively goes down the chrome Api\n+  // First we get all the keys for the level we're on\n+  var keys = _.keysIn(chromeApi);\n+\n+  _.forEach(keys, function(key){\n+    // then we loop over them and assign them\n+    // this first one is just a safety in case of non-objects.\n+    newApi[key] = chromeApi[key];\n+\n+    if(_.isObject(chromeApi[key])){\n+      // If we hit an object we want to go down inside of it\n+      // Cloning it so we recursively call the function again\n+      newApi[key] = buildApi({}, chromeApi[key]);\n+    }\n+\n+    if(_.isFunction(chromeApi[key])){\n+      // Aha! A function here the real fun begins\n+      newApi[key] = _.restParam(function(args){\n+        var lastElement = _.last(args);\n+\n+        if(_.isFunction(lastElement)){\n+          // If the last element of the arguments array is a function we assume it's a callback and remove it\n+          var callback = lastElement;\n+          args.pop();\n+\n+          // Then we replace it with our own function which handles the error cases\n+          var replacementCallback = _.restParam(function(res){\n+            if(chrome.runtime.lastError){\n+              return callback(chrome.runtime.lastError);\n+            } else {\n+              return callback.apply(null, [null].concat(res));\n+            }\n+          });\n+          // Add our new function to the end of the arguments we're going to call the api with.\n+          args.push(replacementCallback);","path":"index.js","position":40,"original_position":40,"commit_id":"b999431a8ca9224dbe885e3287ad9d9c96bbbc2a","original_commit_id":"b999431a8ca9224dbe885e3287ad9d9c96bbbc2a","user":{"login":"phated","id":992373,"avatar_url":"https://avatars.githubusercontent.com/u/992373?v=3","gravatar_id":"","url":"https://api.github.com/users/phated","html_url":"https://github.com/phated","followers_url":"https://api.github.com/users/phated/followers","following_url":"https://api.github.com/users/phated/following{/other_user}","gists_url":"https://api.github.com/users/phated/gists{/gist_id}","starred_url":"https://api.github.com/users/phated/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phated/subscriptions","organizations_url":"https://api.github.com/users/phated/orgs","repos_url":"https://api.github.com/users/phated/repos","events_url":"https://api.github.com/users/phated/events{/privacy}","received_events_url":"https://api.github.com/users/phated/received_events","type":"User","site_admin":false},"body":"you can concat here","created_at":"2015-05-22T19:42:29Z","updated_at":"2015-05-22T19:42:29Z","html_url":"https://github.com/iceddev/chromeback/pull/1#discussion_r30925091","pull_request_url":"https://api.github.com/repos/iceddev/chromeback/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/iceddev/chromeback/pulls/comments/30925091"},"html":{"href":"https://github.com/iceddev/chromeback/pull/1#discussion_r30925091"},"pull_request":{"href":"https://api.github.com/repos/iceddev/chromeback/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/iceddev/chromeback/pulls/1","id":36062605,"html_url":"https://github.com/iceddev/chromeback/pull/1","diff_url":"https://github.com/iceddev/chromeback/pull/1.diff","patch_url":"https://github.com/iceddev/chromeback/pull/1.patch","issue_url":"https://api.github.com/repos/iceddev/chromeback/issues/1","number":1,"state":"open","locked":false,"title":"initial implementation and docs","user":{"login":"warbrett","id":2651110,"avatar_url":"https://avatars.githubusercontent.com/u/2651110?v=3","gravatar_id":"","url":"https://api.github.com/users/warbrett","html_url":"https://github.com/warbrett","followers_url":"https://api.github.com/users/warbrett/followers","following_url":"https://api.github.com/users/warbrett/following{/other_user}","gists_url":"https://api.github.com/users/warbrett/gists{/gist_id}","starred_url":"https://api.github.com/users/warbrett/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/warbrett/subscriptions","organizations_url":"https://api.github.com/users/warbrett/orgs","repos_url":"https://api.github.com/users/warbrett/repos","events_url":"https://api.github.com/users/warbrett/events{/privacy}","received_events_url":"https://api.github.com/users/warbrett/received_events","type":"User","site_admin":false},"body":"Plus stole your author credit :bowtie:\r\n","created_at":"2015-05-22T19:40:24Z","updated_at":"2015-05-22T19:42:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6c6c344dba6d3e7f2c41c06dbfbb04582dc9b8a6","assignee":{"login":"phated","id":992373,"avatar_url":"https://avatars.githubusercontent.com/u/992373?v=3","gravatar_id":"","url":"https://api.github.com/users/phated","html_url":"https://github.com/phated","followers_url":"https://api.github.com/users/phated/followers","following_url":"https://api.github.com/users/phated/following{/other_user}","gists_url":"https://api.github.com/users/phated/gists{/gist_id}","starred_url":"https://api.github.com/users/phated/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phated/subscriptions","organizations_url":"https://api.github.com/users/phated/orgs","repos_url":"https://api.github.com/users/phated/repos","events_url":"https://api.github.com/users/phated/events{/privacy}","received_events_url":"https://api.github.com/users/phated/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/iceddev/chromeback/pulls/1/commits","review_comments_url":"https://api.github.com/repos/iceddev/chromeback/pulls/1/comments","review_comment_url":"https://api.github.com/repos/iceddev/chromeback/pulls/comments{/number}","comments_url":"https://api.github.com/repos/iceddev/chromeback/issues/1/comments","statuses_url":"https://api.github.com/repos/iceddev/chromeback/statuses/b999431a8ca9224dbe885e3287ad9d9c96bbbc2a","head":{"label":"iceddev:initial","ref":"initial","sha":"b999431a8ca9224dbe885e3287ad9d9c96bbbc2a","user":{"login":"iceddev","id":1459970,"avatar_url":"https://avatars.githubusercontent.com/u/1459970?v=3","gravatar_id":"","url":"https://api.github.com/users/iceddev","html_url":"https://github.com/iceddev","followers_url":"https://api.github.com/users/iceddev/followers","following_url":"https://api.github.com/users/iceddev/following{/other_user}","gists_url":"https://api.github.com/users/iceddev/gists{/gist_id}","starred_url":"https://api.github.com/users/iceddev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iceddev/subscriptions","organizations_url":"https://api.github.com/users/iceddev/orgs","repos_url":"https://api.github.com/users/iceddev/repos","events_url":"https://api.github.com/users/iceddev/events{/privacy}","received_events_url":"https://api.github.com/users/iceddev/received_events","type":"Organization","site_admin":false},"repo":{"id":36089316,"name":"chromeback","full_name":"iceddev/chromeback","owner":{"login":"iceddev","id":1459970,"avatar_url":"https://avatars.githubusercontent.com/u/1459970?v=3","gravatar_id":"","url":"https://api.github.com/users/iceddev","html_url":"https://github.com/iceddev","followers_url":"https://api.github.com/users/iceddev/followers","following_url":"https://api.github.com/users/iceddev/following{/other_user}","gists_url":"https://api.github.com/users/iceddev/gists{/gist_id}","starred_url":"https://api.github.com/users/iceddev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iceddev/subscriptions","organizations_url":"https://api.github.com/users/iceddev/orgs","repos_url":"https://api.github.com/users/iceddev/repos","events_url":"https://api.github.com/users/iceddev/events{/privacy}","received_events_url":"https://api.github.com/users/iceddev/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/iceddev/chromeback","description":"Mapping of Chrome APIs to node-style callbacks","fork":false,"url":"https://api.github.com/repos/iceddev/chromeback","forks_url":"https://api.github.com/repos/iceddev/chromeback/forks","keys_url":"https://api.github.com/repos/iceddev/chromeback/keys{/key_id}","collaborators_url":"https://api.github.com/repos/iceddev/chromeback/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/iceddev/chromeback/teams","hooks_url":"https://api.github.com/repos/iceddev/chromeback/hooks","issue_events_url":"https://api.github.com/repos/iceddev/chromeback/issues/events{/number}","events_url":"https://api.github.com/repos/iceddev/chromeback/events","assignees_url":"https://api.github.com/repos/iceddev/chromeback/assignees{/user}","branches_url":"https://api.github.com/repos/iceddev/chromeback/branches{/branch}","tags_url":"https://api.github.com/repos/iceddev/chromeback/tags","blobs_url":"https://api.github.com/repos/iceddev/chromeback/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/iceddev/chromeback/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/iceddev/chromeback/git/refs{/sha}","trees_url":"https://api.github.com/repos/iceddev/chromeback/git/trees{/sha}","statuses_url":"https://api.github.com/repos/iceddev/chromeback/statuses/{sha}","languages_url":"https://api.github.com/repos/iceddev/chromeback/languages","stargazers_url":"https://api.github.com/repos/iceddev/chromeback/stargazers","contributors_url":"https://api.github.com/repos/iceddev/chromeback/contributors","subscribers_url":"https://api.github.com/repos/iceddev/chromeback/subscribers","subscription_url":"https://api.github.com/repos/iceddev/chromeback/subscription","commits_url":"https://api.github.com/repos/iceddev/chromeback/commits{/sha}","git_commits_url":"https://api.github.com/repos/iceddev/chromeback/git/commits{/sha}","comments_url":"https://api.github.com/repos/iceddev/chromeback/comments{/number}","issue_comment_url":"https://api.github.com/repos/iceddev/chromeback/issues/comments{/number}","contents_url":"https://api.github.com/repos/iceddev/chromeback/contents/{+path}","compare_url":"https://api.github.com/repos/iceddev/chromeback/compare/{base}...{head}","merges_url":"https://api.github.com/repos/iceddev/chromeback/merges","archive_url":"https://api.github.com/repos/iceddev/chromeback/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/iceddev/chromeback/downloads","issues_url":"https://api.github.com/repos/iceddev/chromeback/issues{/number}","pulls_url":"https://api.github.com/repos/iceddev/chromeback/pulls{/number}","milestones_url":"https://api.github.com/repos/iceddev/chromeback/milestones{/number}","notifications_url":"https://api.github.com/repos/iceddev/chromeback/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/iceddev/chromeback/labels{/name}","releases_url":"https://api.github.com/repos/iceddev/chromeback/releases{/id}","created_at":"2015-05-22T18:43:00Z","updated_at":"2015-05-22T18:43:00Z","pushed_at":"2015-05-22T19:40:24Z","git_url":"git://github.com/iceddev/chromeback.git","ssh_url":"git@github.com:iceddev/chromeback.git","clone_url":"https://github.com/iceddev/chromeback.git","svn_url":"https://github.com/iceddev/chromeback","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"iceddev:master","ref":"master","sha":"43d23dbecefc75d4ce24bd6590db93c390b0f59c","user":{"login":"iceddev","id":1459970,"avatar_url":"https://avatars.githubusercontent.com/u/1459970?v=3","gravatar_id":"","url":"https://api.github.com/users/iceddev","html_url":"https://github.com/iceddev","followers_url":"https://api.github.com/users/iceddev/followers","following_url":"https://api.github.com/users/iceddev/following{/other_user}","gists_url":"https://api.github.com/users/iceddev/gists{/gist_id}","starred_url":"https://api.github.com/users/iceddev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iceddev/subscriptions","organizations_url":"https://api.github.com/users/iceddev/orgs","repos_url":"https://api.github.com/users/iceddev/repos","events_url":"https://api.github.com/users/iceddev/events{/privacy}","received_events_url":"https://api.github.com/users/iceddev/received_events","type":"Organization","site_admin":false},"repo":{"id":36089316,"name":"chromeback","full_name":"iceddev/chromeback","owner":{"login":"iceddev","id":1459970,"avatar_url":"https://avatars.githubusercontent.com/u/1459970?v=3","gravatar_id":"","url":"https://api.github.com/users/iceddev","html_url":"https://github.com/iceddev","followers_url":"https://api.github.com/users/iceddev/followers","following_url":"https://api.github.com/users/iceddev/following{/other_user}","gists_url":"https://api.github.com/users/iceddev/gists{/gist_id}","starred_url":"https://api.github.com/users/iceddev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iceddev/subscriptions","organizations_url":"https://api.github.com/users/iceddev/orgs","repos_url":"https://api.github.com/users/iceddev/repos","events_url":"https://api.github.com/users/iceddev/events{/privacy}","received_events_url":"https://api.github.com/users/iceddev/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/iceddev/chromeback","description":"Mapping of Chrome APIs to node-style callbacks","fork":false,"url":"https://api.github.com/repos/iceddev/chromeback","forks_url":"https://api.github.com/repos/iceddev/chromeback/forks","keys_url":"https://api.github.com/repos/iceddev/chromeback/keys{/key_id}","collaborators_url":"https://api.github.com/repos/iceddev/chromeback/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/iceddev/chromeback/teams","hooks_url":"https://api.github.com/repos/iceddev/chromeback/hooks","issue_events_url":"https://api.github.com/repos/iceddev/chromeback/issues/events{/number}","events_url":"https://api.github.com/repos/iceddev/chromeback/events","assignees_url":"https://api.github.com/repos/iceddev/chromeback/assignees{/user}","branches_url":"https://api.github.com/repos/iceddev/chromeback/branches{/branch}","tags_url":"https://api.github.com/repos/iceddev/chromeback/tags","blobs_url":"https://api.github.com/repos/iceddev/chromeback/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/iceddev/chromeback/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/iceddev/chromeback/git/refs{/sha}","trees_url":"https://api.github.com/repos/iceddev/chromeback/git/trees{/sha}","statuses_url":"https://api.github.com/repos/iceddev/chromeback/statuses/{sha}","languages_url":"https://api.github.com/repos/iceddev/chromeback/languages","stargazers_url":"https://api.github.com/repos/iceddev/chromeback/stargazers","contributors_url":"https://api.github.com/repos/iceddev/chromeback/contributors","subscribers_url":"https://api.github.com/repos/iceddev/chromeback/subscribers","subscription_url":"https://api.github.com/repos/iceddev/chromeback/subscription","commits_url":"https://api.github.com/repos/iceddev/chromeback/commits{/sha}","git_commits_url":"https://api.github.com/repos/iceddev/chromeback/git/commits{/sha}","comments_url":"https://api.github.com/repos/iceddev/chromeback/comments{/number}","issue_comment_url":"https://api.github.com/repos/iceddev/chromeback/issues/comments{/number}","contents_url":"https://api.github.com/repos/iceddev/chromeback/contents/{+path}","compare_url":"https://api.github.com/repos/iceddev/chromeback/compare/{base}...{head}","merges_url":"https://api.github.com/repos/iceddev/chromeback/merges","archive_url":"https://api.github.com/repos/iceddev/chromeback/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/iceddev/chromeback/downloads","issues_url":"https://api.github.com/repos/iceddev/chromeback/issues{/number}","pulls_url":"https://api.github.com/repos/iceddev/chromeback/pulls{/number}","milestones_url":"https://api.github.com/repos/iceddev/chromeback/milestones{/number}","notifications_url":"https://api.github.com/repos/iceddev/chromeback/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/iceddev/chromeback/labels{/name}","releases_url":"https://api.github.com/repos/iceddev/chromeback/releases{/id}","created_at":"2015-05-22T18:43:00Z","updated_at":"2015-05-22T18:43:00Z","pushed_at":"2015-05-22T19:40:24Z","git_url":"git://github.com/iceddev/chromeback.git","ssh_url":"git@github.com:iceddev/chromeback.git","clone_url":"https://github.com/iceddev/chromeback.git","svn_url":"https://github.com/iceddev/chromeback","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/iceddev/chromeback/pulls/1"},"html":{"href":"https://github.com/iceddev/chromeback/pull/1"},"issue":{"href":"https://api.github.com/repos/iceddev/chromeback/issues/1"},"comments":{"href":"https://api.github.com/repos/iceddev/chromeback/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/iceddev/chromeback/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/iceddev/chromeback/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/iceddev/chromeback/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/iceddev/chromeback/statuses/b999431a8ca9224dbe885e3287ad9d9c96bbbc2a"}}}}