We use cookies (just for analytics) on this website. If you continue we will assume you are happy with it. ok

BeBanjo

Back to index

Granted requirement

The granted requirement resource is used to specify the platform requirements a given blackout or right applies to. A given blackout or right will affect to those platforms having all the requirements specified in the granted requirements of the blackout/right.

In Movida, a granted requirement will look like this:

<granted-requirement>
  <id type="integer">1</id>
  <link rel="self" href="https://movida.bebanjo.net/api/granted_requirements/1"/>
  <link rel="requirement" href="https://movida.bebanjo.net/api/requirements/3"/>
</granted-requirement>

Listing all granted requirements of a blackout or right

Granted requirements are accessed via the blackout or right they belong to. Refer to the corresponding resource page, i.e. check the blackout resource to find out how to access a blackout and the right resource to find out how to access a right.

Inside a blackout or a right, one of the related link nodes is the granted_requirements node, identified by the rel attribute.

Example for a blackout:

<?xml version='1.0' encoding='utf-8' ?>
<blackout>
  <!-- ... -->
  <link rel="granted_requirements" href="https://movida.bebanjo.net/api/blackouts/13/granted_requirements"/>
  <!-- ... -->
</blackout>

If we follow that link we can fetch the list of all granted requirements for that blackout.

$ curl --digest -u robot_user:password https://movida.bebanjo.net/api/blackouts/13/granted_requirements
<granted_requirements type="array">
  <granted_requirement>
    <id type="integer">10</id>
    <link rel="self" href="https://movida.bebanjo.net/api/granted_requirements/10"/>
    <link rel="requirement" href="https://movida.bebanjo.net/api/requirements/3"/>
  </granted_requirement>
  <granted_requirement>
    <id type="integer">11</id>
    <link rel="self" href="https://movida.bebanjo.net/api/granted_requirements/11"/>
    <link rel="requirement" href="https://movida.bebanjo.net/api/requirements/2"/>
  </granted_requirement>
</granted_requirements>

Example for a right:

<?xml version='1.0' encoding='utf-8' ?>
<right>
  <!-- ... -->
  <link rel="granted_requirements" href="https://movida.bebanjo.net/api/rights/13/granted_requirements"/>
  <!-- ... -->
</right>

If we follow that link we can fetch the list of all granted requirements for that right.

$ curl --digest -u robot_user:password https://movida.bebanjo.net/api/rights/13/granted_requirements
<granted_requirements type="array">
  <granted_requirement>
    <id type="integer">10</id>
    <link rel="self" href="https://movida.bebanjo.net/api/granted_requirements/10"/>
    <link rel="requirement" href="https://movida.bebanjo.net/api/requirements/3"/>
  </granted_requirement>
  <granted_requirement>
    <id type="integer">11</id>
    <link rel="self" href="https://movida.bebanjo.net/api/granted_requirements/11"/>
    <link rel="requirement" href="https://movida.bebanjo.net/api/requirements/2"/>
  </granted_requirement>
</granted_requirements>

Creating a granted requirement for a blackout or right

To create a new granted requirement, you just need to POST a proper XML granted requirement representation to the granted requirements URL of the resource. That URL can be found in a link which rel attribute equals granted_requirements. The only information required to include in the payload is a link to a requirement.

For example, this POST would create a granted requirement (we’ll use curl’s @ option, which reads data to be posted from a file):

$ cat granted_requirement.xml
<granted_requirement>
  <link rel="requirement" href="https://movida.bebanjo.net/api/requirements/3"/>
</granted_requirement>
$ curl --digest -u robot_user:password -H "Content-Type: application/xml" -X POST -d @granted_requirement.xml "https://movida.bebanjo.net/api/blackouts/13/granted_requirements"

Movida will return the full XML of the granted requirement just created:

<?xml version="1.0" encoding="UTF-8"?>
<granted_requirement>
  <id type="integer">10</id>
  <link rel="self" href="https://movida.bebanjo.net/api/granted_requirements/10"/>
  <link rel="requirement" href="https://movida.bebanjo.net/api/requirements/3"/>
</granted_requirement>

However, you’re not limited to creating one granted_requirement at a time. You can easily create multiple granted requirements with only one API request (and that is, indeed, the preferred way to do it) instead of making multiple consecutive requests.

For that, you’ll need to wrap your granted_requirement entities with a granted_requirements node in the XML payload. For example, this payload will create 3 granted requirements for this blackout:

$ cat granted_requirements_batch.xml
<granted-requirements type="array">
  <granted_requirement>
    <link rel="requirement" href="https://movida.bebanjo.net/api/requirements/3"/>
  </granted_requirement>
  <granted_requirement>
    <link rel="requirement" href="https://movida.bebanjo.net/api/requirements/4"/>
  </granted_requirement>
  <granted_requirement>
    <link rel="requirement" href="https://movida.bebanjo.net/api/requirements/5"/>
  </granted_requirement>
</granted-requirements>
$ curl --digest -u robot_user:password -H "Content-Type: application/xml" -X POST -d @granted_requirements_batch.xml "https://movida.bebanjo.net/api/blackouts/13/granted_requirements"

The response will contain the XML representation of the created entities:

<?xml version="1.0" encoding="UTF-8"?>
<granted-requirements type="array">
  <granted_requirement>
    <id type="integer">10</id>
    <link rel="self" href="https://movida.bebanjo.net/api/granted_requirements/10"/>
    <link rel="requirement" href="https://movida.bebanjo.net/api/requirements/3"/>
  </granted_requirement>
  <granted_requirement>
    <id type="integer">11</id>
    <link rel="self" href="https://movida.bebanjo.net/api/granted_requirements/11"/>
    <link rel="requirement" href="https://movida.bebanjo.net/api/requirements/4"/>
  </granted_requirement>
  <granted_requirement>
    <id type="integer">12</id>
    <link rel="self" href="https://movida.bebanjo.net/api/granted_requirements/12"/>
    <link rel="requirement" href="https://movida.bebanjo.net/api/requirements/5"/>
  </granted_requirement>
</granted-requirements>

Note:

  • The request will either create all of the granted requirements, if all is correct, or none, if there’s any error. Note that all the requirements must previously exist.
  • You just need to include the granted requirements that need to be created in the payload, i.e. you don’t need to include the already existing ones. The granted requirements will be added on top of the existing ones, which will be kept.
  • If you include a granted requirement that already exists in the payload, it’ll be ignored: it won’t be duplicated and it won’t raise any error.
  • Currently, you can create up to 50 granted requirements in this way. If your payload includes more than 50 granted requirements, you’ll receive a 422 HTTP error response.

Updating a granted requirement

You can update granted requirement using a PUT request to the URL of a given granted requirement, as the following example illustrates.

$ cat granted_requirement.xml
<granted_requirement>
  <link rel="requirement" href="https://movida.bebanjo.net/api/requirements/4"/>
</granted_requirement>

Now we send the XML as the body of a PUT request to the granted_requirements’s URL

$ curl --digest -u robot_user:password -H "Content-Type: application/xml" -X PUT -d @granted_requirement.xml "https://movida.bebanjo.net/api/granted_requirements/10"

The PUT request would return the updated XML of the granted requirement:

<granted_requirement>
  <id type="integer">10</id>
  <link rel="self" href="https://movida.bebanjo.net/api/granted_requirements/10"/>
  <link rel="requirement" href="https://movida.bebanjo.net/api/requirements/4"/>
</granted_requirement>

Deleting a granted requirement

The following example shows how to destroy a particular granted requirement. Only a DELETE HTTP request to its URL is required:

$ curl --digest -u robot_user:password -H "Content-Type: application/xml" -X DELETE "https://movida.bebanjo.net/api/granted_requirements/10"

The DELETE request doesn’t return anything, as that granted requirement is now gone.

Deleting a granted requirement doesn’t delete the grantor (blackout or right) nor the requirement.

Last updated October 06th, 2021.