{"action":"created","comment":{"url":"https://api.github.com/repos/andela-cdaniel/xtrim/pulls/comments/43580815","id":43580815,"diff_hunk":"@@ -0,0 +1,130 @@\n+module LinkAuth\n+  extend ActiveSupport::Concerns\n+\n+  def user_params\n+    params.require(:link).permit(:given_url, :short_url, :user_id)\n+  end\n+\n+  def url\n+    prepend_protocol_if_missing(user_params[:given_url])\n+  end\n+\n+  def slug\n+    user_params[:short_url]\n+  end\n+\n+  def id\n+    user_params[:user_id]\n+  end\n+\n+  def link\n+    Link.new(given_url: url, user_id: id)\n+  end\n+\n+  def new_link?\n+    Link.where(given_url: url).where(user_id: id).blank?\n+  end\n+\n+  def new_link_with_slug?\n+    Link.where(short_url: slug).blank?\n+  end\n+\n+  def pluck_slug\n+    Link.where(given_url: url).pluck(:short_url).join\n+  end\n+\n+  def prepend_protocol_if_missing(url)\n+    simplified_url = url.split('www.').join\n+    return simplified_url unless simplified_url.split(':')[1].nil?\n+    \"http://#{simplified_url}\"\n+  end\n+\n+  def link_manager_user\n+    if slug.blank?\n+      handle_no_slug_given\n+    else\n+      handle_slug_given\n+    end\n+  end\n+\n+  def handle_no_slug_given\n+    if new_link?\n+      link.save ? \n+                flash_and_redirect(:alert, \"Link saved\", dashboard_path) :\n+                flash_and_redirect(:alert, \"An error occurred\", dashboard_path)\n+    else\n+      flash_and_redirect(:alert, \"Link exists\", dashboard_path)\n+    end\n+  end\n+\n+  def handle_slug_given\n+    if new_link_with_slug?\n+      new_link = link\n+      if new_link.save\n+        new_link.update_attribute(:short_url, slug)\n+        flash_and_redirect(:alert, \"New link with custom keyword saved\", dashboard_path)\n+      end\n+    else\n+      flash_and_redirect(:alert, \"Keyword already exists\", dashboard_path)\n+    end\n+  end\n+\n+  def link_manager_anon\n+    if new_link?\n+      new_link = link\n+      new_link.save ?\n+        flash_and_redirect(:short_url, new_link.short_url, preview_path) :\n+        flash_and_redirect(:alert, \"An error occurred\", root_path)\n+    else\n+      flash_and_redirect(:existing_link, pluck_slug, preview_path)\n+    end\n+  end\n+end\n+\n+# url = prepend_protocol_if_missing(params[:link][:given_url])\n+    # slug = params[:link][:short_url]\n+    # id = params[:link][:user_id]\n+\n+    # is_existing_link = Link.where(\"given_url = ?\", url).where(\"user_id = ?\", id)\n+    # is_existing_slug = Link.where(\"given_url = ?\", url).where(\"short_url = ?\", slug).where(\"user_id = ?\", id)","path":"app/controllers/concerns/link_auth.rb","position":89,"original_position":89,"commit_id":"c968b8c6f8cd0714e5608413ccf3a8911e57a0a2","original_commit_id":"c968b8c6f8cd0714e5608413ccf3a8911e57a0a2","user":{"login":"houndci","id":6697940,"avatar_url":"https://avatars.githubusercontent.com/u/6697940?v=3","gravatar_id":"","url":"https://api.github.com/users/houndci","html_url":"https://github.com/houndci","followers_url":"https://api.github.com/users/houndci/followers","following_url":"https://api.github.com/users/houndci/following{/other_user}","gists_url":"https://api.github.com/users/houndci/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci/subscriptions","organizations_url":"https://api.github.com/users/houndci/orgs","repos_url":"https://api.github.com/users/houndci/repos","events_url":"https://api.github.com/users/houndci/events{/privacy}","received_events_url":"https://api.github.com/users/houndci/received_events","type":"User","site_admin":false},"body":"Line is too long. [111/80]<br>Incorrect indentation detected (column 4 instead of 2).","created_at":"2015-11-01T09:51:47Z","updated_at":"2015-11-01T09:51:47Z","html_url":"https://github.com/andela-cdaniel/xtrim/pull/12#discussion_r43580815","pull_request_url":"https://api.github.com/repos/andela-cdaniel/xtrim/pulls/12","_links":{"self":{"href":"https://api.github.com/repos/andela-cdaniel/xtrim/pulls/comments/43580815"},"html":{"href":"https://github.com/andela-cdaniel/xtrim/pull/12#discussion_r43580815"},"pull_request":{"href":"https://api.github.com/repos/andela-cdaniel/xtrim/pulls/12"}}},"pull_request":{"url":"https://api.github.com/repos/andela-cdaniel/xtrim/pulls/12","id":49368860,"html_url":"https://github.com/andela-cdaniel/xtrim/pull/12","diff_url":"https://github.com/andela-cdaniel/xtrim/pull/12.diff","patch_url":"https://github.com/andela-cdaniel/xtrim/pull/12.patch","issue_url":"https://api.github.com/repos/andela-cdaniel/xtrim/issues/12","number":12,"state":"open","locked":false,"title":"Feature/user auth","user":{"login":"andela-cdaniel","id":7131935,"avatar_url":"https://avatars.githubusercontent.com/u/7131935?v=3","gravatar_id":"","url":"https://api.github.com/users/andela-cdaniel","html_url":"https://github.com/andela-cdaniel","followers_url":"https://api.github.com/users/andela-cdaniel/followers","following_url":"https://api.github.com/users/andela-cdaniel/following{/other_user}","gists_url":"https://api.github.com/users/andela-cdaniel/gists{/gist_id}","starred_url":"https://api.github.com/users/andela-cdaniel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andela-cdaniel/subscriptions","organizations_url":"https://api.github.com/users/andela-cdaniel/orgs","repos_url":"https://api.github.com/users/andela-cdaniel/repos","events_url":"https://api.github.com/users/andela-cdaniel/events{/privacy}","received_events_url":"https://api.github.com/users/andela-cdaniel/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-11-01T09:51:42Z","updated_at":"2015-11-01T09:51:48Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1e8abaaf889dae2704307ef20847e88fb54465bd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/andela-cdaniel/xtrim/pulls/12/commits","review_comments_url":"https://api.github.com/repos/andela-cdaniel/xtrim/pulls/12/comments","review_comment_url":"https://api.github.com/repos/andela-cdaniel/xtrim/pulls/comments{/number}","comments_url":"https://api.github.com/repos/andela-cdaniel/xtrim/issues/12/comments","statuses_url":"https://api.github.com/repos/andela-cdaniel/xtrim/statuses/c968b8c6f8cd0714e5608413ccf3a8911e57a0a2","head":{"label":"andela-cdaniel:feature/user-auth","ref":"feature/user-auth","sha":"c968b8c6f8cd0714e5608413ccf3a8911e57a0a2","user":{"login":"andela-cdaniel","id":7131935,"avatar_url":"https://avatars.githubusercontent.com/u/7131935?v=3","gravatar_id":"","url":"https://api.github.com/users/andela-cdaniel","html_url":"https://github.com/andela-cdaniel","followers_url":"https://api.github.com/users/andela-cdaniel/followers","following_url":"https://api.github.com/users/andela-cdaniel/following{/other_user}","gists_url":"https://api.github.com/users/andela-cdaniel/gists{/gist_id}","starred_url":"https://api.github.com/users/andela-cdaniel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andela-cdaniel/subscriptions","organizations_url":"https://api.github.com/users/andela-cdaniel/orgs","repos_url":"https://api.github.com/users/andela-cdaniel/repos","events_url":"https://api.github.com/users/andela-cdaniel/events{/privacy}","received_events_url":"https://api.github.com/users/andela-cdaniel/received_events","type":"User","site_admin":false},"repo":{"id":44548183,"name":"xtrim","full_name":"andela-cdaniel/xtrim","owner":{"login":"andela-cdaniel","id":7131935,"avatar_url":"https://avatars.githubusercontent.com/u/7131935?v=3","gravatar_id":"","url":"https://api.github.com/users/andela-cdaniel","html_url":"https://github.com/andela-cdaniel","followers_url":"https://api.github.com/users/andela-cdaniel/followers","following_url":"https://api.github.com/users/andela-cdaniel/following{/other_user}","gists_url":"https://api.github.com/users/andela-cdaniel/gists{/gist_id}","starred_url":"https://api.github.com/users/andela-cdaniel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andela-cdaniel/subscriptions","organizations_url":"https://api.github.com/users/andela-cdaniel/orgs","repos_url":"https://api.github.com/users/andela-cdaniel/repos","events_url":"https://api.github.com/users/andela-cdaniel/events{/privacy}","received_events_url":"https://api.github.com/users/andela-cdaniel/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/andela-cdaniel/xtrim","description":"","fork":false,"url":"https://api.github.com/repos/andela-cdaniel/xtrim","forks_url":"https://api.github.com/repos/andela-cdaniel/xtrim/forks","keys_url":"https://api.github.com/repos/andela-cdaniel/xtrim/keys{/key_id}","collaborators_url":"https://api.github.com/repos/andela-cdaniel/xtrim/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/andela-cdaniel/xtrim/teams","hooks_url":"https://api.github.com/repos/andela-cdaniel/xtrim/hooks","issue_events_url":"https://api.github.com/repos/andela-cdaniel/xtrim/issues/events{/number}","events_url":"https://api.github.com/repos/andela-cdaniel/xtrim/events","assignees_url":"https://api.github.com/repos/andela-cdaniel/xtrim/assignees{/user}","branches_url":"https://api.github.com/repos/andela-cdaniel/xtrim/branches{/branch}","tags_url":"https://api.github.com/repos/andela-cdaniel/xtrim/tags","blobs_url":"https://api.github.com/repos/andela-cdaniel/xtrim/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/andela-cdaniel/xtrim/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/andela-cdaniel/xtrim/git/refs{/sha}","trees_url":"https://api.github.com/repos/andela-cdaniel/xtrim/git/trees{/sha}","statuses_url":"https://api.github.com/repos/andela-cdaniel/xtrim/statuses/{sha}","languages_url":"https://api.github.com/repos/andela-cdaniel/xtrim/languages","stargazers_url":"https://api.github.com/repos/andela-cdaniel/xtrim/stargazers","contributors_url":"https://api.github.com/repos/andela-cdaniel/xtrim/contributors","subscribers_url":"https://api.github.com/repos/andela-cdaniel/xtrim/subscribers","subscription_url":"https://api.github.com/repos/andela-cdaniel/xtrim/subscription","commits_url":"https://api.github.com/repos/andela-cdaniel/xtrim/commits{/sha}","git_commits_url":"https://api.github.com/repos/andela-cdaniel/xtrim/git/commits{/sha}","comments_url":"https://api.github.com/repos/andela-cdaniel/xtrim/comments{/number}","issue_comment_url":"https://api.github.com/repos/andela-cdaniel/xtrim/issues/comments{/number}","contents_url":"https://api.github.com/repos/andela-cdaniel/xtrim/contents/{+path}","compare_url":"https://api.github.com/repos/andela-cdaniel/xtrim/compare/{base}...{head}","merges_url":"https://api.github.com/repos/andela-cdaniel/xtrim/merges","archive_url":"https://api.github.com/repos/andela-cdaniel/xtrim/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/andela-cdaniel/xtrim/downloads","issues_url":"https://api.github.com/repos/andela-cdaniel/xtrim/issues{/number}","pulls_url":"https://api.github.com/repos/andela-cdaniel/xtrim/pulls{/number}","milestones_url":"https://api.github.com/repos/andela-cdaniel/xtrim/milestones{/number}","notifications_url":"https://api.github.com/repos/andela-cdaniel/xtrim/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/andela-cdaniel/xtrim/labels{/name}","releases_url":"https://api.github.com/repos/andela-cdaniel/xtrim/releases{/id}","created_at":"2015-10-19T16:27:01Z","updated_at":"2015-10-23T12:26:16Z","pushed_at":"2015-11-01T09:51:42Z","git_url":"git://github.com/andela-cdaniel/xtrim.git","ssh_url":"git@github.com:andela-cdaniel/xtrim.git","clone_url":"https://github.com/andela-cdaniel/xtrim.git","svn_url":"https://github.com/andela-cdaniel/xtrim","homepage":null,"size":17620,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"andela-cdaniel:master","ref":"master","sha":"9d09dae4b9555fb8324dd6a61e8fbfc0de98fd98","user":{"login":"andela-cdaniel","id":7131935,"avatar_url":"https://avatars.githubusercontent.com/u/7131935?v=3","gravatar_id":"","url":"https://api.github.com/users/andela-cdaniel","html_url":"https://github.com/andela-cdaniel","followers_url":"https://api.github.com/users/andela-cdaniel/followers","following_url":"https://api.github.com/users/andela-cdaniel/following{/other_user}","gists_url":"https://api.github.com/users/andela-cdaniel/gists{/gist_id}","starred_url":"https://api.github.com/users/andela-cdaniel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andela-cdaniel/subscriptions","organizations_url":"https://api.github.com/users/andela-cdaniel/orgs","repos_url":"https://api.github.com/users/andela-cdaniel/repos","events_url":"https://api.github.com/users/andela-cdaniel/events{/privacy}","received_events_url":"https://api.github.com/users/andela-cdaniel/received_events","type":"User","site_admin":false},"repo":{"id":44548183,"name":"xtrim","full_name":"andela-cdaniel/xtrim","owner":{"login":"andela-cdaniel","id":7131935,"avatar_url":"https://avatars.githubusercontent.com/u/7131935?v=3","gravatar_id":"","url":"https://api.github.com/users/andela-cdaniel","html_url":"https://github.com/andela-cdaniel","followers_url":"https://api.github.com/users/andela-cdaniel/followers","following_url":"https://api.github.com/users/andela-cdaniel/following{/other_user}","gists_url":"https://api.github.com/users/andela-cdaniel/gists{/gist_id}","starred_url":"https://api.github.com/users/andela-cdaniel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andela-cdaniel/subscriptions","organizations_url":"https://api.github.com/users/andela-cdaniel/orgs","repos_url":"https://api.github.com/users/andela-cdaniel/repos","events_url":"https://api.github.com/users/andela-cdaniel/events{/privacy}","received_events_url":"https://api.github.com/users/andela-cdaniel/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/andela-cdaniel/xtrim","description":"","fork":false,"url":"https://api.github.com/repos/andela-cdaniel/xtrim","forks_url":"https://api.github.com/repos/andela-cdaniel/xtrim/forks","keys_url":"https://api.github.com/repos/andela-cdaniel/xtrim/keys{/key_id}","collaborators_url":"https://api.github.com/repos/andela-cdaniel/xtrim/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/andela-cdaniel/xtrim/teams","hooks_url":"https://api.github.com/repos/andela-cdaniel/xtrim/hooks","issue_events_url":"https://api.github.com/repos/andela-cdaniel/xtrim/issues/events{/number}","events_url":"https://api.github.com/repos/andela-cdaniel/xtrim/events","assignees_url":"https://api.github.com/repos/andela-cdaniel/xtrim/assignees{/user}","branches_url":"https://api.github.com/repos/andela-cdaniel/xtrim/branches{/branch}","tags_url":"https://api.github.com/repos/andela-cdaniel/xtrim/tags","blobs_url":"https://api.github.com/repos/andela-cdaniel/xtrim/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/andela-cdaniel/xtrim/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/andela-cdaniel/xtrim/git/refs{/sha}","trees_url":"https://api.github.com/repos/andela-cdaniel/xtrim/git/trees{/sha}","statuses_url":"https://api.github.com/repos/andela-cdaniel/xtrim/statuses/{sha}","languages_url":"https://api.github.com/repos/andela-cdaniel/xtrim/languages","stargazers_url":"https://api.github.com/repos/andela-cdaniel/xtrim/stargazers","contributors_url":"https://api.github.com/repos/andela-cdaniel/xtrim/contributors","subscribers_url":"https://api.github.com/repos/andela-cdaniel/xtrim/subscribers","subscription_url":"https://api.github.com/repos/andela-cdaniel/xtrim/subscription","commits_url":"https://api.github.com/repos/andela-cdaniel/xtrim/commits{/sha}","git_commits_url":"https://api.github.com/repos/andela-cdaniel/xtrim/git/commits{/sha}","comments_url":"https://api.github.com/repos/andela-cdaniel/xtrim/comments{/number}","issue_comment_url":"https://api.github.com/repos/andela-cdaniel/xtrim/issues/comments{/number}","contents_url":"https://api.github.com/repos/andela-cdaniel/xtrim/contents/{+path}","compare_url":"https://api.github.com/repos/andela-cdaniel/xtrim/compare/{base}...{head}","merges_url":"https://api.github.com/repos/andela-cdaniel/xtrim/merges","archive_url":"https://api.github.com/repos/andela-cdaniel/xtrim/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/andela-cdaniel/xtrim/downloads","issues_url":"https://api.github.com/repos/andela-cdaniel/xtrim/issues{/number}","pulls_url":"https://api.github.com/repos/andela-cdaniel/xtrim/pulls{/number}","milestones_url":"https://api.github.com/repos/andela-cdaniel/xtrim/milestones{/number}","notifications_url":"https://api.github.com/repos/andela-cdaniel/xtrim/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/andela-cdaniel/xtrim/labels{/name}","releases_url":"https://api.github.com/repos/andela-cdaniel/xtrim/releases{/id}","created_at":"2015-10-19T16:27:01Z","updated_at":"2015-10-23T12:26:16Z","pushed_at":"2015-11-01T09:51:42Z","git_url":"git://github.com/andela-cdaniel/xtrim.git","ssh_url":"git@github.com:andela-cdaniel/xtrim.git","clone_url":"https://github.com/andela-cdaniel/xtrim.git","svn_url":"https://github.com/andela-cdaniel/xtrim","homepage":null,"size":17620,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/andela-cdaniel/xtrim/pulls/12"},"html":{"href":"https://github.com/andela-cdaniel/xtrim/pull/12"},"issue":{"href":"https://api.github.com/repos/andela-cdaniel/xtrim/issues/12"},"comments":{"href":"https://api.github.com/repos/andela-cdaniel/xtrim/issues/12/comments"},"review_comments":{"href":"https://api.github.com/repos/andela-cdaniel/xtrim/pulls/12/comments"},"review_comment":{"href":"https://api.github.com/repos/andela-cdaniel/xtrim/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/andela-cdaniel/xtrim/pulls/12/commits"},"statuses":{"href":"https://api.github.com/repos/andela-cdaniel/xtrim/statuses/c968b8c6f8cd0714e5608413ccf3a8911e57a0a2"}}}}