{"action":"created","comment":{"url":"https://api.github.com/repos/sci-sim/sci-sim/pulls/comments/24375924","id":24375924,"diff_hunk":"@@ -0,0 +1,115 @@\n+from scisim import app, db, clean_text\n+from flask import request\n+from models import *\n+from scisim.helpers import *\n+from sqlalchemy import and_\n+from datetime import datetime\n+from json import dumps\n+\n+@app.route('/api/login')\n+def login():\n+    username = request.form['username']\n+    sim_id = request.form['sim_id']\n+    password = request.form['password']\n+\n+    if len(username) < 1:\n+        return error_message('The username must have more than 1 character')\n+\n+    sim = Simulation.query.filter(Simulation.id == sim_id).first()\n+    if sim.password != password:\n+        return error_message('The simulation password is not correct')\n+\n+    user = User(name=username, sim_id=sim_id)\n+    db.add(user)\n+    db.commit()\n+\n+    return dumps(unpack_model(user))\n+\n+\n+@app.route('/api/logout')\n+def logout():\n+    # maybe we could create a 'logged in' table that will store logged in users. Put an expiration and remove logged in users with a cron job\n+    pass\n+\n+@app.route('/api/simulations', methods=['GET'])\n+def simulations():\n+    return to_json(Simulation.query.all())\n+\n+@app.route('/api/pages', methods=['POST'])\n+def pages():\n+    check = check_for_params(['sim_id'], request)\n+    if type(check) is type(str()):\n+        return error_message(check)\n+\n+    return to_json(Page.query.filter(Page.sim_id == request.form['sim_id']))\n+\n+@app.route('/api/page', methods=['POST'])\n+def page():\n+    check = check_for_params(['page_id'], request)\n+    if type(check) is type(str()):\n+        return error_message(check)\n+    return to_json(Page.query.filter(Page.id == request.form['page_id']))\n+\n+\n+@app.route('/api/links', methods=['POST'])\n+def links():\n+    check = check_for_params(['page_id'], request)\n+    if type(check) is type(str()):\n+        return error_message(check)\n+\n+    return to_json(Link.query.filter(Link.page_src_id == request.form['page_id']))\n+\n+@app.route('/api/sections', methods=['POST'])\n+def sections():\n+    check = check_for_params(['page_id'], request)\n+    if type(check) is type(str()):\n+        return error_message(check)\n+\n+    return to_json(Section.query.filter(Section.page_id == request.form['page_id']))\n+\n+@app.route('/api/prompts', methods=['POST'])\n+def section():\n+    check = check_for_params(['link_id'], request)\n+    if type(check) is type(str()):\n+        return error_message(check)\n+\n+    return to_json(Prompt.query.filter(Prompt.link_id == request.form['link_id']))\n+\n+\n+@app.route('/api/notes', methods=['POST'])\n+def notes():\n+    check = check_for_params(['user_id'], request)\n+    if type(check) is type(str()):\n+        return error_message(check)\n+\n+    return to_json(Note.query.filter(Note.user_id == request.form['user_id']))\n+\n+@app.route('/api/note/create', methods=['POST'])\n+def create_note():\n+    check = check_for_params(['user_id', 'note'], request)\n+    if type(check) is type(str()):\n+        return error_message(check)\n+\n+    user = User.query.filter(User.id == request.form['user_id']).first()\n+    user_note = clean_text(request.form['note'])\n+\n+    note = \"<strong>Added notebook entry:</strong><br /><blockquote>\" + user_note + \"</blockquote>\"","path":"scisim/api.py","position":96,"original_position":96,"commit_id":"584f2e542dbac0532516a42355da52eb978d6248","original_commit_id":"584f2e542dbac0532516a42355da52eb978d6248","user":{"login":"matthewbeckler","id":449185,"avatar_url":"https://avatars.githubusercontent.com/u/449185?v=3","gravatar_id":"","url":"https://api.github.com/users/matthewbeckler","html_url":"https://github.com/matthewbeckler","followers_url":"https://api.github.com/users/matthewbeckler/followers","following_url":"https://api.github.com/users/matthewbeckler/following{/other_user}","gists_url":"https://api.github.com/users/matthewbeckler/gists{/gist_id}","starred_url":"https://api.github.com/users/matthewbeckler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matthewbeckler/subscriptions","organizations_url":"https://api.github.com/users/matthewbeckler/orgs","repos_url":"https://api.github.com/users/matthewbeckler/repos","events_url":"https://api.github.com/users/matthewbeckler/events{/privacy}","received_events_url":"https://api.github.com/users/matthewbeckler/received_events","type":"User","site_admin":false},"body":"We don't want to have \"Added notebook entry\" in the user's notebook, we just want the content. Having \"Added notebook entry\" is great for the Log object.","created_at":"2015-02-09T23:22:25Z","updated_at":"2015-02-09T23:22:25Z","html_url":"https://github.com/sci-sim/sci-sim/pull/2#discussion_r24375924","pull_request_url":"https://api.github.com/repos/sci-sim/sci-sim/pulls/2","_links":{"self":{"href":"https://api.github.com/repos/sci-sim/sci-sim/pulls/comments/24375924"},"html":{"href":"https://github.com/sci-sim/sci-sim/pull/2#discussion_r24375924"},"pull_request":{"href":"https://api.github.com/repos/sci-sim/sci-sim/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/sci-sim/sci-sim/pulls/2","id":28887264,"html_url":"https://github.com/sci-sim/sci-sim/pull/2","diff_url":"https://github.com/sci-sim/sci-sim/pull/2.diff","patch_url":"https://github.com/sci-sim/sci-sim/pull/2.patch","issue_url":"https://api.github.com/repos/sci-sim/sci-sim/issues/2","number":2,"state":"open","locked":false,"title":"Added an api","user":{"login":"calebdre","id":3318929,"avatar_url":"https://avatars.githubusercontent.com/u/3318929?v=3","gravatar_id":"","url":"https://api.github.com/users/calebdre","html_url":"https://github.com/calebdre","followers_url":"https://api.github.com/users/calebdre/followers","following_url":"https://api.github.com/users/calebdre/following{/other_user}","gists_url":"https://api.github.com/users/calebdre/gists{/gist_id}","starred_url":"https://api.github.com/users/calebdre/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/calebdre/subscriptions","organizations_url":"https://api.github.com/users/calebdre/orgs","repos_url":"https://api.github.com/users/calebdre/repos","events_url":"https://api.github.com/users/calebdre/events{/privacy}","received_events_url":"https://api.github.com/users/calebdre/received_events","type":"User","site_admin":false},"body":"I added the api! I also added the debug flag to the `app.run` to make development easier (it auto-reloads and provides really nice error pages.)","created_at":"2015-02-08T21:43:20Z","updated_at":"2015-02-09T23:22:25Z","closed_at":null,"merged_at":null,"merge_commit_sha":"39d5bc809de6574a4e833f6040146797289cacff","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/sci-sim/sci-sim/pulls/2/commits","review_comments_url":"https://api.github.com/repos/sci-sim/sci-sim/pulls/2/comments","review_comment_url":"https://api.github.com/repos/sci-sim/sci-sim/pulls/comments/{number}","comments_url":"https://api.github.com/repos/sci-sim/sci-sim/issues/2/comments","statuses_url":"https://api.github.com/repos/sci-sim/sci-sim/statuses/584f2e542dbac0532516a42355da52eb978d6248","head":{"label":"sci-sim:dev_cl","ref":"dev_cl","sha":"584f2e542dbac0532516a42355da52eb978d6248","user":{"login":"sci-sim","id":9721495,"avatar_url":"https://avatars.githubusercontent.com/u/9721495?v=3","gravatar_id":"","url":"https://api.github.com/users/sci-sim","html_url":"https://github.com/sci-sim","followers_url":"https://api.github.com/users/sci-sim/followers","following_url":"https://api.github.com/users/sci-sim/following{/other_user}","gists_url":"https://api.github.com/users/sci-sim/gists{/gist_id}","starred_url":"https://api.github.com/users/sci-sim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sci-sim/subscriptions","organizations_url":"https://api.github.com/users/sci-sim/orgs","repos_url":"https://api.github.com/users/sci-sim/repos","events_url":"https://api.github.com/users/sci-sim/events{/privacy}","received_events_url":"https://api.github.com/users/sci-sim/received_events","type":"Organization","site_admin":false},"repo":{"id":27109361,"name":"sci-sim","full_name":"sci-sim/sci-sim","owner":{"login":"sci-sim","id":9721495,"avatar_url":"https://avatars.githubusercontent.com/u/9721495?v=3","gravatar_id":"","url":"https://api.github.com/users/sci-sim","html_url":"https://github.com/sci-sim","followers_url":"https://api.github.com/users/sci-sim/followers","following_url":"https://api.github.com/users/sci-sim/following{/other_user}","gists_url":"https://api.github.com/users/sci-sim/gists{/gist_id}","starred_url":"https://api.github.com/users/sci-sim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sci-sim/subscriptions","organizations_url":"https://api.github.com/users/sci-sim/orgs","repos_url":"https://api.github.com/users/sci-sim/repos","events_url":"https://api.github.com/users/sci-sim/events{/privacy}","received_events_url":"https://api.github.com/users/sci-sim/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/sci-sim/sci-sim","description":"Science Classroom Inquiry Simulation engine","fork":false,"url":"https://api.github.com/repos/sci-sim/sci-sim","forks_url":"https://api.github.com/repos/sci-sim/sci-sim/forks","keys_url":"https://api.github.com/repos/sci-sim/sci-sim/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sci-sim/sci-sim/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sci-sim/sci-sim/teams","hooks_url":"https://api.github.com/repos/sci-sim/sci-sim/hooks","issue_events_url":"https://api.github.com/repos/sci-sim/sci-sim/issues/events{/number}","events_url":"https://api.github.com/repos/sci-sim/sci-sim/events","assignees_url":"https://api.github.com/repos/sci-sim/sci-sim/assignees{/user}","branches_url":"https://api.github.com/repos/sci-sim/sci-sim/branches{/branch}","tags_url":"https://api.github.com/repos/sci-sim/sci-sim/tags","blobs_url":"https://api.github.com/repos/sci-sim/sci-sim/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sci-sim/sci-sim/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sci-sim/sci-sim/git/refs{/sha}","trees_url":"https://api.github.com/repos/sci-sim/sci-sim/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sci-sim/sci-sim/statuses/{sha}","languages_url":"https://api.github.com/repos/sci-sim/sci-sim/languages","stargazers_url":"https://api.github.com/repos/sci-sim/sci-sim/stargazers","contributors_url":"https://api.github.com/repos/sci-sim/sci-sim/contributors","subscribers_url":"https://api.github.com/repos/sci-sim/sci-sim/subscribers","subscription_url":"https://api.github.com/repos/sci-sim/sci-sim/subscription","commits_url":"https://api.github.com/repos/sci-sim/sci-sim/commits{/sha}","git_commits_url":"https://api.github.com/repos/sci-sim/sci-sim/git/commits{/sha}","comments_url":"https://api.github.com/repos/sci-sim/sci-sim/comments{/number}","issue_comment_url":"https://api.github.com/repos/sci-sim/sci-sim/issues/comments/{number}","contents_url":"https://api.github.com/repos/sci-sim/sci-sim/contents/{+path}","compare_url":"https://api.github.com/repos/sci-sim/sci-sim/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sci-sim/sci-sim/merges","archive_url":"https://api.github.com/repos/sci-sim/sci-sim/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sci-sim/sci-sim/downloads","issues_url":"https://api.github.com/repos/sci-sim/sci-sim/issues{/number}","pulls_url":"https://api.github.com/repos/sci-sim/sci-sim/pulls{/number}","milestones_url":"https://api.github.com/repos/sci-sim/sci-sim/milestones{/number}","notifications_url":"https://api.github.com/repos/sci-sim/sci-sim/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sci-sim/sci-sim/labels{/name}","releases_url":"https://api.github.com/repos/sci-sim/sci-sim/releases{/id}","created_at":"2014-11-25T04:39:14Z","updated_at":"2015-01-16T19:49:36Z","pushed_at":"2015-02-09T16:09:06Z","git_url":"git://github.com/sci-sim/sci-sim.git","ssh_url":"git@github.com:sci-sim/sci-sim.git","clone_url":"https://github.com/sci-sim/sci-sim.git","svn_url":"https://github.com/sci-sim/sci-sim","homepage":"http://sci-sims.com","size":3504,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"sci-sim:dev","ref":"dev","sha":"2fc9960b585aea146528cf264a01f91b13b0c902","user":{"login":"sci-sim","id":9721495,"avatar_url":"https://avatars.githubusercontent.com/u/9721495?v=3","gravatar_id":"","url":"https://api.github.com/users/sci-sim","html_url":"https://github.com/sci-sim","followers_url":"https://api.github.com/users/sci-sim/followers","following_url":"https://api.github.com/users/sci-sim/following{/other_user}","gists_url":"https://api.github.com/users/sci-sim/gists{/gist_id}","starred_url":"https://api.github.com/users/sci-sim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sci-sim/subscriptions","organizations_url":"https://api.github.com/users/sci-sim/orgs","repos_url":"https://api.github.com/users/sci-sim/repos","events_url":"https://api.github.com/users/sci-sim/events{/privacy}","received_events_url":"https://api.github.com/users/sci-sim/received_events","type":"Organization","site_admin":false},"repo":{"id":27109361,"name":"sci-sim","full_name":"sci-sim/sci-sim","owner":{"login":"sci-sim","id":9721495,"avatar_url":"https://avatars.githubusercontent.com/u/9721495?v=3","gravatar_id":"","url":"https://api.github.com/users/sci-sim","html_url":"https://github.com/sci-sim","followers_url":"https://api.github.com/users/sci-sim/followers","following_url":"https://api.github.com/users/sci-sim/following{/other_user}","gists_url":"https://api.github.com/users/sci-sim/gists{/gist_id}","starred_url":"https://api.github.com/users/sci-sim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sci-sim/subscriptions","organizations_url":"https://api.github.com/users/sci-sim/orgs","repos_url":"https://api.github.com/users/sci-sim/repos","events_url":"https://api.github.com/users/sci-sim/events{/privacy}","received_events_url":"https://api.github.com/users/sci-sim/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/sci-sim/sci-sim","description":"Science Classroom Inquiry Simulation engine","fork":false,"url":"https://api.github.com/repos/sci-sim/sci-sim","forks_url":"https://api.github.com/repos/sci-sim/sci-sim/forks","keys_url":"https://api.github.com/repos/sci-sim/sci-sim/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sci-sim/sci-sim/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sci-sim/sci-sim/teams","hooks_url":"https://api.github.com/repos/sci-sim/sci-sim/hooks","issue_events_url":"https://api.github.com/repos/sci-sim/sci-sim/issues/events{/number}","events_url":"https://api.github.com/repos/sci-sim/sci-sim/events","assignees_url":"https://api.github.com/repos/sci-sim/sci-sim/assignees{/user}","branches_url":"https://api.github.com/repos/sci-sim/sci-sim/branches{/branch}","tags_url":"https://api.github.com/repos/sci-sim/sci-sim/tags","blobs_url":"https://api.github.com/repos/sci-sim/sci-sim/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sci-sim/sci-sim/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sci-sim/sci-sim/git/refs{/sha}","trees_url":"https://api.github.com/repos/sci-sim/sci-sim/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sci-sim/sci-sim/statuses/{sha}","languages_url":"https://api.github.com/repos/sci-sim/sci-sim/languages","stargazers_url":"https://api.github.com/repos/sci-sim/sci-sim/stargazers","contributors_url":"https://api.github.com/repos/sci-sim/sci-sim/contributors","subscribers_url":"https://api.github.com/repos/sci-sim/sci-sim/subscribers","subscription_url":"https://api.github.com/repos/sci-sim/sci-sim/subscription","commits_url":"https://api.github.com/repos/sci-sim/sci-sim/commits{/sha}","git_commits_url":"https://api.github.com/repos/sci-sim/sci-sim/git/commits{/sha}","comments_url":"https://api.github.com/repos/sci-sim/sci-sim/comments{/number}","issue_comment_url":"https://api.github.com/repos/sci-sim/sci-sim/issues/comments/{number}","contents_url":"https://api.github.com/repos/sci-sim/sci-sim/contents/{+path}","compare_url":"https://api.github.com/repos/sci-sim/sci-sim/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sci-sim/sci-sim/merges","archive_url":"https://api.github.com/repos/sci-sim/sci-sim/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sci-sim/sci-sim/downloads","issues_url":"https://api.github.com/repos/sci-sim/sci-sim/issues{/number}","pulls_url":"https://api.github.com/repos/sci-sim/sci-sim/pulls{/number}","milestones_url":"https://api.github.com/repos/sci-sim/sci-sim/milestones{/number}","notifications_url":"https://api.github.com/repos/sci-sim/sci-sim/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sci-sim/sci-sim/labels{/name}","releases_url":"https://api.github.com/repos/sci-sim/sci-sim/releases{/id}","created_at":"2014-11-25T04:39:14Z","updated_at":"2015-01-16T19:49:36Z","pushed_at":"2015-02-09T16:09:06Z","git_url":"git://github.com/sci-sim/sci-sim.git","ssh_url":"git@github.com:sci-sim/sci-sim.git","clone_url":"https://github.com/sci-sim/sci-sim.git","svn_url":"https://github.com/sci-sim/sci-sim","homepage":"http://sci-sims.com","size":3504,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/sci-sim/sci-sim/pulls/2"},"html":{"href":"https://github.com/sci-sim/sci-sim/pull/2"},"issue":{"href":"https://api.github.com/repos/sci-sim/sci-sim/issues/2"},"comments":{"href":"https://api.github.com/repos/sci-sim/sci-sim/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/sci-sim/sci-sim/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/sci-sim/sci-sim/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/sci-sim/sci-sim/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/sci-sim/sci-sim/statuses/584f2e542dbac0532516a42355da52eb978d6248"}}}}