Resources

Create and manage your resources.

Create

  • URL: http://api.bugswarm.net/resources
  • Method: POST
  • Headers:
    "x-bugswarmapikey: ${API_KEY}",
    "content-type: application/json"
  • Parameters (Required): None
  • Parameters (Optional): None

Resources belong to users and may be created using this method. In order for a user's resource to participate in a swarm, however, the user must first add that resource to the swarm. Creating a resource involves passing a JSON object containing the resource's meta-data.

Body: The "name", and "machine_type" fields are required. The "description" and "position" fields are optional.
{
    "name": "My resource",
    "machine_type": "pc", # current valid types are "pc", "bug", and "smartphone"
    "description": "My Resource description",
    "position": {
                    "longitude": 0,
                    "latitude": 0
    }
}

Usage: Create a JSON file with the name create_resource.json and matching the above format. Then execute:
curl -X POST -d@create_resource.json --header "x-bugswarmapikey: 911cbc244827dba9c6dbdd09aff3e5e8fe5eee02" --header "content-type: application/json" http://api.bugswarm.net/resources          
Returns: The created resource as a JSON object.
{
    "id": "4735f4417f4fd2eb67ace9f2d2e7948e2d9f43f9",
    "user_id": "username",
    "description": "My Resource description",
    "machine_type": "pc",
    "name": "My resource",
    "created_at": "2011-10-09T22:58:39.710Z",
    "position": {
                    "longitude": 0,
                    "latitude": 0
    }
}

Update

  • URL: http://api.bugswarm.net/resources/RESOURCE_ID
  • Method: PUT
  • Headers:
    "x-bugswarmapikey: ${API_KEY}",
    "content-type: application/json"
  • Parameters (Required): None
  • Parameters (Optional): None

Resources belonging to a given user can have some of their information updated after creation. Updating a resource involves passing a JSON object containing the fields that the user wishes to update.

Body: All fields are optional.
{
    "name": "My Resource Updated",
    "machine_type": "bug",
    "description": "My Resource description updated",
    "position": {
                    "longitude": 1,
                    "latitude": 1
    }
}

Usage: Create a JSON file with the name update_resource.json and matching the above format. Then execute:
curl -X PUT -d@update_resource.json --header "x-bugswarmapikey: 911cbc244827dba9c6dbdd09aff3e5e8fe5eee02" --header "content-type: application/json" http://api.bugswarm.net/resources/RESOURCE_ID

Returns: The updated resource as a JSON object, including a "modified_at" field.
{
    "modified_at": "2011-10-10T00:12:58.354Z",
    "id": "4735f4417f4fd2eb67ace9f2d2e7948e2d9f43f9",
    "user_id": "username",
    "description": "My Resource description updated",
    "machine_type": "bug",
    "name": "My Resource Updated",
    "created_at": "2011-10-09T22:58:39.710Z",
    "position": {
                    "longitude": 1,
                    "latitude": 1
    }
}

Destroy

  • URL: http://api.bugswarm.net/resources/RESOURCE_ID
  • Method: DELETE
  • Headers: "x-bugswarmapikey: ${API_KEY}"
  • Parameters (Required): None
  • Parameters (Optional): None

Destroying a resource removes it completely from the user account and any swarms of which it is a member. The method uses the unique resource id specified in the URL to determine which resource to destroy.

Usage:
curl -X DELETE --header "x-bugswarmapikey: 911cbc244827dba9c6dbdd09aff3e5e8fe5eee02" http://api.bugswarm.net/resources/RESOURCE_ID          

Returns: HTTP Response Codes

List

  • URL: http://api.bugswarm.net/resources
  • Method: GET
  • Headers:
    "x-bugswarmapikey: ${API_KEY}"
  • Parameters (Required): None
  • Parameters (Optional): None

List all of the resources belonging to the user.

Usage:
curl -X GET --header "x-bugswarmapikey: 911cbc244827dba9c6dbdd09aff3e5e8fe5eee02" http://api.bugswarm.net/resources

Returns: A list of resources as a JSON array.
[
  {
    "id": "33e675f7888c1d7f6f5da41bcccdff7b67f6c9a0"
    "user_id": "username",
    "description": "My Resource description",
    "machine_type": "pc",
    "name": "My resource",
    "created_at": "2011-10-09T22:58:39.710Z",
    "position": {
                    "longitude": 0,
                    "latitude": 0
    }
  },
  {
    "id": "4735f4417f4fd2eb67ace9f2d2e7948e2d9f43f9",
    "user_id": "username",
    "description": "My Other Resource description",
    "machine_type": "bug",
    "name": "My other resource",
    "created_at": "2011-10-09T22:58:39.710Z",
    "position": {
                    "longitude": 0,
                    "latitude": 0
    }
  }
]

Get Info

  • URL: http://api.bugswarm.net/resources/RESOURCE_ID
  • Method: GET
  • Headers:
    "x-bugswarmapikey: ${API_KEY}"
  • Parameters (Required): None
  • Parameters (Optional): None

This method returns the given resource and its meta-data as a JSON object.

Usage:
curl -X GET --header "x-bugswarmapikey: 911cbc244827dba9c6dbdd09aff3e5e8fe5eee02" http://api.bugswarm.net/resources/RESOURCE_ID

Returns: A resource as a JSON object.
{
    "id": "4735f4417f4fd2eb67ace9f2d2e7948e2d9f43f9",
    "user_id": "username",
    "description": "My Resource description",
    "machine_type": "pc",
    "name": "My resource",
    "created_at": "2011-10-09T22:58:39.710Z",
    "position": {
                    "longitude": 0,
                    "latitude": 0
    }
}

List Swarms

  • URL: http://api.bugswarm.net/resources/RESOURCE_ID/swarms
  • Method: GET
  • Headers:
    "x-bugswarmapikey: ${API_KEY}"
  • Parameters (Required): None
  • Parameters (Optional): None

Resources can be added to one or many swarms. This method takes a unique resource id and lists all of the swarms of which that resource is a member. A JSON array of the swarm(s) and their resources is printed.

Usage:
curl -X GET --header "x-bugswarmapikey: 911cbc244827dba9c6dbdd09aff3e5e8fe5eee02" http://api.bugswarm.net/resources/RESOURCE_ID/swarms

Returns: A list of swarms that the given resource is a member as a JSON array.
[
    {
        "id": "a16fb1d896817c58d4f4be9dea51e74b86519579",
        "user_id": "username",
        "description": "My Swarm description",
        "name": "My Swarm",
        "created_at": "2011-08-29T20:17:08.676Z",
        "resources": [
            {
                "resource_id": "33e675f7888c1d7f6f5da41bcccdff7b67f6c9a0",
                "resource_type": "producer",
                "user_id": "username",
                "url": "http://api.bugswarm.net/resources/33e675f7888c1d7f6f5da41bcccdff7b67f6c9a0"
            },
            {
                "resource_id": "4735f4417f4fd2eb67ace9f2d2e7948e2d9f43f9",
                "resource_type": "both",
                "user_id": "username",
                "url": "http://api.bugswarm.net/resources/4735f4417f4fd2eb67ace9f2d2e7948e2d9f43f9"
            }
        ],
        "public": true
    },
    {
        "id": "92236421f64633430baa54fd9848e03aa2696111",
        "user_id": "username",
        "description": "My Other Swarm description",
        "name": "My Other Swarm",
        "created_at": "2011-08-29T20:17:08.676Z",
        "resources": [
            {
                "resource_id": "33e675f7888c1d7f6f5da41bcccdff7b67f6c9a0",
                "resource_type": "consumer",
                "user_id": "username",
                "url": "http://api.bugswarm.net/resources/33e675f7888c1d7f6f5da41bcccdff7b67f6c9a0"
            }                      
        ],
        "public": false
    }
]