{"action":"created","comment":{"url":"https://api.github.com/repos/nmaggioni/HubGraph/pulls/comments/78294682","id":78294682,"diff_hunk":"@@ -201,48 +232,96 @@ func unauthenticatedGet(pages int, page int, client *http.Client) (GithubEvents,\n \t\t\tTimeout: time.Second * 30,\n \t\t}\n \t}\n-\tr, err := httpClient.Get(\"https://api.github.com/events?page=\" + strconv.Itoa(page))\n+\tr, err := httpClient.Get(url)\n \tif err != nil {\n \t\tlog.Fatalf(\"Error in requesting data from API: %s\", err.Error())\n \t}\n-\tdefer r.Body.Close()\n \n-\tRateLimitSpecs.Limit = parseHeader(r.Header, \"x-ratelimit-limit\")\n-\tRateLimitSpecs.Remaining = parseHeader(r.Header, \"x-ratelimit-remaining\")\n-\tRateLimitSpecs.ResetTimestamp = parseLongHeader(r.Header, \"x-ratelimit-reset\")\n-\tRateLimitSpecs.PollInterval = parseHeader(r.Header, \"x-poll-interval\") * pages\n+\tdefer r.Body.Close()\n \n \tif r.StatusCode == http.StatusNotModified { // (304) No new content\n \t\treturn nil, &APIError{\"no new content\", 304}\n \t} else if r.StatusCode == http.StatusForbidden { // (403) Rate limit reached\n \t\treturn nil, &APIError{\"rate limited\", 403}\n \t}\n \n-\tbody, _ := ioutil.ReadAll(r.Body)\n+\tbody, err := ioutil.ReadAll(r.Body)\n+\n+\tif err != nil {\n+\t\tlog.Fatal(\"Unable to read response body\")\n+\t\treturn nil, err\n+\t}\n+\n+\treturn body, nil\n+}\n+\n+func getGithubEvents(page int, pages int, token string) (GithubEvents, error) {\n+\tvar responseBody []byte\n+\tvar err error\n+\n+\tif token == \"\" {\n+\t\tresponseBody, err =\n+\t\t\tunauthenticatedGet(\"https://api.github.com/events?page=\"+strconv.Itoa(page), nil)\n+\t} else {\n+\t\tresponseBody, err =\n+\t\t\tauthenticatedGet(\"https://api.github.com/events?page=\"+strconv.Itoa(page), token)\n+\t}\n+\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\n \tvar events GithubEvents\n-\tjson.Unmarshal(body, &events)\n+\tjson.Unmarshal(responseBody, &events)\n \n \treturn events, nil\n }\n \n // authenticatedGet performs an authenticated call to the GitHub's API using the user-supplied token.\n // A custom call to `unauthenticatedGet` is made under the hood.\n-func authenticatedGet(pages int, page int, token string) (GithubEvents, error) {\n+func authenticatedGet(url string, token string) ([]byte, error) {\n \tts := oauth2.StaticTokenSource(\n \t\t&oauth2.Token{AccessToken: token},\n \t)\n \ttc := oauth2.NewClient(oauth2.NoContext, ts)\n \n-\treturn unauthenticatedGet(pages, page, tc)\n+\treturn unauthenticatedGet(url, tc)\n }\n \n // GetHubData returns a success/failure boolean (respectively `true`/`false`) along with the marshalled API data.\n // See the `GithubEvents` struct.\n func GetHubData(pages int, page int, token string) (GithubEvents, error) {\n-\tif token != \"\" {\n-\t\treturn authenticatedGet(pages, page, token)\n+\treturn getGithubEvents(pages, page, token)","path":"github.go","position":227,"original_position":227,"commit_id":"d829ec5961cb3afe3277dd27f4b91b7515879d07","original_commit_id":"d829ec5961cb3afe3277dd27f4b91b7515879d07","user":{"login":"nmaggioni","id":3594528,"avatar_url":"https://avatars.githubusercontent.com/u/3594528?v=3","gravatar_id":"","url":"https://api.github.com/users/nmaggioni","html_url":"https://github.com/nmaggioni","followers_url":"https://api.github.com/users/nmaggioni/followers","following_url":"https://api.github.com/users/nmaggioni/following{/other_user}","gists_url":"https://api.github.com/users/nmaggioni/gists{/gist_id}","starred_url":"https://api.github.com/users/nmaggioni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nmaggioni/subscriptions","organizations_url":"https://api.github.com/users/nmaggioni/orgs","repos_url":"https://api.github.com/users/nmaggioni/repos","events_url":"https://api.github.com/users/nmaggioni/events{/privacy}","received_events_url":"https://api.github.com/users/nmaggioni/received_events","type":"User","site_admin":false},"body":"Why moving the whole function's body in another one that takes the same parameters...? `getGithubEvents`'s body should just be here.","created_at":"2016-09-11T12:59:06Z","updated_at":"2016-09-11T12:59:06Z","html_url":"https://github.com/nmaggioni/HubGraph/pull/1#discussion_r78294682","pull_request_url":"https://api.github.com/repos/nmaggioni/HubGraph/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/nmaggioni/HubGraph/pulls/comments/78294682"},"html":{"href":"https://github.com/nmaggioni/HubGraph/pull/1#discussion_r78294682"},"pull_request":{"href":"https://api.github.com/repos/nmaggioni/HubGraph/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/nmaggioni/HubGraph/pulls/1","id":84511978,"html_url":"https://github.com/nmaggioni/HubGraph/pull/1","diff_url":"https://github.com/nmaggioni/HubGraph/pull/1.diff","patch_url":"https://github.com/nmaggioni/HubGraph/pull/1.patch","issue_url":"https://api.github.com/repos/nmaggioni/HubGraph/issues/1","number":1,"state":"open","locked":false,"title":"Added dashboard from web UI","user":{"login":"giovanniberti","id":8624484,"avatar_url":"https://avatars.githubusercontent.com/u/8624484?v=3","gravatar_id":"","url":"https://api.github.com/users/giovanniberti","html_url":"https://github.com/giovanniberti","followers_url":"https://api.github.com/users/giovanniberti/followers","following_url":"https://api.github.com/users/giovanniberti/following{/other_user}","gists_url":"https://api.github.com/users/giovanniberti/gists{/gist_id}","starred_url":"https://api.github.com/users/giovanniberti/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/giovanniberti/subscriptions","organizations_url":"https://api.github.com/users/giovanniberti/orgs","repos_url":"https://api.github.com/users/giovanniberti/repos","events_url":"https://api.github.com/users/giovanniberti/events{/privacy}","received_events_url":"https://api.github.com/users/giovanniberti/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-09-08T16:37:17Z","updated_at":"2016-09-11T12:59:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"311a461497f516098a84530221dd13db5cb9adca","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/nmaggioni/HubGraph/pulls/1/commits","review_comments_url":"https://api.github.com/repos/nmaggioni/HubGraph/pulls/1/comments","review_comment_url":"https://api.github.com/repos/nmaggioni/HubGraph/pulls/comments{/number}","comments_url":"https://api.github.com/repos/nmaggioni/HubGraph/issues/1/comments","statuses_url":"https://api.github.com/repos/nmaggioni/HubGraph/statuses/d829ec5961cb3afe3277dd27f4b91b7515879d07","head":{"label":"giovanniberti:master","ref":"master","sha":"d829ec5961cb3afe3277dd27f4b91b7515879d07","user":{"login":"giovanniberti","id":8624484,"avatar_url":"https://avatars.githubusercontent.com/u/8624484?v=3","gravatar_id":"","url":"https://api.github.com/users/giovanniberti","html_url":"https://github.com/giovanniberti","followers_url":"https://api.github.com/users/giovanniberti/followers","following_url":"https://api.github.com/users/giovanniberti/following{/other_user}","gists_url":"https://api.github.com/users/giovanniberti/gists{/gist_id}","starred_url":"https://api.github.com/users/giovanniberti/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/giovanniberti/subscriptions","organizations_url":"https://api.github.com/users/giovanniberti/orgs","repos_url":"https://api.github.com/users/giovanniberti/repos","events_url":"https://api.github.com/users/giovanniberti/events{/privacy}","received_events_url":"https://api.github.com/users/giovanniberti/received_events","type":"User","site_admin":false},"repo":{"id":67693445,"name":"HubGraph","full_name":"giovanniberti/HubGraph","owner":{"login":"giovanniberti","id":8624484,"avatar_url":"https://avatars.githubusercontent.com/u/8624484?v=3","gravatar_id":"","url":"https://api.github.com/users/giovanniberti","html_url":"https://github.com/giovanniberti","followers_url":"https://api.github.com/users/giovanniberti/followers","following_url":"https://api.github.com/users/giovanniberti/following{/other_user}","gists_url":"https://api.github.com/users/giovanniberti/gists{/gist_id}","starred_url":"https://api.github.com/users/giovanniberti/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/giovanniberti/subscriptions","organizations_url":"https://api.github.com/users/giovanniberti/orgs","repos_url":"https://api.github.com/users/giovanniberti/repos","events_url":"https://api.github.com/users/giovanniberti/events{/privacy}","received_events_url":"https://api.github.com/users/giovanniberti/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/giovanniberti/HubGraph","description":"Grab the latest events from the boring GitHub's API and build an entertaining graph upon them!","fork":true,"url":"https://api.github.com/repos/giovanniberti/HubGraph","forks_url":"https://api.github.com/repos/giovanniberti/HubGraph/forks","keys_url":"https://api.github.com/repos/giovanniberti/HubGraph/keys{/key_id}","collaborators_url":"https://api.github.com/repos/giovanniberti/HubGraph/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/giovanniberti/HubGraph/teams","hooks_url":"https://api.github.com/repos/giovanniberti/HubGraph/hooks","issue_events_url":"https://api.github.com/repos/giovanniberti/HubGraph/issues/events{/number}","events_url":"https://api.github.com/repos/giovanniberti/HubGraph/events","assignees_url":"https://api.github.com/repos/giovanniberti/HubGraph/assignees{/user}","branches_url":"https://api.github.com/repos/giovanniberti/HubGraph/branches{/branch}","tags_url":"https://api.github.com/repos/giovanniberti/HubGraph/tags","blobs_url":"https://api.github.com/repos/giovanniberti/HubGraph/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/giovanniberti/HubGraph/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/giovanniberti/HubGraph/git/refs{/sha}","trees_url":"https://api.github.com/repos/giovanniberti/HubGraph/git/trees{/sha}","statuses_url":"https://api.github.com/repos/giovanniberti/HubGraph/statuses/{sha}","languages_url":"https://api.github.com/repos/giovanniberti/HubGraph/languages","stargazers_url":"https://api.github.com/repos/giovanniberti/HubGraph/stargazers","contributors_url":"https://api.github.com/repos/giovanniberti/HubGraph/contributors","subscribers_url":"https://api.github.com/repos/giovanniberti/HubGraph/subscribers","subscription_url":"https://api.github.com/repos/giovanniberti/HubGraph/subscription","commits_url":"https://api.github.com/repos/giovanniberti/HubGraph/commits{/sha}","git_commits_url":"https://api.github.com/repos/giovanniberti/HubGraph/git/commits{/sha}","comments_url":"https://api.github.com/repos/giovanniberti/HubGraph/comments{/number}","issue_comment_url":"https://api.github.com/repos/giovanniberti/HubGraph/issues/comments{/number}","contents_url":"https://api.github.com/repos/giovanniberti/HubGraph/contents/{+path}","compare_url":"https://api.github.com/repos/giovanniberti/HubGraph/compare/{base}...{head}","merges_url":"https://api.github.com/repos/giovanniberti/HubGraph/merges","archive_url":"https://api.github.com/repos/giovanniberti/HubGraph/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/giovanniberti/HubGraph/downloads","issues_url":"https://api.github.com/repos/giovanniberti/HubGraph/issues{/number}","pulls_url":"https://api.github.com/repos/giovanniberti/HubGraph/pulls{/number}","milestones_url":"https://api.github.com/repos/giovanniberti/HubGraph/milestones{/number}","notifications_url":"https://api.github.com/repos/giovanniberti/HubGraph/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/giovanniberti/HubGraph/labels{/name}","releases_url":"https://api.github.com/repos/giovanniberti/HubGraph/releases{/id}","deployments_url":"https://api.github.com/repos/giovanniberti/HubGraph/deployments","created_at":"2016-09-08T10:31:06Z","updated_at":"2016-09-08T10:31:07Z","pushed_at":"2016-09-11T10:25:20Z","git_url":"git://github.com/giovanniberti/HubGraph.git","ssh_url":"git@github.com:giovanniberti/HubGraph.git","clone_url":"https://github.com/giovanniberti/HubGraph.git","svn_url":"https://github.com/giovanniberti/HubGraph","homepage":"","size":655,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"nmaggioni:master","ref":"master","sha":"62919aa304cec09ad877ce391583a0dd79c47c4e","user":{"login":"nmaggioni","id":3594528,"avatar_url":"https://avatars.githubusercontent.com/u/3594528?v=3","gravatar_id":"","url":"https://api.github.com/users/nmaggioni","html_url":"https://github.com/nmaggioni","followers_url":"https://api.github.com/users/nmaggioni/followers","following_url":"https://api.github.com/users/nmaggioni/following{/other_user}","gists_url":"https://api.github.com/users/nmaggioni/gists{/gist_id}","starred_url":"https://api.github.com/users/nmaggioni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nmaggioni/subscriptions","organizations_url":"https://api.github.com/users/nmaggioni/orgs","repos_url":"https://api.github.com/users/nmaggioni/repos","events_url":"https://api.github.com/users/nmaggioni/events{/privacy}","received_events_url":"https://api.github.com/users/nmaggioni/received_events","type":"User","site_admin":false},"repo":{"id":67655927,"name":"HubGraph","full_name":"nmaggioni/HubGraph","owner":{"login":"nmaggioni","id":3594528,"avatar_url":"https://avatars.githubusercontent.com/u/3594528?v=3","gravatar_id":"","url":"https://api.github.com/users/nmaggioni","html_url":"https://github.com/nmaggioni","followers_url":"https://api.github.com/users/nmaggioni/followers","following_url":"https://api.github.com/users/nmaggioni/following{/other_user}","gists_url":"https://api.github.com/users/nmaggioni/gists{/gist_id}","starred_url":"https://api.github.com/users/nmaggioni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nmaggioni/subscriptions","organizations_url":"https://api.github.com/users/nmaggioni/orgs","repos_url":"https://api.github.com/users/nmaggioni/repos","events_url":"https://api.github.com/users/nmaggioni/events{/privacy}","received_events_url":"https://api.github.com/users/nmaggioni/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nmaggioni/HubGraph","description":"Grab the latest events from the boring GitHub's API and build an entertaining graph upon them!","fork":false,"url":"https://api.github.com/repos/nmaggioni/HubGraph","forks_url":"https://api.github.com/repos/nmaggioni/HubGraph/forks","keys_url":"https://api.github.com/repos/nmaggioni/HubGraph/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nmaggioni/HubGraph/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nmaggioni/HubGraph/teams","hooks_url":"https://api.github.com/repos/nmaggioni/HubGraph/hooks","issue_events_url":"https://api.github.com/repos/nmaggioni/HubGraph/issues/events{/number}","events_url":"https://api.github.com/repos/nmaggioni/HubGraph/events","assignees_url":"https://api.github.com/repos/nmaggioni/HubGraph/assignees{/user}","branches_url":"https://api.github.com/repos/nmaggioni/HubGraph/branches{/branch}","tags_url":"https://api.github.com/repos/nmaggioni/HubGraph/tags","blobs_url":"https://api.github.com/repos/nmaggioni/HubGraph/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nmaggioni/HubGraph/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nmaggioni/HubGraph/git/refs{/sha}","trees_url":"https://api.github.com/repos/nmaggioni/HubGraph/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nmaggioni/HubGraph/statuses/{sha}","languages_url":"https://api.github.com/repos/nmaggioni/HubGraph/languages","stargazers_url":"https://api.github.com/repos/nmaggioni/HubGraph/stargazers","contributors_url":"https://api.github.com/repos/nmaggioni/HubGraph/contributors","subscribers_url":"https://api.github.com/repos/nmaggioni/HubGraph/subscribers","subscription_url":"https://api.github.com/repos/nmaggioni/HubGraph/subscription","commits_url":"https://api.github.com/repos/nmaggioni/HubGraph/commits{/sha}","git_commits_url":"https://api.github.com/repos/nmaggioni/HubGraph/git/commits{/sha}","comments_url":"https://api.github.com/repos/nmaggioni/HubGraph/comments{/number}","issue_comment_url":"https://api.github.com/repos/nmaggioni/HubGraph/issues/comments{/number}","contents_url":"https://api.github.com/repos/nmaggioni/HubGraph/contents/{+path}","compare_url":"https://api.github.com/repos/nmaggioni/HubGraph/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nmaggioni/HubGraph/merges","archive_url":"https://api.github.com/repos/nmaggioni/HubGraph/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nmaggioni/HubGraph/downloads","issues_url":"https://api.github.com/repos/nmaggioni/HubGraph/issues{/number}","pulls_url":"https://api.github.com/repos/nmaggioni/HubGraph/pulls{/number}","milestones_url":"https://api.github.com/repos/nmaggioni/HubGraph/milestones{/number}","notifications_url":"https://api.github.com/repos/nmaggioni/HubGraph/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nmaggioni/HubGraph/labels{/name}","releases_url":"https://api.github.com/repos/nmaggioni/HubGraph/releases{/id}","deployments_url":"https://api.github.com/repos/nmaggioni/HubGraph/deployments","created_at":"2016-09-08T01:11:33Z","updated_at":"2016-09-08T10:31:05Z","pushed_at":"2016-09-11T10:25:21Z","git_url":"git://github.com/nmaggioni/HubGraph.git","ssh_url":"git@github.com:nmaggioni/HubGraph.git","clone_url":"https://github.com/nmaggioni/HubGraph.git","svn_url":"https://github.com/nmaggioni/HubGraph","homepage":"","size":646,"stargazers_count":1,"watchers_count":1,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":2,"forks":1,"open_issues":2,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/nmaggioni/HubGraph/pulls/1"},"html":{"href":"https://github.com/nmaggioni/HubGraph/pull/1"},"issue":{"href":"https://api.github.com/repos/nmaggioni/HubGraph/issues/1"},"comments":{"href":"https://api.github.com/repos/nmaggioni/HubGraph/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/nmaggioni/HubGraph/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/nmaggioni/HubGraph/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/nmaggioni/HubGraph/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/nmaggioni/HubGraph/statuses/d829ec5961cb3afe3277dd27f4b91b7515879d07"}}}}
{"actor":{"display_login":"nmaggioni"}}