Permalink
Browse files

(wip) reviewed as a group

  • Loading branch information...
1 parent f0f56a0 commit 023b9b4a42d248b798cdea0003197a4031793788 Benjamin Oakes, Dan Bernier, and Zach Morek committed with Zach Morek Nov 19, 2013
Showing with 38 additions and 20 deletions.
  1. +2 −1 README.md
  2. +36 −19 app.rb
View
@@ -28,8 +28,9 @@ For production, `.env` would be:
To get started:
+ gem install bundler
bundle
- rackup
+ bundle exec rackup
The default port is `4567`, so you can test your connection like so:
View
@@ -3,7 +3,7 @@
# This file is automatically generated from the code publically available on [GitHub](https://github.com/ContinuityControl/control_api_reference).
#
# TODO: add diagram and explanation of User, TemplateToDo, DistributedToDo, and Assignment
-#
+#
# ---
#
# This is a [Sinatra](http://www.sinatrarb.com/) application that integrates with the Control API. Sinatra is a small Ruby web application framework that provides a DSL (domain specific language) for handling HTTP requests like `get` and `post`. It should be easy to read even if you don't read Sinatra's documentation.
@@ -13,22 +13,21 @@
require 'dotenv'
Dotenv.load
-# Log configuration for debugging purposes.
-puts
-puts 'Environment'
-puts "CONTROL_API_BASE_URI=#{ENV['CONTROL_API_BASE_URI']}"
-puts
-
-# This class uses a library called `HTTParty` to connect to the Control API. In general, all API responses are JSON. `HTTParty` automatically detects this and parses into a Ruby object.
+# This class uses a library called HTTParty to connect to the Control API. In general, all API responses are JSON. `HTTParty` automatically detects this and parses into a Ruby object.
#
# For more information, see the [HTTParty](http://johnnunemaker.com/httparty/) website.
class ControlAPI
include HTTParty
base_uri ENV['CONTROL_API_BASE_URI']
+
+ # TODO: add authentication code
end
# The root path in this application simply provides navigation.
get '/' do
+ # `erb :view_name` renders the file in `views/view_name.erb`.
+ #
+ # For example, this will end up rendering `views/root.erb`.
erb :root
end
@@ -46,6 +45,10 @@ class ControlAPI
#
# {"description":"up"}
#
+# #### HTTP 401 Unauthorized
+#
+# The request was not properly authenticated.
+#
# #### HTTP 500 Server Error
#
# ### Response fields
@@ -59,7 +62,7 @@ class ControlAPI
# ## POST /v1/distributed_to_dos
#
-# **Asynchronously** distribute a ToDo to the given assignees.
+# **Asynchronously** distribute a ToDo to the given assignees. (The work happens in a job queue.)
#
# ### Example request
#
@@ -70,9 +73,9 @@ class ControlAPI
#
# ### Request fields
#
-# * `template_to_do_api_id`: **Required**. The UUID for the TemplateToDo that will be distributed. This can be found in settings.
+# * `template_to_do_api_id`: **Required**. The UUID for the TemplateToDo that will be distributed. This can be found in Continuity Control under "Settings".
# * `assignee_emails`: **Required**. A JSON Array of email addresses of Users that will receive the DistributedToDos.
-# * `content`: JSON text of values to pre-fill in the DistributedToDo. Field names are available under "Settings".
+# * `content`: JSON text of values to pre-fill in the DistributedToDo. Field names are available in Continuity Control under "Settings".
#
# ### Example responses
#
@@ -83,13 +86,23 @@ class ControlAPI
# "path":"/v1/distributed_to_dos/f81d4fae-7dec-11d0-a765-00a0c91e6bf6"
# }
#
+# #### HTTP 401 Unauthorized
+#
+# The request was not properly authenticated.
+#
# #### HTTP 422 Unprocessable Entity
#
# {
# "errors": {
+# "template_to_do_api_id": [
+# "does not exist",
+# ],
# "assignee_emails": [
-# "has invalid email address alice@example.com",
-# "has invalid email address bob@example.com"
+# "has email alice@example.com which does not exist for this organization",
+# "has email bob@example.com which does not exist for this organization"
+# ],
+# "content": [
+# "is not valid JSON"
# ]
# }
# }
@@ -102,8 +115,8 @@ class ControlAPI
# ### Response fields
#
# * `id`: An ID for the DistributedToDo which will be created asynchronously. Please include it in any bug reports to Continuity.
-# * `path`: The path where the DistributedToDo will be available.
-# * `errors`: An object with one key per request field and an array of all the validation errors that apply to that field.
+# * `path`: The path where the DistributedToDo will be available once created.
+# * `errors`: An object with one key per request field and an array of all the validation errors that apply to that field. The exact text of the error messages **is not** guaranteed and may change without warning.
#
get '/distributed_to_dos/new' do
erb :distributed_to_dos_new
@@ -117,7 +130,7 @@ class ControlAPI
[200, erb(:distributed_to_dos_post, :locals => distributed_to_do)]
when '422'
[422, erb(:distributed_to_dos_errors, :locals => distributed_to_do)]
- else
+ else
[500, 'There was an error while processing your request']
end
end
@@ -151,6 +164,10 @@ class ControlAPI
# ]
# }
#
+# #### HTTP 401 Unauthorized
+#
+# The request was not properly authenticated.
+#
# #### HTTP 404 Not Found
#
# Returned when the resource does not exist. Note that after a `POST` to `/v1/distributed_to_dos` that gives a `202`, `/v1/distributed_to_dos/:id` would return a `404` until the resource is **asynchronously** created.
@@ -161,11 +178,11 @@ class ControlAPI
#
# * `id`: Unique ID for this DistributedToDo.
# * `created_at`: ISO8601 datetime of the creation of this DistributedToDo, in UTC.
-# * `completed_at`: ISO8601 date of when the DistributedToDo was completed, in UTC.
+# * `completed_at`: ISO8601 datetime of when the DistributedToDo was completed, in UTC. This is when all the assignments have been finished.
# * `due_on`: ISO8601 date of when the DistributedToDo is due, in UTC.
# * `assignments`: Array
# * `email`: User email of DistributedToDo assignment
-# * `finished_on`: ISO8601 date on which the assignment was completed (in UTC), or `null` if not completed
+# * `completed_on`: ISO8601 date on which the assignment was completed (in UTC), or `null` if not completed
#
# TODO: make sure all DistributedToDos have a UUID-style `id`.
#
@@ -177,7 +194,7 @@ class ControlAPI
erb :distributed_to_do, :locals => distributed_to_do
when '404'
[404, 'Not found']
- else
+ else
[500, 'There was an error while processing your request']
end
end

0 comments on commit 023b9b4

Please sign in to comment.