{"action":"created","comment":{"url":"https://api.github.com/repos/CheshireSwift/BusBoard/pulls/comments/204762292","pull_request_review_id":139898239,"id":204762292,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIwNDc2MjI5Mg==","diff_hunk":"@@ -0,0 +1,75 @@\n+const request = require('request-promise-native');\r\n+const moment = require('moment');\r\n+\r\n+// API Credentials\r\n+const appId = '4586bfa0';\r\n+const appKey = '4236304488967b5683897c8980725377';            \r\n+\r\n+function getBusArrivalJSON(postcode) {\r\n+    \r\n+    return request(`https://api.postcodes.io/postcodes/${postcode}`)\r\n+\r\n+    .then(body => {\r\n+        const postcodeInfoAsJSON = JSON.parse(body);\r\n+        \r\n+        // Extract postcode lat lon\r\n+        const latitude = postcodeInfoAsJSON['result']['latitude'];\r\n+        const longitude = postcodeInfoAsJSON['result']['longitude'];\r\n+        \r\n+        const radius = 1000; \r\n+        const busStopURL = `https://api.tfl.gov.uk/StopPoint?stopTypes=NaptanOnstreetBusCoachStopPair&radius=${radius}&lat=${latitude}&lon=${longitude}`;   \r\n+        return request(busStopURL);\r\n+    })\r\n+    \r\n+    .catch(err => {\r\n+        // Both 404 status rejections and invalid postcodes end up in this catch block\r\n+        if (err.name === 'StatusCodeError') {\r\n+            return Promise.reject('Invalid post code');\r\n+        } else {\r\n+            return Promise.reject('Couldn\\'t reach api.postcodes.io');\r\n+        }\r\n+    })\r\n+\r\n+    .then(body => {\r\n+        const stopPointsAsJSON = JSON.parse(body);\r\n+        let promises = [];\r\n+\r\n+        // Get data from first two closest bus stops\r\n+        stopPointsAsJSON['stopPoints'].slice(0,2).forEach(function(stop) {\r","path":"api-requests.js","position":38,"original_position":38,"commit_id":"82a28a37a7e8faa8fac9ed10569f5eb9166af22c","original_commit_id":"82a28a37a7e8faa8fac9ed10569f5eb9166af22c","user":{"login":"CheshireSwift","id":4071936,"node_id":"MDQ6VXNlcjQwNzE5MzY=","avatar_url":"https://avatars3.githubusercontent.com/u/4071936?v=4","gravatar_id":"","url":"https://api.github.com/users/CheshireSwift","html_url":"https://github.com/CheshireSwift","followers_url":"https://api.github.com/users/CheshireSwift/followers","following_url":"https://api.github.com/users/CheshireSwift/following{/other_user}","gists_url":"https://api.github.com/users/CheshireSwift/gists{/gist_id}","starred_url":"https://api.github.com/users/CheshireSwift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CheshireSwift/subscriptions","organizations_url":"https://api.github.com/users/CheshireSwift/orgs","repos_url":"https://api.github.com/users/CheshireSwift/repos","events_url":"https://api.github.com/users/CheshireSwift/events{/privacy}","received_events_url":"https://api.github.com/users/CheshireSwift/received_events","type":"User","site_admin":false},"body":"```javascript\r\nconst promises = Promise.all(stopPointsAsJSON['stopPoints'].slice(...).map(stop =>\r\n  stop.lineGroup.map({ stopId } =>\r\n    request(`https://...${stopId}...`)\r\n  )\r\n).flat())\r\n```\r\n\r\nLots going on here:\r\n\r\n* Map rather than foreach/push.\r\n* `flat` to turn `[[1, 2], [3, 4]]` into `[1, 2, 3, 4]` (i.e. unwrap the nesting of the arrays).\r\n* Use of implicit return in arrow functions rather than explicit return (does mean losing the `requestURL` variable, so it's debatable whether it's an improvement there).\r\n\r\nI've also mixed and matched property lookup vs dot syntax. The reasoning, roughly speaking, is using lookups on the base response, but dot syntax on everything below that. It's a bit arbitrary though, so up to you (if you wanted absolute consistency, I'd personally favour dots everywhere).","created_at":"2018-07-24T13:48:54Z","updated_at":"2018-07-24T13:48:54Z","html_url":"https://github.com/CheshireSwift/BusBoard/pull/1#discussion_r204762292","pull_request_url":"https://api.github.com/repos/CheshireSwift/BusBoard/pulls/1","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/CheshireSwift/BusBoard/pulls/comments/204762292"},"html":{"href":"https://github.com/CheshireSwift/BusBoard/pull/1#discussion_r204762292"},"pull_request":{"href":"https://api.github.com/repos/CheshireSwift/BusBoard/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/CheshireSwift/BusBoard/pulls/1","id":203518398,"node_id":"MDExOlB1bGxSZXF1ZXN0MjAzNTE4Mzk4","html_url":"https://github.com/CheshireSwift/BusBoard/pull/1","diff_url":"https://github.com/CheshireSwift/BusBoard/pull/1.diff","patch_url":"https://github.com/CheshireSwift/BusBoard/pull/1.patch","issue_url":"https://api.github.com/repos/CheshireSwift/BusBoard/issues/1","number":1,"state":"open","locked":false,"title":"Review","user":{"login":"CheshireSwift","id":4071936,"node_id":"MDQ6VXNlcjQwNzE5MzY=","avatar_url":"https://avatars3.githubusercontent.com/u/4071936?v=4","gravatar_id":"","url":"https://api.github.com/users/CheshireSwift","html_url":"https://github.com/CheshireSwift","followers_url":"https://api.github.com/users/CheshireSwift/followers","following_url":"https://api.github.com/users/CheshireSwift/following{/other_user}","gists_url":"https://api.github.com/users/CheshireSwift/gists{/gist_id}","starred_url":"https://api.github.com/users/CheshireSwift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CheshireSwift/subscriptions","organizations_url":"https://api.github.com/users/CheshireSwift/orgs","repos_url":"https://api.github.com/users/CheshireSwift/repos","events_url":"https://api.github.com/users/CheshireSwift/events{/privacy}","received_events_url":"https://api.github.com/users/CheshireSwift/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-07-24T13:00:41Z","updated_at":"2018-07-24T13:48:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9767d8379943c14bcfc046cd4fca0e45738f4e6d","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/CheshireSwift/BusBoard/pulls/1/commits","review_comments_url":"https://api.github.com/repos/CheshireSwift/BusBoard/pulls/1/comments","review_comment_url":"https://api.github.com/repos/CheshireSwift/BusBoard/pulls/comments{/number}","comments_url":"https://api.github.com/repos/CheshireSwift/BusBoard/issues/1/comments","statuses_url":"https://api.github.com/repos/CheshireSwift/BusBoard/statuses/82a28a37a7e8faa8fac9ed10569f5eb9166af22c","head":{"label":"CheshireSwift:review","ref":"review","sha":"82a28a37a7e8faa8fac9ed10569f5eb9166af22c","user":{"login":"CheshireSwift","id":4071936,"node_id":"MDQ6VXNlcjQwNzE5MzY=","avatar_url":"https://avatars3.githubusercontent.com/u/4071936?v=4","gravatar_id":"","url":"https://api.github.com/users/CheshireSwift","html_url":"https://github.com/CheshireSwift","followers_url":"https://api.github.com/users/CheshireSwift/followers","following_url":"https://api.github.com/users/CheshireSwift/following{/other_user}","gists_url":"https://api.github.com/users/CheshireSwift/gists{/gist_id}","starred_url":"https://api.github.com/users/CheshireSwift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CheshireSwift/subscriptions","organizations_url":"https://api.github.com/users/CheshireSwift/orgs","repos_url":"https://api.github.com/users/CheshireSwift/repos","events_url":"https://api.github.com/users/CheshireSwift/events{/privacy}","received_events_url":"https://api.github.com/users/CheshireSwift/received_events","type":"User","site_admin":false},"repo":{"id":142158493,"node_id":"MDEwOlJlcG9zaXRvcnkxNDIxNTg0OTM=","name":"BusBoard","full_name":"CheshireSwift/BusBoard","owner":{"login":"CheshireSwift","id":4071936,"node_id":"MDQ6VXNlcjQwNzE5MzY=","avatar_url":"https://avatars3.githubusercontent.com/u/4071936?v=4","gravatar_id":"","url":"https://api.github.com/users/CheshireSwift","html_url":"https://github.com/CheshireSwift","followers_url":"https://api.github.com/users/CheshireSwift/followers","following_url":"https://api.github.com/users/CheshireSwift/following{/other_user}","gists_url":"https://api.github.com/users/CheshireSwift/gists{/gist_id}","starred_url":"https://api.github.com/users/CheshireSwift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CheshireSwift/subscriptions","organizations_url":"https://api.github.com/users/CheshireSwift/orgs","repos_url":"https://api.github.com/users/CheshireSwift/repos","events_url":"https://api.github.com/users/CheshireSwift/events{/privacy}","received_events_url":"https://api.github.com/users/CheshireSwift/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/CheshireSwift/BusBoard","description":null,"fork":true,"url":"https://api.github.com/repos/CheshireSwift/BusBoard","forks_url":"https://api.github.com/repos/CheshireSwift/BusBoard/forks","keys_url":"https://api.github.com/repos/CheshireSwift/BusBoard/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CheshireSwift/BusBoard/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CheshireSwift/BusBoard/teams","hooks_url":"https://api.github.com/repos/CheshireSwift/BusBoard/hooks","issue_events_url":"https://api.github.com/repos/CheshireSwift/BusBoard/issues/events{/number}","events_url":"https://api.github.com/repos/CheshireSwift/BusBoard/events","assignees_url":"https://api.github.com/repos/CheshireSwift/BusBoard/assignees{/user}","branches_url":"https://api.github.com/repos/CheshireSwift/BusBoard/branches{/branch}","tags_url":"https://api.github.com/repos/CheshireSwift/BusBoard/tags","blobs_url":"https://api.github.com/repos/CheshireSwift/BusBoard/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CheshireSwift/BusBoard/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CheshireSwift/BusBoard/git/refs{/sha}","trees_url":"https://api.github.com/repos/CheshireSwift/BusBoard/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CheshireSwift/BusBoard/statuses/{sha}","languages_url":"https://api.github.com/repos/CheshireSwift/BusBoard/languages","stargazers_url":"https://api.github.com/repos/CheshireSwift/BusBoard/stargazers","contributors_url":"https://api.github.com/repos/CheshireSwift/BusBoard/contributors","subscribers_url":"https://api.github.com/repos/CheshireSwift/BusBoard/subscribers","subscription_url":"https://api.github.com/repos/CheshireSwift/BusBoard/subscription","commits_url":"https://api.github.com/repos/CheshireSwift/BusBoard/commits{/sha}","git_commits_url":"https://api.github.com/repos/CheshireSwift/BusBoard/git/commits{/sha}","comments_url":"https://api.github.com/repos/CheshireSwift/BusBoard/comments{/number}","issue_comment_url":"https://api.github.com/repos/CheshireSwift/BusBoard/issues/comments{/number}","contents_url":"https://api.github.com/repos/CheshireSwift/BusBoard/contents/{+path}","compare_url":"https://api.github.com/repos/CheshireSwift/BusBoard/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CheshireSwift/BusBoard/merges","archive_url":"https://api.github.com/repos/CheshireSwift/BusBoard/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CheshireSwift/BusBoard/downloads","issues_url":"https://api.github.com/repos/CheshireSwift/BusBoard/issues{/number}","pulls_url":"https://api.github.com/repos/CheshireSwift/BusBoard/pulls{/number}","milestones_url":"https://api.github.com/repos/CheshireSwift/BusBoard/milestones{/number}","notifications_url":"https://api.github.com/repos/CheshireSwift/BusBoard/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CheshireSwift/BusBoard/labels{/name}","releases_url":"https://api.github.com/repos/CheshireSwift/BusBoard/releases{/id}","deployments_url":"https://api.github.com/repos/CheshireSwift/BusBoard/deployments","created_at":"2018-07-24T12:56:19Z","updated_at":"2018-07-24T12:56:21Z","pushed_at":"2018-07-24T13:00:42Z","git_url":"git://github.com/CheshireSwift/BusBoard.git","ssh_url":"git@github.com:CheshireSwift/BusBoard.git","clone_url":"https://github.com/CheshireSwift/BusBoard.git","svn_url":"https://github.com/CheshireSwift/BusBoard","homepage":null,"size":45,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"CheshireSwift:empty","ref":"empty","sha":"025844bbeb6cbcff75e5b92a01894a75f5035151","user":{"login":"CheshireSwift","id":4071936,"node_id":"MDQ6VXNlcjQwNzE5MzY=","avatar_url":"https://avatars3.githubusercontent.com/u/4071936?v=4","gravatar_id":"","url":"https://api.github.com/users/CheshireSwift","html_url":"https://github.com/CheshireSwift","followers_url":"https://api.github.com/users/CheshireSwift/followers","following_url":"https://api.github.com/users/CheshireSwift/following{/other_user}","gists_url":"https://api.github.com/users/CheshireSwift/gists{/gist_id}","starred_url":"https://api.github.com/users/CheshireSwift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CheshireSwift/subscriptions","organizations_url":"https://api.github.com/users/CheshireSwift/orgs","repos_url":"https://api.github.com/users/CheshireSwift/repos","events_url":"https://api.github.com/users/CheshireSwift/events{/privacy}","received_events_url":"https://api.github.com/users/CheshireSwift/received_events","type":"User","site_admin":false},"repo":{"id":142158493,"node_id":"MDEwOlJlcG9zaXRvcnkxNDIxNTg0OTM=","name":"BusBoard","full_name":"CheshireSwift/BusBoard","owner":{"login":"CheshireSwift","id":4071936,"node_id":"MDQ6VXNlcjQwNzE5MzY=","avatar_url":"https://avatars3.githubusercontent.com/u/4071936?v=4","gravatar_id":"","url":"https://api.github.com/users/CheshireSwift","html_url":"https://github.com/CheshireSwift","followers_url":"https://api.github.com/users/CheshireSwift/followers","following_url":"https://api.github.com/users/CheshireSwift/following{/other_user}","gists_url":"https://api.github.com/users/CheshireSwift/gists{/gist_id}","starred_url":"https://api.github.com/users/CheshireSwift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CheshireSwift/subscriptions","organizations_url":"https://api.github.com/users/CheshireSwift/orgs","repos_url":"https://api.github.com/users/CheshireSwift/repos","events_url":"https://api.github.com/users/CheshireSwift/events{/privacy}","received_events_url":"https://api.github.com/users/CheshireSwift/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/CheshireSwift/BusBoard","description":null,"fork":true,"url":"https://api.github.com/repos/CheshireSwift/BusBoard","forks_url":"https://api.github.com/repos/CheshireSwift/BusBoard/forks","keys_url":"https://api.github.com/repos/CheshireSwift/BusBoard/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CheshireSwift/BusBoard/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CheshireSwift/BusBoard/teams","hooks_url":"https://api.github.com/repos/CheshireSwift/BusBoard/hooks","issue_events_url":"https://api.github.com/repos/CheshireSwift/BusBoard/issues/events{/number}","events_url":"https://api.github.com/repos/CheshireSwift/BusBoard/events","assignees_url":"https://api.github.com/repos/CheshireSwift/BusBoard/assignees{/user}","branches_url":"https://api.github.com/repos/CheshireSwift/BusBoard/branches{/branch}","tags_url":"https://api.github.com/repos/CheshireSwift/BusBoard/tags","blobs_url":"https://api.github.com/repos/CheshireSwift/BusBoard/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CheshireSwift/BusBoard/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CheshireSwift/BusBoard/git/refs{/sha}","trees_url":"https://api.github.com/repos/CheshireSwift/BusBoard/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CheshireSwift/BusBoard/statuses/{sha}","languages_url":"https://api.github.com/repos/CheshireSwift/BusBoard/languages","stargazers_url":"https://api.github.com/repos/CheshireSwift/BusBoard/stargazers","contributors_url":"https://api.github.com/repos/CheshireSwift/BusBoard/contributors","subscribers_url":"https://api.github.com/repos/CheshireSwift/BusBoard/subscribers","subscription_url":"https://api.github.com/repos/CheshireSwift/BusBoard/subscription","commits_url":"https://api.github.com/repos/CheshireSwift/BusBoard/commits{/sha}","git_commits_url":"https://api.github.com/repos/CheshireSwift/BusBoard/git/commits{/sha}","comments_url":"https://api.github.com/repos/CheshireSwift/BusBoard/comments{/number}","issue_comment_url":"https://api.github.com/repos/CheshireSwift/BusBoard/issues/comments{/number}","contents_url":"https://api.github.com/repos/CheshireSwift/BusBoard/contents/{+path}","compare_url":"https://api.github.com/repos/CheshireSwift/BusBoard/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CheshireSwift/BusBoard/merges","archive_url":"https://api.github.com/repos/CheshireSwift/BusBoard/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CheshireSwift/BusBoard/downloads","issues_url":"https://api.github.com/repos/CheshireSwift/BusBoard/issues{/number}","pulls_url":"https://api.github.com/repos/CheshireSwift/BusBoard/pulls{/number}","milestones_url":"https://api.github.com/repos/CheshireSwift/BusBoard/milestones{/number}","notifications_url":"https://api.github.com/repos/CheshireSwift/BusBoard/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CheshireSwift/BusBoard/labels{/name}","releases_url":"https://api.github.com/repos/CheshireSwift/BusBoard/releases{/id}","deployments_url":"https://api.github.com/repos/CheshireSwift/BusBoard/deployments","created_at":"2018-07-24T12:56:19Z","updated_at":"2018-07-24T12:56:21Z","pushed_at":"2018-07-24T13:00:42Z","git_url":"git://github.com/CheshireSwift/BusBoard.git","ssh_url":"git@github.com:CheshireSwift/BusBoard.git","clone_url":"https://github.com/CheshireSwift/BusBoard.git","svn_url":"https://github.com/CheshireSwift/BusBoard","homepage":null,"size":45,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/CheshireSwift/BusBoard/pulls/1"},"html":{"href":"https://github.com/CheshireSwift/BusBoard/pull/1"},"issue":{"href":"https://api.github.com/repos/CheshireSwift/BusBoard/issues/1"},"comments":{"href":"https://api.github.com/repos/CheshireSwift/BusBoard/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/CheshireSwift/BusBoard/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/CheshireSwift/BusBoard/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/CheshireSwift/BusBoard/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/CheshireSwift/BusBoard/statuses/82a28a37a7e8faa8fac9ed10569f5eb9166af22c"}},"author_association":"OWNER"}}
{"actor":{"display_login":"CheshireSwift"}}