{"action":"created","comment":{"url":"https://api.github.com/repos/VojtechVitek/go-trello/pulls/comments/47437589","id":47437589,"diff_hunk":"@@ -16,22 +16,107 @@ limitations under the License.\n \n package trello\n \n-import \"net/http\"\n+import (\n+\t\"fmt\"\n+\t\"io/ioutil\"\n+\t\"net/http\"\n+\t\"net/url\"\n+\t\"strings\"\n+)\n \n type Client struct {\n-\t// Auth\n-\n \tclient   *http.Client\n \tendpoint string\n \tversion  string\n }\n \n-func NewClient() (*Client, error) {\n+func (c *Client) do(req *http.Request) ([]byte, error) {\n+\tresp, err := c.client.Do(req)\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\tdefer resp.Body.Close()\n+\n+\tbody, err := ioutil.ReadAll(resp.Body)\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\tif resp.StatusCode != 200 {\n+\t\terr = fmt.Errorf(\"Received unexpected status %d while trying to retrieve the server data with \\\"%s\\\"\", resp.StatusCode, string(body))\n+\t\treturn nil, err\n+\t}\n+\treturn body, nil\n+}\n+\n+func (c *Client) Get(resource string) ([]byte, error) {\n+\treq, err := http.NewRequest(\"GET\", c.endpoint+resource, nil)\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\treturn c.do(req)\n+}\n+\n+func (c *Client) Post(resource string, data url.Values) ([]byte, error) {\n+\treq, err := http.NewRequest(\"POST\", c.endpoint+resource, strings.NewReader(data.Encode()))\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\treq.Header.Set(\"Content-Type\", \"application/x-www-form-urlencoded\")\n+\n+\treturn c.do(req)\n+}\n+\n+func (c *Client) Delete(resource string) ([]byte, error) {\n+\treq, err := http.NewRequest(\"DELETE\", c.endpoint+resource, nil)\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\n+\treturn c.do(req)\n+}\n+\n+type bearerRoundTripper struct {\n+\tDelegate http.RoundTripper\n+\tkey      string\n+\ttoken    string\n+}\n+\n+func (b *bearerRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {\n+\tif b.Delegate == nil {\n+\t\tb.Delegate = http.DefaultTransport\n+\t}\n+\tvalues := req.URL.Query()\n+\tvalues.Add(\"key\", b.key)\n+\tvalues.Add(\"token\", b.token)\n+\treq.URL.RawQuery = values.Encode()\n+\treturn b.Delegate.RoundTrip(req)\n+}\n+\n+// NewBearerTokenTransport will return an http.RoundTripper which will add the\n+// provided application id and token to API calls.\n+//   If Delegate is left unset the http.DefaultTransport will be used.\n+// See https://trello.com/app-key to get your applicationKey\n+// See https://trello.com/1/connect?key=MYKEYFROMABOVE&name=MYAPPNAME&response_type=token&scope=read,write&expiration=1d\n+// to get a read/write token good for 1 day\n+func NewBearerTokenTransport(applicationKey string, token string) *bearerRoundTripper {\n+\treturn &bearerRoundTripper{\n+\t\tkey:   applicationKey,\n+\t\ttoken: token,\n+\t}\n+}\n+\n+// NewClient returns a client needed to make trello API calls. If transport is nil\n+// all API calls will be unauthenticated. If you have a bearer token, NewBearerTokenTransport()\n+// may be helpful in making calls authenticated.\n+func NewClient(transport http.RoundTripper) (*Client, error) {","path":"client.go","position":null,"original_position":100,"commit_id":"d82b45cdc519da1c6271ec98f42ae7b579a50108","original_commit_id":"de1f053a47be28e20ee2b44cba941ab6ea39e8e4","user":{"login":"eparis","id":8093535,"avatar_url":"https://avatars.githubusercontent.com/u/8093535?v=3","gravatar_id":"","url":"https://api.github.com/users/eparis","html_url":"https://github.com/eparis","followers_url":"https://api.github.com/users/eparis/followers","following_url":"https://api.github.com/users/eparis/following{/other_user}","gists_url":"https://api.github.com/users/eparis/gists{/gist_id}","starred_url":"https://api.github.com/users/eparis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eparis/subscriptions","organizations_url":"https://api.github.com/users/eparis/orgs","repos_url":"https://api.github.com/users/eparis/repos","events_url":"https://api.github.com/users/eparis/events{/privacy}","received_events_url":"https://api.github.com/users/eparis/received_events","type":"User","site_admin":false},"body":"Hopefully my latest code meets both of our needs. Arbitrarily stackable and easy to implement trello token auth for people who don't want more transport stacking.","created_at":"2015-12-12T22:26:16Z","updated_at":"2015-12-12T22:26:16Z","html_url":"https://github.com/VojtechVitek/go-trello/pull/6#discussion_r47437589","pull_request_url":"https://api.github.com/repos/VojtechVitek/go-trello/pulls/6","_links":{"self":{"href":"https://api.github.com/repos/VojtechVitek/go-trello/pulls/comments/47437589"},"html":{"href":"https://github.com/VojtechVitek/go-trello/pull/6#discussion_r47437589"},"pull_request":{"href":"https://api.github.com/repos/VojtechVitek/go-trello/pulls/6"}}},"pull_request":{"url":"https://api.github.com/repos/VojtechVitek/go-trello/pulls/6","id":53438367,"html_url":"https://github.com/VojtechVitek/go-trello/pull/6","diff_url":"https://github.com/VojtechVitek/go-trello/pull/6.diff","patch_url":"https://github.com/VojtechVitek/go-trello/pull/6.patch","issue_url":"https://api.github.com/repos/VojtechVitek/go-trello/issues/6","number":6,"state":"open","locked":false,"title":"Ability to modify checklists","user":{"login":"eparis","id":8093535,"avatar_url":"https://avatars.githubusercontent.com/u/8093535?v=3","gravatar_id":"","url":"https://api.github.com/users/eparis","html_url":"https://github.com/eparis","followers_url":"https://api.github.com/users/eparis/followers","following_url":"https://api.github.com/users/eparis/following{/other_user}","gists_url":"https://api.github.com/users/eparis/gists{/gist_id}","starred_url":"https://api.github.com/users/eparis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eparis/subscriptions","organizations_url":"https://api.github.com/users/eparis/orgs","repos_url":"https://api.github.com/users/eparis/repos","events_url":"https://api.github.com/users/eparis/events{/privacy}","received_events_url":"https://api.github.com/users/eparis/received_events","type":"User","site_admin":false},"body":"I needed the ability to manage checklists on cards. This patch implements that. It also implements authentication along the way (as my boards were private)","created_at":"2015-12-11T20:11:04Z","updated_at":"2015-12-12T22:26:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e914a08113743d551b8c7f7fec64e7c692bb96c6","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/VojtechVitek/go-trello/pulls/6/commits","review_comments_url":"https://api.github.com/repos/VojtechVitek/go-trello/pulls/6/comments","review_comment_url":"https://api.github.com/repos/VojtechVitek/go-trello/pulls/comments{/number}","comments_url":"https://api.github.com/repos/VojtechVitek/go-trello/issues/6/comments","statuses_url":"https://api.github.com/repos/VojtechVitek/go-trello/statuses/d82b45cdc519da1c6271ec98f42ae7b579a50108","head":{"label":"eparis:modify-checklists","ref":"modify-checklists","sha":"d82b45cdc519da1c6271ec98f42ae7b579a50108","user":{"login":"eparis","id":8093535,"avatar_url":"https://avatars.githubusercontent.com/u/8093535?v=3","gravatar_id":"","url":"https://api.github.com/users/eparis","html_url":"https://github.com/eparis","followers_url":"https://api.github.com/users/eparis/followers","following_url":"https://api.github.com/users/eparis/following{/other_user}","gists_url":"https://api.github.com/users/eparis/gists{/gist_id}","starred_url":"https://api.github.com/users/eparis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eparis/subscriptions","organizations_url":"https://api.github.com/users/eparis/orgs","repos_url":"https://api.github.com/users/eparis/repos","events_url":"https://api.github.com/users/eparis/events{/privacy}","received_events_url":"https://api.github.com/users/eparis/received_events","type":"User","site_admin":false},"repo":{"id":47781773,"name":"go-trello","full_name":"eparis/go-trello","owner":{"login":"eparis","id":8093535,"avatar_url":"https://avatars.githubusercontent.com/u/8093535?v=3","gravatar_id":"","url":"https://api.github.com/users/eparis","html_url":"https://github.com/eparis","followers_url":"https://api.github.com/users/eparis/followers","following_url":"https://api.github.com/users/eparis/following{/other_user}","gists_url":"https://api.github.com/users/eparis/gists{/gist_id}","starred_url":"https://api.github.com/users/eparis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eparis/subscriptions","organizations_url":"https://api.github.com/users/eparis/orgs","repos_url":"https://api.github.com/users/eparis/repos","events_url":"https://api.github.com/users/eparis/events{/privacy}","received_events_url":"https://api.github.com/users/eparis/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/eparis/go-trello","description":"Go client package for accessing the Trello API","fork":true,"url":"https://api.github.com/repos/eparis/go-trello","forks_url":"https://api.github.com/repos/eparis/go-trello/forks","keys_url":"https://api.github.com/repos/eparis/go-trello/keys{/key_id}","collaborators_url":"https://api.github.com/repos/eparis/go-trello/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/eparis/go-trello/teams","hooks_url":"https://api.github.com/repos/eparis/go-trello/hooks","issue_events_url":"https://api.github.com/repos/eparis/go-trello/issues/events{/number}","events_url":"https://api.github.com/repos/eparis/go-trello/events","assignees_url":"https://api.github.com/repos/eparis/go-trello/assignees{/user}","branches_url":"https://api.github.com/repos/eparis/go-trello/branches{/branch}","tags_url":"https://api.github.com/repos/eparis/go-trello/tags","blobs_url":"https://api.github.com/repos/eparis/go-trello/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/eparis/go-trello/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/eparis/go-trello/git/refs{/sha}","trees_url":"https://api.github.com/repos/eparis/go-trello/git/trees{/sha}","statuses_url":"https://api.github.com/repos/eparis/go-trello/statuses/{sha}","languages_url":"https://api.github.com/repos/eparis/go-trello/languages","stargazers_url":"https://api.github.com/repos/eparis/go-trello/stargazers","contributors_url":"https://api.github.com/repos/eparis/go-trello/contributors","subscribers_url":"https://api.github.com/repos/eparis/go-trello/subscribers","subscription_url":"https://api.github.com/repos/eparis/go-trello/subscription","commits_url":"https://api.github.com/repos/eparis/go-trello/commits{/sha}","git_commits_url":"https://api.github.com/repos/eparis/go-trello/git/commits{/sha}","comments_url":"https://api.github.com/repos/eparis/go-trello/comments{/number}","issue_comment_url":"https://api.github.com/repos/eparis/go-trello/issues/comments{/number}","contents_url":"https://api.github.com/repos/eparis/go-trello/contents/{+path}","compare_url":"https://api.github.com/repos/eparis/go-trello/compare/{base}...{head}","merges_url":"https://api.github.com/repos/eparis/go-trello/merges","archive_url":"https://api.github.com/repos/eparis/go-trello/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/eparis/go-trello/downloads","issues_url":"https://api.github.com/repos/eparis/go-trello/issues{/number}","pulls_url":"https://api.github.com/repos/eparis/go-trello/pulls{/number}","milestones_url":"https://api.github.com/repos/eparis/go-trello/milestones{/number}","notifications_url":"https://api.github.com/repos/eparis/go-trello/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/eparis/go-trello/labels{/name}","releases_url":"https://api.github.com/repos/eparis/go-trello/releases{/id}","created_at":"2015-12-10T19:05:28Z","updated_at":"2015-12-10T19:05:29Z","pushed_at":"2015-12-12T22:24:01Z","git_url":"git://github.com/eparis/go-trello.git","ssh_url":"git@github.com:eparis/go-trello.git","clone_url":"https://github.com/eparis/go-trello.git","svn_url":"https://github.com/eparis/go-trello","homepage":"","size":34,"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":"VojtechVitek:master","ref":"master","sha":"8ad967527441bce55fff4ed1dc08146849afad53","user":{"login":"VojtechVitek","id":139342,"avatar_url":"https://avatars.githubusercontent.com/u/139342?v=3","gravatar_id":"","url":"https://api.github.com/users/VojtechVitek","html_url":"https://github.com/VojtechVitek","followers_url":"https://api.github.com/users/VojtechVitek/followers","following_url":"https://api.github.com/users/VojtechVitek/following{/other_user}","gists_url":"https://api.github.com/users/VojtechVitek/gists{/gist_id}","starred_url":"https://api.github.com/users/VojtechVitek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/VojtechVitek/subscriptions","organizations_url":"https://api.github.com/users/VojtechVitek/orgs","repos_url":"https://api.github.com/users/VojtechVitek/repos","events_url":"https://api.github.com/users/VojtechVitek/events{/privacy}","received_events_url":"https://api.github.com/users/VojtechVitek/received_events","type":"User","site_admin":false},"repo":{"id":22961617,"name":"go-trello","full_name":"VojtechVitek/go-trello","owner":{"login":"VojtechVitek","id":139342,"avatar_url":"https://avatars.githubusercontent.com/u/139342?v=3","gravatar_id":"","url":"https://api.github.com/users/VojtechVitek","html_url":"https://github.com/VojtechVitek","followers_url":"https://api.github.com/users/VojtechVitek/followers","following_url":"https://api.github.com/users/VojtechVitek/following{/other_user}","gists_url":"https://api.github.com/users/VojtechVitek/gists{/gist_id}","starred_url":"https://api.github.com/users/VojtechVitek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/VojtechVitek/subscriptions","organizations_url":"https://api.github.com/users/VojtechVitek/orgs","repos_url":"https://api.github.com/users/VojtechVitek/repos","events_url":"https://api.github.com/users/VojtechVitek/events{/privacy}","received_events_url":"https://api.github.com/users/VojtechVitek/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/VojtechVitek/go-trello","description":"Go client package for accessing the Trello API","fork":false,"url":"https://api.github.com/repos/VojtechVitek/go-trello","forks_url":"https://api.github.com/repos/VojtechVitek/go-trello/forks","keys_url":"https://api.github.com/repos/VojtechVitek/go-trello/keys{/key_id}","collaborators_url":"https://api.github.com/repos/VojtechVitek/go-trello/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/VojtechVitek/go-trello/teams","hooks_url":"https://api.github.com/repos/VojtechVitek/go-trello/hooks","issue_events_url":"https://api.github.com/repos/VojtechVitek/go-trello/issues/events{/number}","events_url":"https://api.github.com/repos/VojtechVitek/go-trello/events","assignees_url":"https://api.github.com/repos/VojtechVitek/go-trello/assignees{/user}","branches_url":"https://api.github.com/repos/VojtechVitek/go-trello/branches{/branch}","tags_url":"https://api.github.com/repos/VojtechVitek/go-trello/tags","blobs_url":"https://api.github.com/repos/VojtechVitek/go-trello/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/VojtechVitek/go-trello/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/VojtechVitek/go-trello/git/refs{/sha}","trees_url":"https://api.github.com/repos/VojtechVitek/go-trello/git/trees{/sha}","statuses_url":"https://api.github.com/repos/VojtechVitek/go-trello/statuses/{sha}","languages_url":"https://api.github.com/repos/VojtechVitek/go-trello/languages","stargazers_url":"https://api.github.com/repos/VojtechVitek/go-trello/stargazers","contributors_url":"https://api.github.com/repos/VojtechVitek/go-trello/contributors","subscribers_url":"https://api.github.com/repos/VojtechVitek/go-trello/subscribers","subscription_url":"https://api.github.com/repos/VojtechVitek/go-trello/subscription","commits_url":"https://api.github.com/repos/VojtechVitek/go-trello/commits{/sha}","git_commits_url":"https://api.github.com/repos/VojtechVitek/go-trello/git/commits{/sha}","comments_url":"https://api.github.com/repos/VojtechVitek/go-trello/comments{/number}","issue_comment_url":"https://api.github.com/repos/VojtechVitek/go-trello/issues/comments{/number}","contents_url":"https://api.github.com/repos/VojtechVitek/go-trello/contents/{+path}","compare_url":"https://api.github.com/repos/VojtechVitek/go-trello/compare/{base}...{head}","merges_url":"https://api.github.com/repos/VojtechVitek/go-trello/merges","archive_url":"https://api.github.com/repos/VojtechVitek/go-trello/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/VojtechVitek/go-trello/downloads","issues_url":"https://api.github.com/repos/VojtechVitek/go-trello/issues{/number}","pulls_url":"https://api.github.com/repos/VojtechVitek/go-trello/pulls{/number}","milestones_url":"https://api.github.com/repos/VojtechVitek/go-trello/milestones{/number}","notifications_url":"https://api.github.com/repos/VojtechVitek/go-trello/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/VojtechVitek/go-trello/labels{/name}","releases_url":"https://api.github.com/repos/VojtechVitek/go-trello/releases{/id}","created_at":"2014-08-14T16:58:10Z","updated_at":"2015-11-24T11:34:55Z","pushed_at":"2015-12-12T22:24:01Z","git_url":"git://github.com/VojtechVitek/go-trello.git","ssh_url":"git@github.com:VojtechVitek/go-trello.git","clone_url":"https://github.com/VojtechVitek/go-trello.git","svn_url":"https://github.com/VojtechVitek/go-trello","homepage":"","size":346,"stargazers_count":9,"watchers_count":9,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":8,"mirror_url":null,"open_issues_count":3,"forks":8,"open_issues":3,"watchers":9,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/VojtechVitek/go-trello/pulls/6"},"html":{"href":"https://github.com/VojtechVitek/go-trello/pull/6"},"issue":{"href":"https://api.github.com/repos/VojtechVitek/go-trello/issues/6"},"comments":{"href":"https://api.github.com/repos/VojtechVitek/go-trello/issues/6/comments"},"review_comments":{"href":"https://api.github.com/repos/VojtechVitek/go-trello/pulls/6/comments"},"review_comment":{"href":"https://api.github.com/repos/VojtechVitek/go-trello/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/VojtechVitek/go-trello/pulls/6/commits"},"statuses":{"href":"https://api.github.com/repos/VojtechVitek/go-trello/statuses/d82b45cdc519da1c6271ec98f42ae7b579a50108"}}}}