This commit is contained in:
Rémy HUBSCHER 2015-05-21 11:39:22 +02:00
Родитель 167b850a6a
Коммит 233b9ad8fa
2 изменённых файлов: 345 добавлений и 232 удалений

Просмотреть файл

@ -41,7 +41,7 @@ if not on_rtd: # only import and set the theme if we're building docs locally
# Add any Sphinx extension module names here, as strings. They can be # Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones. # ones.
extensions = [] extensions = ['sphinxcontrib.httpdomain']
# Add any paths that contain templates here, relative to this directory. # Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates'] templates_path = ['_templates']

Просмотреть файл

@ -11,18 +11,86 @@ For this examples let's say:
As a user, I want to retrieve my information about my purchases As a user, I want to retrieve my information about my purchases
=============================================================== ===============================================================
.. code-block:: http .. http:get:: /buckets/(bucket_id)/collections/(collection_id)/records
GET /buckets/mozilla/collections/payments/records **Example request**:
Authorization: Bearer <User Firefox Account Bearer Token>
.. sourcecode:: http
HTTP/1.1 200 OK GET /buckets/mozilla/collections/payments/records HTTP/1.1
Content-Type: application/json; charset=UTF-8 Authorization: Bearer <User Firefox Account Bearer Token>
**Example response**:
.. sourcecode:: http
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
{
"items": [
{ {
"items": [
{
"id": "dc86afa9-a839-4ce1-ae02-3d538b75496f",
"last_modified": 1432024555580,
"buyer": "fxa:5331be33303ccff19d3c49b6da276913",
"seller": "hawk:144c22a77d75937740ec3c957fbdb1d1",
"product": "bb5bf35f-cb2b-40e7-b1ef-8b097bd550f2",
"added_on": 1432024555580,
"valid_until": 1463560555580
},
{
"id": "23160c47-27a5-41f6-9164-21d46141804d",
"last_modified": 1430140411480,
"title": "MoFo",
"buyer": "fxa:5331be33303ccff19d3c49b6da276913",
"seller": "hawk:5851128c0c7d72c6845339599b46d092",
"product": "bda9d953-dd81-427d-b7fc-7bcb0df9d666",
"added_on": 1430140411480,
"valid_until": 1432732411480
}
]
}
:statuscode 200: Ok no error.
As the payments app, I want to submit new payment information for a given user
==============================================================================
.. http:post:: /buckets/(bucket_id)/collections/(collection_id)/records
**Example request**:
.. sourcecode:: http
POST /buckets/mozilla/collections/payments/records HTTP/1.1
Authorization: Basic <PaimentApp Basic Auth Credentials>
{
"data": {
"last_modified": 1432024555580,
"buyer": "fxa:5331be33303ccff19d3c49b6da276913",
"seller": "hawk:144c22a77d75937740ec3c957fbdb1d1",
"product": "bb5bf35f-cb2b-40e7-b1ef-8b097bd550f2",
"added_on": 1432024555580,
"valid_until": 1463560555580
},
"permissions": {
"read": ["fxa:5331be33303ccff19d3c49b6da276913",
"hawk:144c22a77d75937740ec3c957fbdb1d1"]
}
}
**Example response**:
.. sourcecode:: http
HTTP/1.1 201 Created
Content-Type: application/json; charset=UTF-8
{
"data": {
"id": "dc86afa9-a839-4ce1-ae02-3d538b75496f", "id": "dc86afa9-a839-4ce1-ae02-3d538b75496f",
"last_modified": 1432024555580, "last_modified": 1432024555580,
"buyer": "fxa:5331be33303ccff19d3c49b6da276913", "buyer": "fxa:5331be33303ccff19d3c49b6da276913",
@ -30,142 +98,122 @@ As a user, I want to retrieve my information about my purchases
"product": "bb5bf35f-cb2b-40e7-b1ef-8b097bd550f2", "product": "bb5bf35f-cb2b-40e7-b1ef-8b097bd550f2",
"added_on": 1432024555580, "added_on": 1432024555580,
"valid_until": 1463560555580 "valid_until": 1463560555580
}, },
{ "permissions": {
"id": "23160c47-27a5-41f6-9164-21d46141804d", "read": ["fxa:5331be33303ccff19d3c49b6da276913",
"last_modified": 1430140411480, "hawk:144c22a77d75937740ec3c957fbdb1d1"]
"title": "MoFo", }
"buyer": "fxa:5331be33303ccff19d3c49b6da276913",
"seller": "hawk:5851128c0c7d72c6845339599b46d092",
"product": "bda9d953-dd81-427d-b7fc-7bcb0df9d666",
"added_on": 1430140411480,
"valid_until": 1432732411480
} }
]
}
:statuscode 201: The record have been created.
As the payments app, I want to submit new payment information for a given user
==============================================================================
.. code-block:: http
POST /buckets/mozilla/collections/payments/records
Authorization: Basic <PaimentApp Basic Auth Credentials>
{
"data": {
"last_modified": 1432024555580,
"buyer": "fxa:5331be33303ccff19d3c49b6da276913",
"seller": "hawk:144c22a77d75937740ec3c957fbdb1d1",
"product": "bb5bf35f-cb2b-40e7-b1ef-8b097bd550f2",
"added_on": 1432024555580,
"valid_until": 1463560555580
},
"permissions": {
"read": ["fxa:5331be33303ccff19d3c49b6da276913",
"hawk:144c22a77d75937740ec3c957fbdb1d1"]
}
}
HTTP/1.1 201 Created
Content-Type: application/json; charset=UTF-8
{
"data": {
"id": "dc86afa9-a839-4ce1-ae02-3d538b75496f",
"last_modified": 1432024555580,
"buyer": "fxa:5331be33303ccff19d3c49b6da276913",
"seller": "hawk:144c22a77d75937740ec3c957fbdb1d1",
"product": "bb5bf35f-cb2b-40e7-b1ef-8b097bd550f2",
"added_on": 1432024555580,
"valid_until": 1463560555580
},
"permissions": {
"read": ["fxa:5331be33303ccff19d3c49b6da276913",
"hawk:144c22a77d75937740ec3c957fbdb1d1"]
}
}
As the payments app, I want to remove an existing payment from the system As the payments app, I want to remove an existing payment from the system
========================================================================= =========================================================================
.. code-block:: http .. http:delete:: /buckets/(bucket_id)/collections/(collection_id)/records/(record_id)
DELETE /buckets/mozilla/collections/payments/records/dc86afa9-a839-4ce1-ae02-3d538b75496f **Example request**:
Authorization: Basic <PaimentApp Basic Auth Credentials>
HTTP/1.1 204 No Content .. sourcecode:: http
DELETE /buckets/mozilla/collections/payments/records/dc86afa9-a839-4ce1-ae02-3d538b75496f HTTP/1.1
Authorization: Basic <PaimentApp Basic Auth Credentials>
**Example response**:
.. sourcecode:: http
HTTP/1.1 204 No Content
:statuscode 204: The record have been deleted without error.
As the payments app, I want to edit an existing payment As the payments app, I want to edit an existing payment
======================================================= =======================================================
Using PUT: .. http:put:: /buckets/(bucket_id)/collections/(collection_id)/records/(record_id)
.. code-block:: http **Example request**:
PUT /buckets/mozilla/collections/payments/records/dc86afa9-a839-4ce1-ae02-3d538b75496f .. sourcecode:: http
Authorization: Basic <PaymentApp Basic Auth credentials>
{ PUT /buckets/mozilla/collections/payments/records/dc86afa9-a839-4ce1-ae02-3d538b75496f HTTP/1.1
"data": { Authorization: Basic <PaymentApp Basic Auth credentials>
"buyer": "fxa:5331be33303ccff19d3c49b6da276913",
"seller": "hawk:144c22a77d75937740ec3c957fbdb1d1",
"product": "bb5bf35f-cb2b-40e7-b1ef-8b097bd550f2",
"added_on": 1432024555580,
"valid_until": 1437208555580
},
"permissions": {
"read": ["fxa:5331be33303ccff19d3c49b6da276913",
"hawk:144c22a77d75937740ec3c957fbdb1d1"]
}
}
HTTP/1.1 200 Ok {
{ "data": {
"data": { "buyer": "fxa:5331be33303ccff19d3c49b6da276913",
"buyer": "fxa:5331be33303ccff19d3c49b6da276913", "seller": "hawk:144c22a77d75937740ec3c957fbdb1d1",
"seller": "hawk:144c22a77d75937740ec3c957fbdb1d1", "product": "bb5bf35f-cb2b-40e7-b1ef-8b097bd550f2",
"product": "bb5bf35f-cb2b-40e7-b1ef-8b097bd550f2", "added_on": 1432024555580,
"added_on": 1432024555580, "valid_until": 1437208555580
"valid_until": 1437208555580 },
}, "permissions": {
"permissions": { "read": ["fxa:5331be33303ccff19d3c49b6da276913",
"read": ["fxa:5331be33303ccff19d3c49b6da276913", "hawk:144c22a77d75937740ec3c957fbdb1d1"]
"hawk:144c22a77d75937740ec3c957fbdb1d1"] }
} }
}
Using PATCH: **Example response**:
.. code-block:: http .. sourcecode:: http
PATCH /buckets/mozilla/collections/payments/records/dc86afa9-a839-4ce1-ae02-3d538b75496f HTTP/1.1 200 Ok
Authorization: Basic <PaymentApp Basic Auth credentials>
{ {
"data": { "data": {
"valid_until": 1437208555580 "buyer": "fxa:5331be33303ccff19d3c49b6da276913",
} "seller": "hawk:144c22a77d75937740ec3c957fbdb1d1",
} "product": "bb5bf35f-cb2b-40e7-b1ef-8b097bd550f2",
"added_on": 1432024555580,
"valid_until": 1437208555580
},
"permissions": {
"read": ["fxa:5331be33303ccff19d3c49b6da276913",
"hawk:144c22a77d75937740ec3c957fbdb1d1"]
}
}
HTTP/1.1 200 Ok :statuscode 200: Ok, no error
{
"data": { .. http:patch:: /buckets/(bucket_id)/collections/(collection_id)/records/(record_id)
"buyer": "fxa:5331be33303ccff19d3c49b6da276913",
"seller": "hawk:144c22a77d75937740ec3c957fbdb1d1", **Example request**:
"product": "bb5bf35f-cb2b-40e7-b1ef-8b097bd550f2",
"added_on": 1432024555580, .. sourcecode:: http
"valid_until": 1437208555580
}, PATCH /buckets/mozilla/collections/payments/records/dc86afa9-a839-4ce1-ae02-3d538b75496f HTTP/1.1
"permissions": { Authorization: Basic <PaymentApp Basic Auth credentials>
"read": ["fxa:5331be33303ccff19d3c49b6da276913",
"hawk:144c22a77d75937740ec3c957fbdb1d1"] {
} "data": {
} "valid_until": 1437208555580
}
}
**Example response**:
.. sourcecode:: http
HTTP/1.1 200 Ok
{
"data": {
"buyer": "fxa:5331be33303ccff19d3c49b6da276913",
"seller": "hawk:144c22a77d75937740ec3c957fbdb1d1",
"product": "bb5bf35f-cb2b-40e7-b1ef-8b097bd550f2",
"added_on": 1432024555580,
"valid_until": 1437208555580
},
"permissions": {
"read": ["fxa:5331be33303ccff19d3c49b6da276913",
"hawk:144c22a77d75937740ec3c957fbdb1d1"]
}
}
:statuscode 200: Ok, no error
As the payments application I want to be able to alter all purchases As the payments application I want to be able to alter all purchases
@ -175,150 +223,215 @@ You'll need to do a BATCH operation with all the sub-operations in there.
- First get the list of records you want to modify. - First get the list of records you want to modify.
.. code-block:: http .. http:get:: /buckets/(bucket_id)/collections/(collection_id)/records
GET /buckets/mozilla/collections/payments/records?seller=hawk:144c22a77d75937740ec3c957fbdb1d1 **Example request**:
Authorization: Basic <PaymentApp Basic Auth credentials>
.. sourcecode:: http
GET /buckets/mozilla/collections/payments/records?seller=hawk:144c22a77d75937740ec3c957fbdb1d1 HTTP/1.1
Authorization: Basic <PaymentApp Basic Auth credentials>
**Example response**:
.. sourcecode:: http
HTTP/1.1 200 OK
HTTP/1.1 200 OK
{
"items": [
{ {
"id": "dc86afa9-a839-4ce1-ae02-3d538b75496f", "items": [
"last_modified": 1432024555580, {
"buyer": "fxa:5331be33303ccff19d3c49b6da276913", "id": "dc86afa9-a839-4ce1-ae02-3d538b75496f",
"seller": "hawk:144c22a77d75937740ec3c957fbdb1d1", "last_modified": 1432024555580,
"product": "bb5bf35f-cb2b-40e7-b1ef-8b097bd550f2", "buyer": "fxa:5331be33303ccff19d3c49b6da276913",
"added_on": 1432024555580, "seller": "hawk:144c22a77d75937740ec3c957fbdb1d1",
"valid_until": 1463560555580 "product": "bb5bf35f-cb2b-40e7-b1ef-8b097bd550f2",
}, "added_on": 1432024555580,
{ "valid_until": 1463560555580
"id": "db4d95e1-c076-4848-950c-cf462b2631f0", },
"last_modified": 1430140411480, {
"title": "MoFo", "id": "db4d95e1-c076-4848-950c-cf462b2631f0",
"buyer": "fxa:465afecea6b565c85fd980a603747fec", "last_modified": 1430140411480,
"seller": "hawk:144c22a77d75937740ec3c957fbdb1d1", "title": "MoFo",
"product": "ecd68f3c-984b-471c-a670-8411e5247358", "buyer": "fxa:465afecea6b565c85fd980a603747fec",
"added_on": 1430140411480, "seller": "hawk:144c22a77d75937740ec3c957fbdb1d1",
"valid_until": 1432732411480 "product": "ecd68f3c-984b-471c-a670-8411e5247358",
"added_on": 1430140411480,
"valid_until": 1432732411480
}
]
} }
]
} :query seller: Filter on the seller app identifier
:statuscode 200: Ok, no error
- Then run a BATCH requests. - Then run a BATCH requests.
If you want to add the ``read`` permission for the seller app to all records of the app, you could use: If you want to add the ``read`` permission for the seller app to all
records of the app, you could use:
.. code-block:: http .. http:post:: /batch
POST /batch **Example request**:
Authorization: Basic <PaymentApp Basic Auth credentials>
{ .. sourcecode:: http
"defaults": {
"method" : "PATCH", POST /batch HTTP/1.1
"data": { Authorization: Basic <PaymentApp Basic Auth credentials>
"permissions": {
"read": ["+hawk:144c22a77d75937740ec3c957fbdb1d1"] {
"defaults": {
"data": {
"permissions": {
"read": [
"+hawk:144c22a77d75937740ec3c957fbdb1d1"
]
}
},
"method": "PATCH"
},
"requests": [
{
"path": "/buckets/mozilla/collections/payments/records/dc86afa9-a839-4ce1-ae02-3d538b75496f"
},
{
"path": "/buckets/mozilla/collections/payments/records/db4d95e1-c076-4848-950c-cf462b2631f0"
}
]
} }
}
},
"requests": [
{
"path" : "/buckets/mozilla/collections/payments/records/dc86afa9-a839-4ce1-ae02-3d538b75496f"
},
{
"path" : "/buckets/mozilla/collections/payments/records/db4d95e1-c076-4848-950c-cf462b2631f0"
}
]
}
As the selling application I want to be able to access the purchase information for agivenuser for my application As the selling application I want to be able to access the purchase information for agivenuser for my application
================================================================================================================= =================================================================================================================
.. code-block:: http .. http:get:: /buckets/(bucket_id)/collections/(collection_id)/records
GET /buckets/mozilla/collections/payments/records?buyer=fxa:5331be33303ccff19d3c49b6da276913 **Example request**:
Authorization: Hawk mac="kDPC...=", hash="B0we...=", id="144c22a77d75937740ec3c957fbdb1d1", ts="1432030137", nonce="mQao38"
.. sourcecode:: http
GET /buckets/mozilla/collections/payments/records?buyer=fxa:5331be33303ccff19d3c49b6da276913 HTTP/1.1
Authorization: Hawk mac="kDPC...=", hash="B0we...=", id="144c22a77d75937740ec3c957fbdb1d1", ts="1432030137", nonce="mQao38"
**Example response**:
.. sourcecode:: http
HTTP/1.1 200 OK
HTTP/1.1 200 OK
{
"items": [
{ {
"id": "dc86afa9-a839-4ce1-ae02-3d538b75496f", "items": [
"last_modified": 1432024555580, {
"buyer": "fxa:5331be33303ccff19d3c49b6da276913", "id": "dc86afa9-a839-4ce1-ae02-3d538b75496f",
"seller": "hawk:144c22a77d75937740ec3c957fbdb1d1", "last_modified": 1432024555580,
"product": "bb5bf35f-cb2b-40e7-b1ef-8b097bd550f2", "buyer": "fxa:5331be33303ccff19d3c49b6da276913",
"added_on": 1432024555580, "seller": "hawk:144c22a77d75937740ec3c957fbdb1d1",
"valid_until": 1463560555580 "product": "bb5bf35f-cb2b-40e7-b1ef-8b097bd550f2",
"added_on": 1432024555580,
"valid_until": 1463560555580
}
]
} }
]
} :query buyer: Filter on the buyer user identifier
:statuscode 200: Ok, no error
As the selling application, I cannot access other selling applications payments As the selling application, I cannot access other selling applications payments
=============================================================================== ===============================================================================
.. code-block:: http .. http:get:: /buckets/(bucket_id)/collections/(collection_id)/records
GET /buckets/mozilla/collections/payments/records?seller=hawk:5331be33303ccff19d3c49b6da276913 **Example request**:
Authorization: Hawk mac="kDPC...=", hash="B0we...=", id="144c22a77d75937740ec3c957fbdb1d1", ts="1432030137", nonce="mQao38"
HTTP/1.1 200 OK .. sourcecode:: http
{
"items": [] GET /buckets/mozilla/collections/payments/records?seller=hawk:5331be33303ccff19d3c49b6da276913 HTTP/1.1
} Authorization: Hawk mac="kDPC...=", hash="B0we...=", id="144c22a77d75937740ec3c957fbdb1d1", ts="1432030137", nonce="mQao38"
**Example response**:
.. sourcecode:: http
HTTP/1.1 200 OK
{
"items": []
}
:query seller: Filter on the seller app identifier
:statuscode 200: no error, but also no items in that case
As a user, I should not be able to edit / add payments As a user, I should not be able to edit / add payments
====================================================== ======================================================
.. code-block:: http .. http:put:: /buckets/(bucket_id)/collections/(collection_id)/records/(record_id)
PUT /buckets/mozilla/collections/payments/records/dc86afa9-a839-4ce1-ae02-3d538b75496f **Example request**:
Authorization: Bearer <User Firefox Account Bearer Token>
{ .. sourcecode:: http
"data": {
"buyer": "fxa:5331be33303ccff19d3c49b6da276913",
"seller": "hawk:144c22a77d75937740ec3c957fbdb1d1",
"product": "bb5bf35f-cb2b-40e7-b1ef-8b097bd550f2",
"added_on": 1432024555580,
"valid_until": 1437208555580
},
"permissions": {
"read": ["fxa:5331be33303ccff19d3c49b6da276913",
"hawk:144c22a77d75937740ec3c957fbdb1d1"]
}
}
HTTP/1.1 403 Forbidden PUT /buckets/mozilla/collections/payments/records/dc86afa9-a839-4ce1-ae02-3d538b75496f HTTP/1.1
Authorization: Bearer <User Firefox Account Bearer Token>
{
"data": {
"buyer": "fxa:5331be33303ccff19d3c49b6da276913",
"seller": "hawk:144c22a77d75937740ec3c957fbdb1d1",
"product": "bb5bf35f-cb2b-40e7-b1ef-8b097bd550f2",
"added_on": 1432024555580,
"valid_until": 1437208555580
},
"permissions": {
"read": ["fxa:5331be33303ccff19d3c49b6da276913",
"hawk:144c22a77d75937740ec3c957fbdb1d1"]
}
}
**Example response**:
.. sourcecode:: http
HTTP/1.1 403 Forbidden
:statuscode 403: Forbidden, the authenticated user cannot modifiy this record.
As the selling application I should not be able to edit / add purchases As the selling application I should not be able to edit / add purchases
======================================================================= =======================================================================
.. code-block:: http .. http:put:: /buckets/(bucket_id)/collections/(collection_id)/records/(record_id)
PUT /buckets/mozilla/collections/payments/records/dc86afa9-a839-4ce1-ae02-3d538b75496f **Example request**:
Authorization: Hawk mac="kDPC...=", hash="B0we...=", id="144c22a77d75937740ec3c957fbdb1d1", ts="1432030137", nonce="mQao38"
{ .. sourcecode:: http
"data": {
"buyer": "fxa:5331be33303ccff19d3c49b6da276913", PUT /buckets/mozilla/collections/payments/records/dc86afa9-a839-4ce1-ae02-3d538b75496f HTTP/1.1
"seller": "hawk:144c22a77d75937740ec3c957fbdb1d1", Authorization: Hawk mac="kDPC...=", hash="B0we...=", id="144c22a77d75937740ec3c957fbdb1d1", ts="1432030137", nonce="mQao38"
"product": "bb5bf35f-cb2b-40e7-b1ef-8b097bd550f2",
"added_on": 1432024555580, {
"valid_until": 1437208555580 "data": {
}, "buyer": "fxa:5331be33303ccff19d3c49b6da276913",
"permissions": { "seller": "hawk:144c22a77d75937740ec3c957fbdb1d1",
"read": ["fxa:5331be33303ccff19d3c49b6da276913", "product": "bb5bf35f-cb2b-40e7-b1ef-8b097bd550f2",
"hawk:144c22a77d75937740ec3c957fbdb1d1"] "added_on": 1432024555580,
} "valid_until": 1437208555580
} },
"permissions": {
"read": ["fxa:5331be33303ccff19d3c49b6da276913",
"hawk:144c22a77d75937740ec3c957fbdb1d1"]
}
}
**Example response**:
.. sourcecode:: http
HTTP/1.1 403 Forbidden
:statuscode 403: Forbidden, the authenticated app cannot modifiy this record.
HTTP/1.1 403 Forbidden
Basically an operation on something not authorized will result in a 403. Basically an operation on something not authorized will result in a 403.