Skip to content

Commit

Permalink
Add api handler for individual change
Browse files Browse the repository at this point in the history
  • Loading branch information
gmjosack committed Jan 5, 2015
1 parent 8774846 commit 19139bd
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
63 changes: 63 additions & 0 deletions nsot/handlers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1334,6 +1334,69 @@ def get(self, site_id):
})


class ChangeHandler(ApiHandler):
def get(self, site_id, change_id):
""" **Get a specific Change**
**Example Request**:
.. sourcecode:: http
GET /api/sites/1/changes/1 HTTP/1.1
Host: localhost
X-NSoT-Email: user@localhost
**Example response**:
.. sourcecode:: http
HTTP/1.1 200 OK
Content-Type: application/json
{
"status": "ok",
"data": {
"change": {
"id": 1,
"site_id": 1,
"user_id": 1,
"change_at": 1420062748,
"event": "Create",
"resource_type": "Site",
"resource_id": 1,
"resource": {
"name": "New Site",
"description": ""
},
}
}
}
:param site_id: ID of the Site to retrieve Changes from.
:type site_id: int
:param change_id: ID of the Change.
:type change_id: int
:reqheader X-NSoT-Email: required for all api requests.
:statuscode 200: The request was successful.
:statuscode 401: The request was made without being logged in.
:statuscode 404: The Site/Change was not found.
"""

change = self.session.query(models.Change).filter_by(
id=change_id, site_id=site_id
).scalar()

if not change:
return self.notfound(
"No such Change ({}) at Site ({})".format(change_id, site_id)
)

self.success({
"change": change.to_dict(),
})

class UsersHandler(ApiHandler):
def get(self):
""" **Get all Users**
Expand Down
1 change: 1 addition & 0 deletions nsot/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

# Change Log
(r"/api/sites/(?P<site_id>\d+)/changes", api.ChangesHandler),
(r"/api/sites/(?P<site_id>\d+)/changes/(?P<change_id>\d+)", api.ChangeHandler),

# Users
(r"/api/users", api.UsersHandler),
Expand Down

0 comments on commit 19139bd

Please sign in to comment.