{"action":"created","comment":{"url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/pulls/comments/89449690","pull_request_review_id":9994534,"id":89449690,"diff_hunk":"@@ -0,0 +1,178 @@\n+require 'sinatra'\n+require 'erb'\n+require 'mongo'\n+require 'json'\n+\n+require 'thin'\n+require 'sinatra/base'\n+require 'em-websocket'\n+\n+require_relative 'Models/user.rb'\n+require_relative 'Models/word.rb'\n+require_relative 'Models/phrase.rb'\n+\n+EventMachine.run do\n+  class App < Sinatra::Base\n+    enable :sessions\n+\n+    get '/' do\n+      @user = session[:user]\n+      @phrases = Phrase.new.find_all\n+\n+      erb :index\n+    end\n+\n+    post '/add_phrase' do\n+      erb :index, :layout => false\n+    end\n+\n+    post '/sign_in' do\n+      username = request.params['username']\n+      password = request.params['password']\n+\n+      if User.new.is_exist(username) && User.new.check_password(username, password)\n+        user = User.new.find_by_username(username)\n+\n+        session['user'] = {\n+            username: username,\n+            name: user[:name]\n+        }\n+\n+        return {result: true}.to_json\n+      else\n+        return {result: false}.to_json\n+      end\n+\n+    end\n+\n+    get '/logout' do\n+      session[:user] = nil\n+\n+      redirect '/'\n+    end\n+\n+    post '/sign_up' do\n+      name = request.params['name']\n+      username = request.params['username']\n+      password = request.params['password']\n+\n+      if User.new.is_exist(username)\n+        return {result: false}.to_json\n+      else\n+        User.new.insert_one(name, username, password)\n+        session[:user] = {\n+            name: name,\n+            username: username,\n+            password: password\n+        }\n+\n+        return {result: true}.to_json\n+      end\n+    end\n+  end\n+\n+  # our WebSockets server logic will go here\n+\n+  App.run! :port => 3000\n+\n+  @clients = []\n+\n+  EM::WebSocket.start(:host => '0.0.0.0', :port => '3001', :secure_proxy => true) do |ws|\n+    enable :sessions\n+\n+    ws.onopen do |handshake|\n+      @clients << ws\n+\n+      ws.send \"Connected to #{handshake.path}.\"\n+    end\n+\n+    ws.onclose do\n+      ws.send \"Closed.\"\n+      @clients.delete ws\n+    end\n+\n+    ws.onmessage do |message|\n+      message = JSON.parse(message)\n+\n+      case message['type']\n+        when 'create_phrase' then\n+          create_phrase(message['data'])\n+        when 'add_word' then\n+          add_word(message['data'])\n+      end\n+    end\n+\n+    def create_phrase(data)\n+      text = data['text']\n+      username = data['username']\n+\n+      date = Time.now\n+\n+      user = User.new\n+      word = Word.new(client: user.get_client)\n+      phrase = Phrase.new(client: user.get_client)\n+\n+      user = user.find_by_username(username)\n+\n+      if user\n+        word_id = word.insert_one(user[:_id], text, date)\n+        phrase_id = phrase.insert_one(user[:_id], date)\n+        phrase.add_word(BSON::ObjectId(phrase_id), word_id)\n+        word_model = word.find_by_id(word_id)\n+\n+        @clients.each do |socket|\n+          result = {\n+              type: 'create_phrase',\n+              data: {\n+                  phrase_id: phrase_id.to_s,\n+                  word_id: word_id.to_s,\n+                  word_text: text,\n+                  username: user[:username],\n+                  name: user[:name],\n+                  time: word_model[:date]\n+              }\n+          }.to_json\n+\n+          socket.send result\n+        end\n+      end\n+","path":"2016/KonstantinMihlyuk/3/app.rb","position":139,"original_position":139,"commit_id":"39a58719c37459113c5420c2d0e42cfcb198d47c","original_commit_id":"39a58719c37459113c5420c2d0e42cfcb198d47c","user":{"login":"houndci-bot","id":6697940,"avatar_url":"https://avatars.githubusercontent.com/u/6697940?v=3","gravatar_id":"","url":"https://api.github.com/users/houndci-bot","html_url":"https://github.com/houndci-bot","followers_url":"https://api.github.com/users/houndci-bot/followers","following_url":"https://api.github.com/users/houndci-bot/following{/other_user}","gists_url":"https://api.github.com/users/houndci-bot/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci-bot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci-bot/subscriptions","organizations_url":"https://api.github.com/users/houndci-bot/orgs","repos_url":"https://api.github.com/users/houndci-bot/repos","events_url":"https://api.github.com/users/houndci-bot/events{/privacy}","received_events_url":"https://api.github.com/users/houndci-bot/received_events","type":"User","site_admin":false},"body":"Extra empty line detected at method body end.","created_at":"2016-11-24T08:09:37Z","updated_at":"2016-11-24T08:09:37Z","html_url":"https://github.com/rubyroidlabs/bsuir-courses/pull/525#discussion_r89449690","pull_request_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/pulls/525","_links":{"self":{"href":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/pulls/comments/89449690"},"html":{"href":"https://github.com/rubyroidlabs/bsuir-courses/pull/525#discussion_r89449690"},"pull_request":{"href":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/pulls/525"}}},"pull_request":{"url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/pulls/525","id":94975562,"html_url":"https://github.com/rubyroidlabs/bsuir-courses/pull/525","diff_url":"https://github.com/rubyroidlabs/bsuir-courses/pull/525.diff","patch_url":"https://github.com/rubyroidlabs/bsuir-courses/pull/525.patch","issue_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/issues/525","number":525,"state":"open","locked":false,"title":"Homework 3","user":{"login":"Mihlyuk","id":15009009,"avatar_url":"https://avatars.githubusercontent.com/u/15009009?v=3","gravatar_id":"","url":"https://api.github.com/users/Mihlyuk","html_url":"https://github.com/Mihlyuk","followers_url":"https://api.github.com/users/Mihlyuk/followers","following_url":"https://api.github.com/users/Mihlyuk/following{/other_user}","gists_url":"https://api.github.com/users/Mihlyuk/gists{/gist_id}","starred_url":"https://api.github.com/users/Mihlyuk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Mihlyuk/subscriptions","organizations_url":"https://api.github.com/users/Mihlyuk/orgs","repos_url":"https://api.github.com/users/Mihlyuk/repos","events_url":"https://api.github.com/users/Mihlyuk/events{/privacy}","received_events_url":"https://api.github.com/users/Mihlyuk/received_events","type":"User","site_admin":false},"body":"## Фамилия Имя\r\nКонстантин Михлюк\r\n\r\n## Email\r\nkonstantin.mihlyuk@yandex.ru\r\n\r\n## Номер домашнего задания\r\n3\r\n\r\n## Ссылка на видео с демо работы\r\nhttp://recordit.co/QNPT6ZiWTr\r\n\r\n## Комментарии\r\nСделал третий уровень. В качестве базы данных решил попробовать mongodb, довольно миленько) сделал собственный active records, с блекджеком и костылями. Открыл для себя целый мир прекрасного бутстрапа. Оказывается верстать не так уж и сложно) Ну это из интересного.. \r\n\r\n","created_at":"2016-11-23T10:21:41Z","updated_at":"2016-11-24T08:09:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ebdc6ede1c1f798e3b38568aba4035176d565826","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/pulls/525/commits","review_comments_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/pulls/525/comments","review_comment_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/issues/525/comments","statuses_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/statuses/39a58719c37459113c5420c2d0e42cfcb198d47c","head":{"label":"Mihlyuk:homework-3-mihlyuk","ref":"homework-3-mihlyuk","sha":"39a58719c37459113c5420c2d0e42cfcb198d47c","user":{"login":"Mihlyuk","id":15009009,"avatar_url":"https://avatars.githubusercontent.com/u/15009009?v=3","gravatar_id":"","url":"https://api.github.com/users/Mihlyuk","html_url":"https://github.com/Mihlyuk","followers_url":"https://api.github.com/users/Mihlyuk/followers","following_url":"https://api.github.com/users/Mihlyuk/following{/other_user}","gists_url":"https://api.github.com/users/Mihlyuk/gists{/gist_id}","starred_url":"https://api.github.com/users/Mihlyuk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Mihlyuk/subscriptions","organizations_url":"https://api.github.com/users/Mihlyuk/orgs","repos_url":"https://api.github.com/users/Mihlyuk/repos","events_url":"https://api.github.com/users/Mihlyuk/events{/privacy}","received_events_url":"https://api.github.com/users/Mihlyuk/received_events","type":"User","site_admin":false},"repo":{"id":71427494,"name":"bsuir-courses","full_name":"Mihlyuk/bsuir-courses","owner":{"login":"Mihlyuk","id":15009009,"avatar_url":"https://avatars.githubusercontent.com/u/15009009?v=3","gravatar_id":"","url":"https://api.github.com/users/Mihlyuk","html_url":"https://github.com/Mihlyuk","followers_url":"https://api.github.com/users/Mihlyuk/followers","following_url":"https://api.github.com/users/Mihlyuk/following{/other_user}","gists_url":"https://api.github.com/users/Mihlyuk/gists{/gist_id}","starred_url":"https://api.github.com/users/Mihlyuk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Mihlyuk/subscriptions","organizations_url":"https://api.github.com/users/Mihlyuk/orgs","repos_url":"https://api.github.com/users/Mihlyuk/repos","events_url":"https://api.github.com/users/Mihlyuk/events{/privacy}","received_events_url":"https://api.github.com/users/Mihlyuk/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Mihlyuk/bsuir-courses","description":"This is common repository for all student to submit all their homeworks","fork":true,"url":"https://api.github.com/repos/Mihlyuk/bsuir-courses","forks_url":"https://api.github.com/repos/Mihlyuk/bsuir-courses/forks","keys_url":"https://api.github.com/repos/Mihlyuk/bsuir-courses/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Mihlyuk/bsuir-courses/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Mihlyuk/bsuir-courses/teams","hooks_url":"https://api.github.com/repos/Mihlyuk/bsuir-courses/hooks","issue_events_url":"https://api.github.com/repos/Mihlyuk/bsuir-courses/issues/events{/number}","events_url":"https://api.github.com/repos/Mihlyuk/bsuir-courses/events","assignees_url":"https://api.github.com/repos/Mihlyuk/bsuir-courses/assignees{/user}","branches_url":"https://api.github.com/repos/Mihlyuk/bsuir-courses/branches{/branch}","tags_url":"https://api.github.com/repos/Mihlyuk/bsuir-courses/tags","blobs_url":"https://api.github.com/repos/Mihlyuk/bsuir-courses/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Mihlyuk/bsuir-courses/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Mihlyuk/bsuir-courses/git/refs{/sha}","trees_url":"https://api.github.com/repos/Mihlyuk/bsuir-courses/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Mihlyuk/bsuir-courses/statuses/{sha}","languages_url":"https://api.github.com/repos/Mihlyuk/bsuir-courses/languages","stargazers_url":"https://api.github.com/repos/Mihlyuk/bsuir-courses/stargazers","contributors_url":"https://api.github.com/repos/Mihlyuk/bsuir-courses/contributors","subscribers_url":"https://api.github.com/repos/Mihlyuk/bsuir-courses/subscribers","subscription_url":"https://api.github.com/repos/Mihlyuk/bsuir-courses/subscription","commits_url":"https://api.github.com/repos/Mihlyuk/bsuir-courses/commits{/sha}","git_commits_url":"https://api.github.com/repos/Mihlyuk/bsuir-courses/git/commits{/sha}","comments_url":"https://api.github.com/repos/Mihlyuk/bsuir-courses/comments{/number}","issue_comment_url":"https://api.github.com/repos/Mihlyuk/bsuir-courses/issues/comments{/number}","contents_url":"https://api.github.com/repos/Mihlyuk/bsuir-courses/contents/{+path}","compare_url":"https://api.github.com/repos/Mihlyuk/bsuir-courses/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Mihlyuk/bsuir-courses/merges","archive_url":"https://api.github.com/repos/Mihlyuk/bsuir-courses/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Mihlyuk/bsuir-courses/downloads","issues_url":"https://api.github.com/repos/Mihlyuk/bsuir-courses/issues{/number}","pulls_url":"https://api.github.com/repos/Mihlyuk/bsuir-courses/pulls{/number}","milestones_url":"https://api.github.com/repos/Mihlyuk/bsuir-courses/milestones{/number}","notifications_url":"https://api.github.com/repos/Mihlyuk/bsuir-courses/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Mihlyuk/bsuir-courses/labels{/name}","releases_url":"https://api.github.com/repos/Mihlyuk/bsuir-courses/releases{/id}","deployments_url":"https://api.github.com/repos/Mihlyuk/bsuir-courses/deployments","created_at":"2016-10-20T05:13:02Z","updated_at":"2016-10-20T05:13:04Z","pushed_at":"2016-11-24T08:09:24Z","git_url":"git://github.com/Mihlyuk/bsuir-courses.git","ssh_url":"git@github.com:Mihlyuk/bsuir-courses.git","clone_url":"https://github.com/Mihlyuk/bsuir-courses.git","svn_url":"https://github.com/Mihlyuk/bsuir-courses","homepage":null,"size":3016,"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":"master"}},"base":{"label":"rubyroidlabs:master","ref":"master","sha":"eb75371b4d7a623651d88add7a5b61dbfcaed0d5","user":{"login":"rubyroidlabs","id":5137565,"avatar_url":"https://avatars.githubusercontent.com/u/5137565?v=3","gravatar_id":"","url":"https://api.github.com/users/rubyroidlabs","html_url":"https://github.com/rubyroidlabs","followers_url":"https://api.github.com/users/rubyroidlabs/followers","following_url":"https://api.github.com/users/rubyroidlabs/following{/other_user}","gists_url":"https://api.github.com/users/rubyroidlabs/gists{/gist_id}","starred_url":"https://api.github.com/users/rubyroidlabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rubyroidlabs/subscriptions","organizations_url":"https://api.github.com/users/rubyroidlabs/orgs","repos_url":"https://api.github.com/users/rubyroidlabs/repos","events_url":"https://api.github.com/users/rubyroidlabs/events{/privacy}","received_events_url":"https://api.github.com/users/rubyroidlabs/received_events","type":"Organization","site_admin":false},"repo":{"id":14405320,"name":"bsuir-courses","full_name":"rubyroidlabs/bsuir-courses","owner":{"login":"rubyroidlabs","id":5137565,"avatar_url":"https://avatars.githubusercontent.com/u/5137565?v=3","gravatar_id":"","url":"https://api.github.com/users/rubyroidlabs","html_url":"https://github.com/rubyroidlabs","followers_url":"https://api.github.com/users/rubyroidlabs/followers","following_url":"https://api.github.com/users/rubyroidlabs/following{/other_user}","gists_url":"https://api.github.com/users/rubyroidlabs/gists{/gist_id}","starred_url":"https://api.github.com/users/rubyroidlabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rubyroidlabs/subscriptions","organizations_url":"https://api.github.com/users/rubyroidlabs/orgs","repos_url":"https://api.github.com/users/rubyroidlabs/repos","events_url":"https://api.github.com/users/rubyroidlabs/events{/privacy}","received_events_url":"https://api.github.com/users/rubyroidlabs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rubyroidlabs/bsuir-courses","description":"This is common repository for all student to submit all their homeworks","fork":false,"url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses","forks_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/forks","keys_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/teams","hooks_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/hooks","issue_events_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/issues/events{/number}","events_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/events","assignees_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/assignees{/user}","branches_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/branches{/branch}","tags_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/tags","blobs_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/git/refs{/sha}","trees_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/statuses/{sha}","languages_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/languages","stargazers_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/stargazers","contributors_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/contributors","subscribers_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/subscribers","subscription_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/subscription","commits_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/commits{/sha}","git_commits_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/git/commits{/sha}","comments_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/comments{/number}","issue_comment_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/issues/comments{/number}","contents_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/contents/{+path}","compare_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/merges","archive_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/downloads","issues_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/issues{/number}","pulls_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/pulls{/number}","milestones_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/milestones{/number}","notifications_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/labels{/name}","releases_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/releases{/id}","deployments_url":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/deployments","created_at":"2013-11-14T19:55:12Z","updated_at":"2016-11-03T04:38:40Z","pushed_at":"2016-11-24T08:09:24Z","git_url":"git://github.com/rubyroidlabs/bsuir-courses.git","ssh_url":"git@github.com:rubyroidlabs/bsuir-courses.git","clone_url":"https://github.com/rubyroidlabs/bsuir-courses.git","svn_url":"https://github.com/rubyroidlabs/bsuir-courses","homepage":null,"size":12551,"stargazers_count":31,"watchers_count":31,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":174,"mirror_url":null,"open_issues_count":38,"forks":174,"open_issues":38,"watchers":31,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/pulls/525"},"html":{"href":"https://github.com/rubyroidlabs/bsuir-courses/pull/525"},"issue":{"href":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/issues/525"},"comments":{"href":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/issues/525/comments"},"review_comments":{"href":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/pulls/525/comments"},"review_comment":{"href":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/pulls/525/commits"},"statuses":{"href":"https://api.github.com/repos/rubyroidlabs/bsuir-courses/statuses/39a58719c37459113c5420c2d0e42cfcb198d47c"}}}}
{"actor":{"display_login":"houndci-bot"}}