{"action":"created","comment":{"url":"https://api.github.com/repos/ably/ably-go/pulls/comments/30475818","id":30475818,"diff_hunk":"@@ -0,0 +1,263 @@\n+package ably\n+\n+import (\n+\t\"encoding/json\"\n+\t\"errors\"\n+\t\"fmt\"\n+\t\"io\"\n+\t\"net\"\n+\t\"net/http\"\n+\n+\t\"github.com/ably/ably-go/ably/proto\"\n+)\n+\n+func tostatus(code int) int {\n+\tswitch status := code / 100; status {\n+\tcase 400, 401, 403, 404, 405, 500:\n+\t\treturn status\n+\tdefault:\n+\t\treturn 0\n+\t}\n+}\n+\n+// Error describes error returned from Ably API. It always has non-zero error\n+// code. It may contain underlying error value which caused the failure\n+// condition.\n+type Error struct {\n+\tCode   int   // internal error code\n+\tStatus int   // HTTP status code\n+\tErr    error // underlying error responsible for the failure; may be nil\n+}\n+\n+// Error implements builtin error interface.\n+func (err *Error) Error() string {\n+\tif err.Err != nil {\n+\t\treturn err.Err.Error()\n+\t}\n+\treturn errCodeText[err.Code]\n+}\n+\n+func newError(code int, err error) error {\n+\tswitch err := err.(type) {\n+\tcase *Error:\n+\t\treturn err\n+\tcase net.Error:\n+\t\tif err.Timeout() {\n+\t\t\treturn &Error{Code: ErrCodeTimeout, Status: 500, Err: err}\n+\t\t}\n+\t}\n+\treturn &Error{\n+\t\tCode:   code,\n+\t\tStatus: tostatus(code),\n+\t\tErr:    err,\n+\t}\n+}\n+\n+func newErrorf(code int, format string, v ...interface{}) error {\n+\treturn &Error{\n+\t\tCode:   code,\n+\t\tStatus: tostatus(code),\n+\t\tErr:    fmt.Errorf(format, v...),\n+\t}\n+}\n+\n+func newErrorProto(err *proto.Error) error {\n+\tif err == nil {\n+\t\treturn nil\n+\t}\n+\treturn &Error{\n+\t\tCode:   err.Code,\n+\t\tStatus: err.StatusCode,\n+\t\tErr:    errors.New(err.Message),\n+\t}\n+}\n+\n+func checkError(resp *http.Response) error {\n+\tconst maxContentLength = 32 * 1024 // 32 KiB\n+\tif resp.StatusCode/100 < 3 {\n+\t\treturn nil\n+\t}\n+\tn := resp.ContentLength\n+\tif n <= 0 || n >= maxContentLength {\n+\t\tn = maxContentLength\n+\t}\n+\tbody := &proto.Error{}\n+\tif e := json.NewDecoder(io.LimitReader(resp.Body, n)).Decode(body); e != nil {","path":"ably/error.go","position":85,"original_position":85,"commit_id":"98a8dc1d87ad3b8bce92800ffeef58d1e420660f","original_commit_id":"98a8dc1d87ad3b8bce92800ffeef58d1e420660f","user":{"login":"rjeczalik","id":1162017,"avatar_url":"https://avatars.githubusercontent.com/u/1162017?v=3","gravatar_id":"","url":"https://api.github.com/users/rjeczalik","html_url":"https://github.com/rjeczalik","followers_url":"https://api.github.com/users/rjeczalik/followers","following_url":"https://api.github.com/users/rjeczalik/following{/other_user}","gists_url":"https://api.github.com/users/rjeczalik/gists{/gist_id}","starred_url":"https://api.github.com/users/rjeczalik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rjeczalik/subscriptions","organizations_url":"https://api.github.com/users/rjeczalik/orgs","repos_url":"https://api.github.com/users/rjeczalik/repos","events_url":"https://api.github.com/users/rjeczalik/events{/privacy}","received_events_url":"https://api.github.com/users/rjeczalik/received_events","type":"User","site_admin":false},"body":"Done.\r\n\r\nI’ve rewritten to ioutil.ReadAll to simplify implementation so readability does not suffer.\r\n\r\nJust for the record, this does not ask for the length, it uses length if present to preallocate full buffer at-once, falling back to what ioutil.ReadAll does when the ContentLength is unknown.","created_at":"2015-05-17T22:49:49Z","updated_at":"2015-05-17T22:49:49Z","html_url":"https://github.com/ably/ably-go/pull/32#discussion_r30475818","pull_request_url":"https://api.github.com/repos/ably/ably-go/pulls/32","_links":{"self":{"href":"https://api.github.com/repos/ably/ably-go/pulls/comments/30475818"},"html":{"href":"https://github.com/ably/ably-go/pull/32#discussion_r30475818"},"pull_request":{"href":"https://api.github.com/repos/ably/ably-go/pulls/32"}}},"pull_request":{"url":"https://api.github.com/repos/ably/ably-go/pulls/32","id":35300031,"html_url":"https://github.com/ably/ably-go/pull/32","diff_url":"https://github.com/ably/ably-go/pull/32.diff","patch_url":"https://github.com/ably/ably-go/pull/32.patch","issue_url":"https://api.github.com/repos/ably/ably-go/issues/32","number":32,"state":"open","locked":false,"title":"realtime client - first working version","user":{"login":"rjeczalik","id":1162017,"avatar_url":"https://avatars.githubusercontent.com/u/1162017?v=3","gravatar_id":"","url":"https://api.github.com/users/rjeczalik","html_url":"https://github.com/rjeczalik","followers_url":"https://api.github.com/users/rjeczalik/followers","following_url":"https://api.github.com/users/rjeczalik/following{/other_user}","gists_url":"https://api.github.com/users/rjeczalik/gists{/gist_id}","starred_url":"https://api.github.com/users/rjeczalik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rjeczalik/subscriptions","organizations_url":"https://api.github.com/users/rjeczalik/orgs","repos_url":"https://api.github.com/users/rjeczalik/repos","events_url":"https://api.github.com/users/rjeczalik/events{/privacy}","received_events_url":"https://api.github.com/users/rjeczalik/received_events","type":"User","site_admin":false},"body":"The realtime client implements:\r\n\r\n- event emitters for connection channels\r\n- channel: publish, subscribe, unsubscribe with ack/nack confirmation\r\n- message queueing for connection, channels\r\n\r\nStill missing parts:\r\n\r\n1) Close for channel, connection\r\n2) Ping for connection\r\n3) TestRealtimeClient_MultipleClient test (50+ instances)\r\n4) updated README.md with examples + listing current limitations / updated spec validation document\r\n5) handling token expiration / refreshing (due to missing token support on rest side)\r\n6) transport timeouts handling\r\n\r\n@mattheworiordan @kouno Please take a look. This is not final PR so please don't merge yet, I'm going to add also commits for 1), 2) and 3) to this PR.","created_at":"2015-05-13T07:19:16Z","updated_at":"2015-05-17T22:49:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d39f25972319c9f5aa0674b6de6b27a53438e89b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ably/ably-go/pulls/32/commits","review_comments_url":"https://api.github.com/repos/ably/ably-go/pulls/32/comments","review_comment_url":"https://api.github.com/repos/ably/ably-go/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ably/ably-go/issues/32/comments","statuses_url":"https://api.github.com/repos/ably/ably-go/statuses/98a8dc1d87ad3b8bce92800ffeef58d1e420660f","head":{"label":"rjeczalik:devel-realtime","ref":"devel-realtime","sha":"98a8dc1d87ad3b8bce92800ffeef58d1e420660f","user":{"login":"rjeczalik","id":1162017,"avatar_url":"https://avatars.githubusercontent.com/u/1162017?v=3","gravatar_id":"","url":"https://api.github.com/users/rjeczalik","html_url":"https://github.com/rjeczalik","followers_url":"https://api.github.com/users/rjeczalik/followers","following_url":"https://api.github.com/users/rjeczalik/following{/other_user}","gists_url":"https://api.github.com/users/rjeczalik/gists{/gist_id}","starred_url":"https://api.github.com/users/rjeczalik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rjeczalik/subscriptions","organizations_url":"https://api.github.com/users/rjeczalik/orgs","repos_url":"https://api.github.com/users/rjeczalik/repos","events_url":"https://api.github.com/users/rjeczalik/events{/privacy}","received_events_url":"https://api.github.com/users/rjeczalik/received_events","type":"User","site_admin":false},"repo":{"id":33247084,"name":"ably-go","full_name":"rjeczalik/ably-go","owner":{"login":"rjeczalik","id":1162017,"avatar_url":"https://avatars.githubusercontent.com/u/1162017?v=3","gravatar_id":"","url":"https://api.github.com/users/rjeczalik","html_url":"https://github.com/rjeczalik","followers_url":"https://api.github.com/users/rjeczalik/followers","following_url":"https://api.github.com/users/rjeczalik/following{/other_user}","gists_url":"https://api.github.com/users/rjeczalik/gists{/gist_id}","starred_url":"https://api.github.com/users/rjeczalik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rjeczalik/subscriptions","organizations_url":"https://api.github.com/users/rjeczalik/orgs","repos_url":"https://api.github.com/users/rjeczalik/repos","events_url":"https://api.github.com/users/rjeczalik/events{/privacy}","received_events_url":"https://api.github.com/users/rjeczalik/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rjeczalik/ably-go","description":"Go client for Ably real-time messaging service","fork":true,"url":"https://api.github.com/repos/rjeczalik/ably-go","forks_url":"https://api.github.com/repos/rjeczalik/ably-go/forks","keys_url":"https://api.github.com/repos/rjeczalik/ably-go/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rjeczalik/ably-go/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rjeczalik/ably-go/teams","hooks_url":"https://api.github.com/repos/rjeczalik/ably-go/hooks","issue_events_url":"https://api.github.com/repos/rjeczalik/ably-go/issues/events{/number}","events_url":"https://api.github.com/repos/rjeczalik/ably-go/events","assignees_url":"https://api.github.com/repos/rjeczalik/ably-go/assignees{/user}","branches_url":"https://api.github.com/repos/rjeczalik/ably-go/branches{/branch}","tags_url":"https://api.github.com/repos/rjeczalik/ably-go/tags","blobs_url":"https://api.github.com/repos/rjeczalik/ably-go/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rjeczalik/ably-go/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rjeczalik/ably-go/git/refs{/sha}","trees_url":"https://api.github.com/repos/rjeczalik/ably-go/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rjeczalik/ably-go/statuses/{sha}","languages_url":"https://api.github.com/repos/rjeczalik/ably-go/languages","stargazers_url":"https://api.github.com/repos/rjeczalik/ably-go/stargazers","contributors_url":"https://api.github.com/repos/rjeczalik/ably-go/contributors","subscribers_url":"https://api.github.com/repos/rjeczalik/ably-go/subscribers","subscription_url":"https://api.github.com/repos/rjeczalik/ably-go/subscription","commits_url":"https://api.github.com/repos/rjeczalik/ably-go/commits{/sha}","git_commits_url":"https://api.github.com/repos/rjeczalik/ably-go/git/commits{/sha}","comments_url":"https://api.github.com/repos/rjeczalik/ably-go/comments{/number}","issue_comment_url":"https://api.github.com/repos/rjeczalik/ably-go/issues/comments{/number}","contents_url":"https://api.github.com/repos/rjeczalik/ably-go/contents/{+path}","compare_url":"https://api.github.com/repos/rjeczalik/ably-go/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rjeczalik/ably-go/merges","archive_url":"https://api.github.com/repos/rjeczalik/ably-go/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rjeczalik/ably-go/downloads","issues_url":"https://api.github.com/repos/rjeczalik/ably-go/issues{/number}","pulls_url":"https://api.github.com/repos/rjeczalik/ably-go/pulls{/number}","milestones_url":"https://api.github.com/repos/rjeczalik/ably-go/milestones{/number}","notifications_url":"https://api.github.com/repos/rjeczalik/ably-go/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rjeczalik/ably-go/labels{/name}","releases_url":"https://api.github.com/repos/rjeczalik/ably-go/releases{/id}","created_at":"2015-04-01T12:48:55Z","updated_at":"2015-04-28T05:43:39Z","pushed_at":"2015-05-17T08:10:38Z","git_url":"git://github.com/rjeczalik/ably-go.git","ssh_url":"git@github.com:rjeczalik/ably-go.git","clone_url":"https://github.com/rjeczalik/ably-go.git","svn_url":"https://github.com/rjeczalik/ably-go","homepage":"","size":785,"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":"ably:master","ref":"master","sha":"ede32a4edea85b0fc1ff21bc96a8cb2f764bc99d","user":{"login":"ably","id":1859245,"avatar_url":"https://avatars.githubusercontent.com/u/1859245?v=3","gravatar_id":"","url":"https://api.github.com/users/ably","html_url":"https://github.com/ably","followers_url":"https://api.github.com/users/ably/followers","following_url":"https://api.github.com/users/ably/following{/other_user}","gists_url":"https://api.github.com/users/ably/gists{/gist_id}","starred_url":"https://api.github.com/users/ably/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ably/subscriptions","organizations_url":"https://api.github.com/users/ably/orgs","repos_url":"https://api.github.com/users/ably/repos","events_url":"https://api.github.com/users/ably/events{/privacy}","received_events_url":"https://api.github.com/users/ably/received_events","type":"Organization","site_admin":false},"repo":{"id":27377399,"name":"ably-go","full_name":"ably/ably-go","owner":{"login":"ably","id":1859245,"avatar_url":"https://avatars.githubusercontent.com/u/1859245?v=3","gravatar_id":"","url":"https://api.github.com/users/ably","html_url":"https://github.com/ably","followers_url":"https://api.github.com/users/ably/followers","following_url":"https://api.github.com/users/ably/following{/other_user}","gists_url":"https://api.github.com/users/ably/gists{/gist_id}","starred_url":"https://api.github.com/users/ably/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ably/subscriptions","organizations_url":"https://api.github.com/users/ably/orgs","repos_url":"https://api.github.com/users/ably/repos","events_url":"https://api.github.com/users/ably/events{/privacy}","received_events_url":"https://api.github.com/users/ably/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ably/ably-go","description":"Go client for Ably real-time messaging service","fork":false,"url":"https://api.github.com/repos/ably/ably-go","forks_url":"https://api.github.com/repos/ably/ably-go/forks","keys_url":"https://api.github.com/repos/ably/ably-go/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ably/ably-go/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ably/ably-go/teams","hooks_url":"https://api.github.com/repos/ably/ably-go/hooks","issue_events_url":"https://api.github.com/repos/ably/ably-go/issues/events{/number}","events_url":"https://api.github.com/repos/ably/ably-go/events","assignees_url":"https://api.github.com/repos/ably/ably-go/assignees{/user}","branches_url":"https://api.github.com/repos/ably/ably-go/branches{/branch}","tags_url":"https://api.github.com/repos/ably/ably-go/tags","blobs_url":"https://api.github.com/repos/ably/ably-go/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ably/ably-go/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ably/ably-go/git/refs{/sha}","trees_url":"https://api.github.com/repos/ably/ably-go/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ably/ably-go/statuses/{sha}","languages_url":"https://api.github.com/repos/ably/ably-go/languages","stargazers_url":"https://api.github.com/repos/ably/ably-go/stargazers","contributors_url":"https://api.github.com/repos/ably/ably-go/contributors","subscribers_url":"https://api.github.com/repos/ably/ably-go/subscribers","subscription_url":"https://api.github.com/repos/ably/ably-go/subscription","commits_url":"https://api.github.com/repos/ably/ably-go/commits{/sha}","git_commits_url":"https://api.github.com/repos/ably/ably-go/git/commits{/sha}","comments_url":"https://api.github.com/repos/ably/ably-go/comments{/number}","issue_comment_url":"https://api.github.com/repos/ably/ably-go/issues/comments{/number}","contents_url":"https://api.github.com/repos/ably/ably-go/contents/{+path}","compare_url":"https://api.github.com/repos/ably/ably-go/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ably/ably-go/merges","archive_url":"https://api.github.com/repos/ably/ably-go/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ably/ably-go/downloads","issues_url":"https://api.github.com/repos/ably/ably-go/issues{/number}","pulls_url":"https://api.github.com/repos/ably/ably-go/pulls{/number}","milestones_url":"https://api.github.com/repos/ably/ably-go/milestones{/number}","notifications_url":"https://api.github.com/repos/ably/ably-go/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ably/ably-go/labels{/name}","releases_url":"https://api.github.com/repos/ably/ably-go/releases{/id}","created_at":"2014-12-01T11:57:59Z","updated_at":"2015-05-05T09:19:30Z","pushed_at":"2015-05-14T09:39:26Z","git_url":"git://github.com/ably/ably-go.git","ssh_url":"git@github.com:ably/ably-go.git","clone_url":"https://github.com/ably/ably-go.git","svn_url":"https://github.com/ably/ably-go","homepage":null,"size":1135,"stargazers_count":2,"watchers_count":2,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":12,"forks":3,"open_issues":12,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ably/ably-go/pulls/32"},"html":{"href":"https://github.com/ably/ably-go/pull/32"},"issue":{"href":"https://api.github.com/repos/ably/ably-go/issues/32"},"comments":{"href":"https://api.github.com/repos/ably/ably-go/issues/32/comments"},"review_comments":{"href":"https://api.github.com/repos/ably/ably-go/pulls/32/comments"},"review_comment":{"href":"https://api.github.com/repos/ably/ably-go/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ably/ably-go/pulls/32/commits"},"statuses":{"href":"https://api.github.com/repos/ably/ably-go/statuses/98a8dc1d87ad3b8bce92800ffeef58d1e420660f"}}}}