{"action":"closed","number":37,"pull_request":{"url":"https://api.github.com/repos/AgileVentures/TakeMeAway/pulls/37","id":36089600,"html_url":"https://github.com/AgileVentures/TakeMeAway/pull/37","diff_url":"https://github.com/AgileVentures/TakeMeAway/pull/37.diff","patch_url":"https://github.com/AgileVentures/TakeMeAway/pull/37.patch","issue_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/issues/37","number":37,"state":"closed","locked":false,"title":"API: Client authentication","user":{"login":"razorcd","id":3721810,"avatar_url":"https://avatars.githubusercontent.com/u/3721810?v=3","gravatar_id":"","url":"https://api.github.com/users/razorcd","html_url":"https://github.com/razorcd","followers_url":"https://api.github.com/users/razorcd/followers","following_url":"https://api.github.com/users/razorcd/following{/other_user}","gists_url":"https://api.github.com/users/razorcd/gists{/gist_id}","starred_url":"https://api.github.com/users/razorcd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/razorcd/subscriptions","organizations_url":"https://api.github.com/users/razorcd/orgs","repos_url":"https://api.github.com/users/razorcd/repos","events_url":"https://api.github.com/users/razorcd/events{/privacy}","received_events_url":"https://api.github.com/users/razorcd/received_events","type":"User","site_admin":false},"body":"##### PT story: https://www.pivotaltracker.com/story/show/95179630\r\n**[Not a blocker, but I'd like to see what has been added/refactored within this PR rather than documentation.]**\r\n\r\nRegister:\r\n> `user#create` - will register a new user and return the email and token in the same format that Log_in does.\r\nRequest: `curl -X POST http://localhost:3000/v1/users --data \"name=John&email=user@tma.org&password=password&password_confirmation=password\"`\r\nResponse valid: `{\"user\":{\"name\"=>\"User Name\",\"email\":\"user@tma.org\"},\"authentication_token\":{\"token\":\"weREXP7z3TeaRqyznzrt\"}}`\r\nResponse invalid: `{\"message\":[\"Email has already been taken\"]}`\r\n\r\nLog_in: (generates new token if missing)\r\n>`session#get_token` - will return email and token based on provided credentials (email and password)\r\nRequest: `curl -X POST http://localhost:3000/v1/sessions --data \"email=user@tma.org&password=password\"`\r\nResponse valid: `{\"user\":{\"name\"=>\"User Name\",\"email\":\"user@tma.org\"},\"authentication_token\":{\"token\":\"zJ894PziZMP3yCdaZSSw\"}}`\r\nResponse invalid: `{\"message\":\"Email or password is incorrect\"}`\r\n\r\nLog_out: optional (it is just clearing the stored token)\r\n>`session#clear_token` - will reset the token based on the authorised user (current_user). Can be called on logout with/without waiting for the response.\r\nRequest: `curl -X DELETE http://localhost:3000/v1/sessions -H \"token: c-LXmsFavPiCEBRvchxe\"`\r\nResponse valid: `{\"message\":\"Token successfully cleared\"}`\r\nResponse invalid: `{\"message\":\"Token clear failed\"}`\r\n\r\nEvery authorised request:\r\n>Should have correct headers:\r\n`curl -X GET http://localhost:3000/v1/private_action -H \"token: c-LXmsFavPiCEBRvchxe\"`\r\nOtherwise Response invalid: `{\"message\":\"Access Forbidden\"}`\r\n\r\n`authenticate_api_user` method will check that the request has correct headers['token'] to authorize actions. It is not creating sessions, it is checking token directly from db.\r\nUse on restricted controller actions with:  `before_action :authenticate_api_user, only: [:restricted_action]`\r\nOnce authorized, controllers and views have access to instance var: `current_user` (AR object)\r\nIf authentication fails, the api will return: `{\"message\":\"Access Forbidden\"}`\r\n\r\nPostman link: https://www.getpostman.com/collections/8377c2b915864d6eda84\r\n","created_at":"2015-05-23T16:13:42Z","updated_at":"2015-05-26T11:58:05Z","closed_at":"2015-05-26T11:58:05Z","merged_at":"2015-05-26T11:58:05Z","merge_commit_sha":"3075966ac539ecefccd2ab077e46ed51df0791f0","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/pulls/37/commits","review_comments_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/pulls/37/comments","review_comment_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/pulls/comments{/number}","comments_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/issues/37/comments","statuses_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/statuses/ebb44d619dacab629666fc52b6780f2a69098f5c","head":{"label":"razorcd:client_authentication","ref":"client_authentication","sha":"ebb44d619dacab629666fc52b6780f2a69098f5c","user":{"login":"razorcd","id":3721810,"avatar_url":"https://avatars.githubusercontent.com/u/3721810?v=3","gravatar_id":"","url":"https://api.github.com/users/razorcd","html_url":"https://github.com/razorcd","followers_url":"https://api.github.com/users/razorcd/followers","following_url":"https://api.github.com/users/razorcd/following{/other_user}","gists_url":"https://api.github.com/users/razorcd/gists{/gist_id}","starred_url":"https://api.github.com/users/razorcd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/razorcd/subscriptions","organizations_url":"https://api.github.com/users/razorcd/orgs","repos_url":"https://api.github.com/users/razorcd/repos","events_url":"https://api.github.com/users/razorcd/events{/privacy}","received_events_url":"https://api.github.com/users/razorcd/received_events","type":"User","site_admin":false},"repo":{"id":35181100,"name":"TakeMeAway","full_name":"razorcd/TakeMeAway","owner":{"login":"razorcd","id":3721810,"avatar_url":"https://avatars.githubusercontent.com/u/3721810?v=3","gravatar_id":"","url":"https://api.github.com/users/razorcd","html_url":"https://github.com/razorcd","followers_url":"https://api.github.com/users/razorcd/followers","following_url":"https://api.github.com/users/razorcd/following{/other_user}","gists_url":"https://api.github.com/users/razorcd/gists{/gist_id}","starred_url":"https://api.github.com/users/razorcd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/razorcd/subscriptions","organizations_url":"https://api.github.com/users/razorcd/orgs","repos_url":"https://api.github.com/users/razorcd/repos","events_url":"https://api.github.com/users/razorcd/events{/privacy}","received_events_url":"https://api.github.com/users/razorcd/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/razorcd/TakeMeAway","description":"An online restaurant system to manage take away orders.","fork":true,"url":"https://api.github.com/repos/razorcd/TakeMeAway","forks_url":"https://api.github.com/repos/razorcd/TakeMeAway/forks","keys_url":"https://api.github.com/repos/razorcd/TakeMeAway/keys{/key_id}","collaborators_url":"https://api.github.com/repos/razorcd/TakeMeAway/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/razorcd/TakeMeAway/teams","hooks_url":"https://api.github.com/repos/razorcd/TakeMeAway/hooks","issue_events_url":"https://api.github.com/repos/razorcd/TakeMeAway/issues/events{/number}","events_url":"https://api.github.com/repos/razorcd/TakeMeAway/events","assignees_url":"https://api.github.com/repos/razorcd/TakeMeAway/assignees{/user}","branches_url":"https://api.github.com/repos/razorcd/TakeMeAway/branches{/branch}","tags_url":"https://api.github.com/repos/razorcd/TakeMeAway/tags","blobs_url":"https://api.github.com/repos/razorcd/TakeMeAway/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/razorcd/TakeMeAway/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/razorcd/TakeMeAway/git/refs{/sha}","trees_url":"https://api.github.com/repos/razorcd/TakeMeAway/git/trees{/sha}","statuses_url":"https://api.github.com/repos/razorcd/TakeMeAway/statuses/{sha}","languages_url":"https://api.github.com/repos/razorcd/TakeMeAway/languages","stargazers_url":"https://api.github.com/repos/razorcd/TakeMeAway/stargazers","contributors_url":"https://api.github.com/repos/razorcd/TakeMeAway/contributors","subscribers_url":"https://api.github.com/repos/razorcd/TakeMeAway/subscribers","subscription_url":"https://api.github.com/repos/razorcd/TakeMeAway/subscription","commits_url":"https://api.github.com/repos/razorcd/TakeMeAway/commits{/sha}","git_commits_url":"https://api.github.com/repos/razorcd/TakeMeAway/git/commits{/sha}","comments_url":"https://api.github.com/repos/razorcd/TakeMeAway/comments{/number}","issue_comment_url":"https://api.github.com/repos/razorcd/TakeMeAway/issues/comments{/number}","contents_url":"https://api.github.com/repos/razorcd/TakeMeAway/contents/{+path}","compare_url":"https://api.github.com/repos/razorcd/TakeMeAway/compare/{base}...{head}","merges_url":"https://api.github.com/repos/razorcd/TakeMeAway/merges","archive_url":"https://api.github.com/repos/razorcd/TakeMeAway/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/razorcd/TakeMeAway/downloads","issues_url":"https://api.github.com/repos/razorcd/TakeMeAway/issues{/number}","pulls_url":"https://api.github.com/repos/razorcd/TakeMeAway/pulls{/number}","milestones_url":"https://api.github.com/repos/razorcd/TakeMeAway/milestones{/number}","notifications_url":"https://api.github.com/repos/razorcd/TakeMeAway/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/razorcd/TakeMeAway/labels{/name}","releases_url":"https://api.github.com/repos/razorcd/TakeMeAway/releases{/id}","created_at":"2015-05-06T20:24:51Z","updated_at":"2015-05-06T20:24:51Z","pushed_at":"2015-05-26T08:22:40Z","git_url":"git://github.com/razorcd/TakeMeAway.git","ssh_url":"git@github.com:razorcd/TakeMeAway.git","clone_url":"https://github.com/razorcd/TakeMeAway.git","svn_url":"https://github.com/razorcd/TakeMeAway","homepage":null,"size":303,"stargazers_count":0,"watchers_count":0,"language":"Ruby","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":"develop"}},"base":{"label":"AgileVentures:develop","ref":"develop","sha":"dccfc71dd1bdc1cfdef18ddd34fac8669b9ef89b","user":{"login":"AgileVentures","id":5116968,"avatar_url":"https://avatars.githubusercontent.com/u/5116968?v=3","gravatar_id":"","url":"https://api.github.com/users/AgileVentures","html_url":"https://github.com/AgileVentures","followers_url":"https://api.github.com/users/AgileVentures/followers","following_url":"https://api.github.com/users/AgileVentures/following{/other_user}","gists_url":"https://api.github.com/users/AgileVentures/gists{/gist_id}","starred_url":"https://api.github.com/users/AgileVentures/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AgileVentures/subscriptions","organizations_url":"https://api.github.com/users/AgileVentures/orgs","repos_url":"https://api.github.com/users/AgileVentures/repos","events_url":"https://api.github.com/users/AgileVentures/events{/privacy}","received_events_url":"https://api.github.com/users/AgileVentures/received_events","type":"Organization","site_admin":false},"repo":{"id":33832549,"name":"TakeMeAway","full_name":"AgileVentures/TakeMeAway","owner":{"login":"AgileVentures","id":5116968,"avatar_url":"https://avatars.githubusercontent.com/u/5116968?v=3","gravatar_id":"","url":"https://api.github.com/users/AgileVentures","html_url":"https://github.com/AgileVentures","followers_url":"https://api.github.com/users/AgileVentures/followers","following_url":"https://api.github.com/users/AgileVentures/following{/other_user}","gists_url":"https://api.github.com/users/AgileVentures/gists{/gist_id}","starred_url":"https://api.github.com/users/AgileVentures/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AgileVentures/subscriptions","organizations_url":"https://api.github.com/users/AgileVentures/orgs","repos_url":"https://api.github.com/users/AgileVentures/repos","events_url":"https://api.github.com/users/AgileVentures/events{/privacy}","received_events_url":"https://api.github.com/users/AgileVentures/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/AgileVentures/TakeMeAway","description":"An online restaurant system to manage take away orders.","fork":false,"url":"https://api.github.com/repos/AgileVentures/TakeMeAway","forks_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/forks","keys_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/keys{/key_id}","collaborators_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/teams","hooks_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/hooks","issue_events_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/issues/events{/number}","events_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/events","assignees_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/assignees{/user}","branches_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/branches{/branch}","tags_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/tags","blobs_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/git/refs{/sha}","trees_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/git/trees{/sha}","statuses_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/statuses/{sha}","languages_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/languages","stargazers_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/stargazers","contributors_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/contributors","subscribers_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/subscribers","subscription_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/subscription","commits_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/commits{/sha}","git_commits_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/git/commits{/sha}","comments_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/comments{/number}","issue_comment_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/issues/comments{/number}","contents_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/contents/{+path}","compare_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/compare/{base}...{head}","merges_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/merges","archive_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/downloads","issues_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/issues{/number}","pulls_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/pulls{/number}","milestones_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/milestones{/number}","notifications_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/labels{/name}","releases_url":"https://api.github.com/repos/AgileVentures/TakeMeAway/releases{/id}","created_at":"2015-04-12T20:26:14Z","updated_at":"2015-05-22T21:36:52Z","pushed_at":"2015-05-26T11:58:05Z","git_url":"git://github.com/AgileVentures/TakeMeAway.git","ssh_url":"git@github.com:AgileVentures/TakeMeAway.git","clone_url":"https://github.com/AgileVentures/TakeMeAway.git","svn_url":"https://github.com/AgileVentures/TakeMeAway","homepage":null,"size":906,"stargazers_count":1,"watchers_count":1,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":0,"forks":9,"open_issues":0,"watchers":1,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/AgileVentures/TakeMeAway/pulls/37"},"html":{"href":"https://github.com/AgileVentures/TakeMeAway/pull/37"},"issue":{"href":"https://api.github.com/repos/AgileVentures/TakeMeAway/issues/37"},"comments":{"href":"https://api.github.com/repos/AgileVentures/TakeMeAway/issues/37/comments"},"review_comments":{"href":"https://api.github.com/repos/AgileVentures/TakeMeAway/pulls/37/comments"},"review_comment":{"href":"https://api.github.com/repos/AgileVentures/TakeMeAway/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/AgileVentures/TakeMeAway/pulls/37/commits"},"statuses":{"href":"https://api.github.com/repos/AgileVentures/TakeMeAway/statuses/ebb44d619dacab629666fc52b6780f2a69098f5c"}},"merged":true,"mergeable":null,"mergeable_state":"unknown","merged_by":{"login":"tochman","id":5248170,"avatar_url":"https://avatars.githubusercontent.com/u/5248170?v=3","gravatar_id":"","url":"https://api.github.com/users/tochman","html_url":"https://github.com/tochman","followers_url":"https://api.github.com/users/tochman/followers","following_url":"https://api.github.com/users/tochman/following{/other_user}","gists_url":"https://api.github.com/users/tochman/gists{/gist_id}","starred_url":"https://api.github.com/users/tochman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tochman/subscriptions","organizations_url":"https://api.github.com/users/tochman/orgs","repos_url":"https://api.github.com/users/tochman/repos","events_url":"https://api.github.com/users/tochman/events{/privacy}","received_events_url":"https://api.github.com/users/tochman/received_events","type":"User","site_admin":false},"comments":6,"review_comments":8,"commits":12,"additions":267,"deletions":49,"changed_files":15}}