{"action":"created","comment":{"url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/pulls/comments/53312235","id":53312235,"diff_hunk":"@@ -4,5 +4,39 @@ module Authentication\n     def token_authenticated?\n       !!@access_token\n     end\n+\n+    def authorization_url\n+      \"https://www.sageone.com/oauth2/auth?response_type=code&client_id=#{@client_id}&redirect_uri=#{redirect_uri}&scope=full_access\"\n+    end\n+\n+    def request_access_token (code)\n+      token_request(\"access_token\", {code: code})\n+    end\n+\n+    def refresh_access_token(refresh_token)\n+      token_request(\"refresh_token\")\n+    end\n+\n+    def token_request(type, options = {})\n+      request = Faraday.new() do |builder|\n+        builder.request :url_encoded\n+        builder.response :json, :content_type => /\\bjson$/\n+        builder.adapter Faraday.default_adapter\n+      end\n+      if type == \"access_token\"\n+         payload = {client_id: @client_id,\n+                      client_secret: @client_secret,\n+                      code: options[:code],\n+                      grant_type: 'authorization_code',\n+                      redirect_uri: @redirect_uri}\n+      elsif type == \"refresh_token\"\n+        payload = {client_id: @client_id,\n+                      client_secret: @client_secret,\n+                      refresh_token: @refresh_token,\n+                      grant_type: 'refresh_token'}\n+      end\n+      json_response = request.post 'https://api.sageone.com/oauth2/token', payload","path":"lib/sageone_sdk/authentication.rb","position":35,"original_position":35,"commit_id":"7f3d70efe2434ff186b542e10007b4b21ce037b6","original_commit_id":"7f3d70efe2434ff186b542e10007b4b21ce037b6","user":{"login":"chrisbarber86","id":145826,"avatar_url":"https://avatars.githubusercontent.com/u/145826?v=3","gravatar_id":"","url":"https://api.github.com/users/chrisbarber86","html_url":"https://github.com/chrisbarber86","followers_url":"https://api.github.com/users/chrisbarber86/followers","following_url":"https://api.github.com/users/chrisbarber86/following{/other_user}","gists_url":"https://api.github.com/users/chrisbarber86/gists{/gist_id}","starred_url":"https://api.github.com/users/chrisbarber86/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrisbarber86/subscriptions","organizations_url":"https://api.github.com/users/chrisbarber86/orgs","repos_url":"https://api.github.com/users/chrisbarber86/repos","events_url":"https://api.github.com/users/chrisbarber86/events{/privacy}","received_events_url":"https://api.github.com/users/chrisbarber86/received_events","type":"User","site_admin":false},"body":"This needs to use `API_ENDPOINT`}}\r\n\r\n```ruby\r\njson_response = request.post \"#{API_ENDPOINT}/oauth2/token\", payload\r\n```","created_at":"2016-02-18T13:22:53Z","updated_at":"2016-02-18T13:22:53Z","html_url":"https://github.com/Sage/sageone_api_ruby_sdk/pull/5#discussion_r53312235","pull_request_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/pulls/5","_links":{"self":{"href":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/pulls/comments/53312235"},"html":{"href":"https://github.com/Sage/sageone_api_ruby_sdk/pull/5#discussion_r53312235"},"pull_request":{"href":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/pulls/5"}}},"pull_request":{"url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/pulls/5","id":59787519,"html_url":"https://github.com/Sage/sageone_api_ruby_sdk/pull/5","diff_url":"https://github.com/Sage/sageone_api_ruby_sdk/pull/5.diff","patch_url":"https://github.com/Sage/sageone_api_ruby_sdk/pull/5.patch","issue_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/issues/5","number":5,"state":"open","locked":false,"title":"Authorisation helper","user":{"login":"Pete-Brown","id":812122,"avatar_url":"https://avatars.githubusercontent.com/u/812122?v=3","gravatar_id":"","url":"https://api.github.com/users/Pete-Brown","html_url":"https://github.com/Pete-Brown","followers_url":"https://api.github.com/users/Pete-Brown/followers","following_url":"https://api.github.com/users/Pete-Brown/following{/other_user}","gists_url":"https://api.github.com/users/Pete-Brown/gists{/gist_id}","starred_url":"https://api.github.com/users/Pete-Brown/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Pete-Brown/subscriptions","organizations_url":"https://api.github.com/users/Pete-Brown/orgs","repos_url":"https://api.github.com/users/Pete-Brown/repos","events_url":"https://api.github.com/users/Pete-Brown/events{/privacy}","received_events_url":"https://api.github.com/users/Pete-Brown/received_events","type":"User","site_admin":false},"body":"Adds methods to generate authorization url, make token requests and make token refresh requests","created_at":"2016-02-18T11:48:27Z","updated_at":"2016-02-18T13:22:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0e7c1864f06bd28ecd2eb95646f42d6350ea99f7","assignee":{"login":"Pete-Brown","id":812122,"avatar_url":"https://avatars.githubusercontent.com/u/812122?v=3","gravatar_id":"","url":"https://api.github.com/users/Pete-Brown","html_url":"https://github.com/Pete-Brown","followers_url":"https://api.github.com/users/Pete-Brown/followers","following_url":"https://api.github.com/users/Pete-Brown/following{/other_user}","gists_url":"https://api.github.com/users/Pete-Brown/gists{/gist_id}","starred_url":"https://api.github.com/users/Pete-Brown/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Pete-Brown/subscriptions","organizations_url":"https://api.github.com/users/Pete-Brown/orgs","repos_url":"https://api.github.com/users/Pete-Brown/repos","events_url":"https://api.github.com/users/Pete-Brown/events{/privacy}","received_events_url":"https://api.github.com/users/Pete-Brown/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/pulls/5/commits","review_comments_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/pulls/5/comments","review_comment_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/issues/5/comments","statuses_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/statuses/7f3d70efe2434ff186b542e10007b4b21ce037b6","head":{"label":"Sage:authorisation-helper","ref":"authorisation-helper","sha":"7f3d70efe2434ff186b542e10007b4b21ce037b6","user":{"login":"Sage","id":24190,"avatar_url":"https://avatars.githubusercontent.com/u/24190?v=3","gravatar_id":"","url":"https://api.github.com/users/Sage","html_url":"https://github.com/Sage","followers_url":"https://api.github.com/users/Sage/followers","following_url":"https://api.github.com/users/Sage/following{/other_user}","gists_url":"https://api.github.com/users/Sage/gists{/gist_id}","starred_url":"https://api.github.com/users/Sage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Sage/subscriptions","organizations_url":"https://api.github.com/users/Sage/orgs","repos_url":"https://api.github.com/users/Sage/repos","events_url":"https://api.github.com/users/Sage/events{/privacy}","received_events_url":"https://api.github.com/users/Sage/received_events","type":"Organization","site_admin":false},"repo":{"id":50499085,"name":"sageone_api_ruby_sdk","full_name":"Sage/sageone_api_ruby_sdk","owner":{"login":"Sage","id":24190,"avatar_url":"https://avatars.githubusercontent.com/u/24190?v=3","gravatar_id":"","url":"https://api.github.com/users/Sage","html_url":"https://github.com/Sage","followers_url":"https://api.github.com/users/Sage/followers","following_url":"https://api.github.com/users/Sage/following{/other_user}","gists_url":"https://api.github.com/users/Sage/gists{/gist_id}","starred_url":"https://api.github.com/users/Sage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Sage/subscriptions","organizations_url":"https://api.github.com/users/Sage/orgs","repos_url":"https://api.github.com/users/Sage/repos","events_url":"https://api.github.com/users/Sage/events{/privacy}","received_events_url":"https://api.github.com/users/Sage/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Sage/sageone_api_ruby_sdk","description":"Sage One API - Ruby SDK","fork":false,"url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk","forks_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/forks","keys_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/teams","hooks_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/hooks","issue_events_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/issues/events{/number}","events_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/events","assignees_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/assignees{/user}","branches_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/branches{/branch}","tags_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/tags","blobs_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/git/refs{/sha}","trees_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/statuses/{sha}","languages_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/languages","stargazers_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/stargazers","contributors_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/contributors","subscribers_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/subscribers","subscription_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/subscription","commits_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/commits{/sha}","git_commits_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/git/commits{/sha}","comments_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/comments{/number}","issue_comment_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/issues/comments{/number}","contents_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/contents/{+path}","compare_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/merges","archive_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/downloads","issues_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/issues{/number}","pulls_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/pulls{/number}","milestones_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/milestones{/number}","notifications_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/labels{/name}","releases_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/releases{/id}","deployments_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/deployments","created_at":"2016-01-27T10:13:54Z","updated_at":"2016-01-29T13:26:55Z","pushed_at":"2016-02-18T11:48:27Z","git_url":"git://github.com/Sage/sageone_api_ruby_sdk.git","ssh_url":"git@github.com:Sage/sageone_api_ruby_sdk.git","clone_url":"https://github.com/Sage/sageone_api_ruby_sdk.git","svn_url":"https://github.com/Sage/sageone_api_ruby_sdk","homepage":"https://developers.sageone.com/","size":134,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":2,"forks":1,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"Sage:master","ref":"master","sha":"06d3a0e00e174fd5d7d60fc5b41afcb0030ef612","user":{"login":"Sage","id":24190,"avatar_url":"https://avatars.githubusercontent.com/u/24190?v=3","gravatar_id":"","url":"https://api.github.com/users/Sage","html_url":"https://github.com/Sage","followers_url":"https://api.github.com/users/Sage/followers","following_url":"https://api.github.com/users/Sage/following{/other_user}","gists_url":"https://api.github.com/users/Sage/gists{/gist_id}","starred_url":"https://api.github.com/users/Sage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Sage/subscriptions","organizations_url":"https://api.github.com/users/Sage/orgs","repos_url":"https://api.github.com/users/Sage/repos","events_url":"https://api.github.com/users/Sage/events{/privacy}","received_events_url":"https://api.github.com/users/Sage/received_events","type":"Organization","site_admin":false},"repo":{"id":50499085,"name":"sageone_api_ruby_sdk","full_name":"Sage/sageone_api_ruby_sdk","owner":{"login":"Sage","id":24190,"avatar_url":"https://avatars.githubusercontent.com/u/24190?v=3","gravatar_id":"","url":"https://api.github.com/users/Sage","html_url":"https://github.com/Sage","followers_url":"https://api.github.com/users/Sage/followers","following_url":"https://api.github.com/users/Sage/following{/other_user}","gists_url":"https://api.github.com/users/Sage/gists{/gist_id}","starred_url":"https://api.github.com/users/Sage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Sage/subscriptions","organizations_url":"https://api.github.com/users/Sage/orgs","repos_url":"https://api.github.com/users/Sage/repos","events_url":"https://api.github.com/users/Sage/events{/privacy}","received_events_url":"https://api.github.com/users/Sage/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Sage/sageone_api_ruby_sdk","description":"Sage One API - Ruby SDK","fork":false,"url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk","forks_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/forks","keys_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/teams","hooks_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/hooks","issue_events_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/issues/events{/number}","events_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/events","assignees_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/assignees{/user}","branches_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/branches{/branch}","tags_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/tags","blobs_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/git/refs{/sha}","trees_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/statuses/{sha}","languages_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/languages","stargazers_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/stargazers","contributors_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/contributors","subscribers_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/subscribers","subscription_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/subscription","commits_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/commits{/sha}","git_commits_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/git/commits{/sha}","comments_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/comments{/number}","issue_comment_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/issues/comments{/number}","contents_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/contents/{+path}","compare_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/merges","archive_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/downloads","issues_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/issues{/number}","pulls_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/pulls{/number}","milestones_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/milestones{/number}","notifications_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/labels{/name}","releases_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/releases{/id}","deployments_url":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/deployments","created_at":"2016-01-27T10:13:54Z","updated_at":"2016-01-29T13:26:55Z","pushed_at":"2016-02-18T11:48:27Z","git_url":"git://github.com/Sage/sageone_api_ruby_sdk.git","ssh_url":"git@github.com:Sage/sageone_api_ruby_sdk.git","clone_url":"https://github.com/Sage/sageone_api_ruby_sdk.git","svn_url":"https://github.com/Sage/sageone_api_ruby_sdk","homepage":"https://developers.sageone.com/","size":134,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":2,"forks":1,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/pulls/5"},"html":{"href":"https://github.com/Sage/sageone_api_ruby_sdk/pull/5"},"issue":{"href":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/issues/5"},"comments":{"href":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/Sage/sageone_api_ruby_sdk/statuses/7f3d70efe2434ff186b542e10007b4b21ce037b6"}}}}