Python Examples

Sample: Creating a Background Burn

Code

import json
import requests
import pprint

pp = pprint.PrettyPrinter(indent=4)

url = "https://api.bonanza.com/api/background_burns"

api_key = "your_api_key"
user_id = "your_user_id"

payload = {
  "url": "https://bonanzapublic.s3.amazonaws.com/images/background_burner/colorful_bag.jpg",
  "key": api_key,
  "user_id": user_id,
}

create_response = requests.post(url, data=payload)
create_result = create_response.json()
pp.pprint(create_result)

Data

The result printed by the final line above will be:

{   u'access_token': u'abc',
    u'action': u'create',
    u'burn_user_id': 1,
    u'complete': False,
    u'final_result_url': None,
    u'id': 5141,
    u'masks': [],
    u'message': u'Successfully queued',
    u'position_in_queue': 27,
    u'review_complete': False,
    u'selected_mask_id': None,
    u'source_image_url': u'http://bonanzaimagestest.s3.amazonaws.com/uploads/burnees/1477070571-12394-0024-0318.jpg',
    u'url': u'http://burner.bonanza.com/background_burns/5141',
    u'user_id': u'1'}

Sample: Showing a Background Burn

Building off the code above to create a Background Burn, you can extract the burn ID from the create result:

burn_id = create_result["id"]

Using this ID, you can get the current status of the Background Burn:

show_url = "{url}/{burn_id}?key={api_key}&user_id={user_id}".format(**locals())
show_response = requests.get(show_url)
pp.pprint(show_response.json())

Data

The result of printing show_response will be:

{   u'access_token': u'abc',
    u'action': u'show',
    u'burn_user_id': 1,
    u'complete': False,
    u'final_result_url': None,
    u'id': 5141,
    u'masks': [],
    u'message': u'Found existing burn for user 18 with id: 5141',
    u'position_in_queue': 27,
    u'review_complete': False,
    u'selected_mask_id': None,
    u'source_image_url': u'http://bonanzaimagestest.s3.amazonaws.com/uploads/burnees/1477070571-12394-0024-0318.jpg',
    u'url': u'http://burner.bonanza.com/background_burns/5141',
    u'user_id': u'1'}

Sample: Deleting a Background Burn

To archive (effectively deleting) a Background Burn, building on the previous examples:

delete_url = "{url}/{burn_id}?key={api_key}&user_id={user_id}".format(**locals())
delete_response = requests.delete(delete_url)
pp.pprint(delete_response.json())

Data

The result of printing the delete_response above will be:

{   u'access_token': u'abc',
    u'action': u'destroy',
    u'burn_user_id': 1,
    u'complete': False,
    u'final_result_url': None,
    u'id': 5141,
    u'masks': [],
    u'message': u'Archived burn with id: 5141',
    u'position_in_queue': 27,
    u'review_complete': False,
    u'selected_mask_id': None,
    u'source_image_url': u'http://bonanzaimagestest.s3.amazonaws.com/uploads/burnees/1477070571-12394-0024-0318.jpg',
    u'url': u'http://burner.bonanza.com/background_burns/5141',
    u'user_id': u'1'}

Sample: Listing Background Burns

Code

To get a list of Background Burns you have submitted:

index_url = "{url}?key={api_key}&user_id={user_id}".format(**locals())
index_response = requests.get(index_url)
pp.pprint(index_response.json())

Data

The result of printing index_response above will be:

{   u'access_token': u'abc',
    u'action': u'index',
    u'background_burns': [   {   u'complete': False,
                                 u'final_result_url': None,
                                 u'id': 5139,
                                 u'masks': [],
                                 u'position_in_queue': 25,
                                 u'review_complete': False,
                                 u'selected_mask_id': None,
                                 u'source_image_url': u'http://bonanzaimagestest.s3.amazonaws.com/uploads/burnees/1477070268-12394-0022-1662.jpg',
                                 u'url': u'http://burner.bonanza.com/background_burns/5139'},
                             {   u'complete': False,
                                 u'final_result_url': None,
                                 u'id': 5138,
                                 u'masks': [],
                                 u'position_in_queue': 24,
                                 u'review_complete': False,
                                 u'selected_mask_id': None,
                                 u'source_image_url': u'http://bonanzaimagestest.s3.amazonaws.com/uploads/burnees/1477070221-12394-0021-4561.jpg',
                                 u'url': u'http://burner.bonanza.com/background_burns/5138'},
    u'burn_user_id': 1,
    u'count': 2,
    u'message': u'Success',
    u'user_id': u'1'}

Sample: Updating a Background Burn

Code

Given a Background Burn that has a mask result, as returned from the index or show actions, e.g.:

u'masks': [   {   
        u'composite_url': u'http://burner.bonanza.com/background_masks/53487714.png?1477071771&composite=true&no_crop=false&transparent=false',
        u'id': 53487714,
        u'quality_score': 506,
        u'url': u'http://burner.bonanza.com/background_masks/53487714.png?',
        u'variation': u'flooded'}]

You can select the final mask:

update_payload = {
  "key": api_key,
  "user_id": user_id,
  "selected_mask_id": 53487714
}

update_url = "{url}/{burn_id}".format(**locals())
update_response = requests.put(update_url, update_payload)
pp.pprint(update_response.json())

Data

The result of printing update_response above will be:

{   u'access_token': u'abv',
    u'action': u'update',
    u'burn_user_id': 1,
    u'complete': True,
    u'final_result_url': u'https://images.bonanzastatic.com/uploads/burns/16599244.jpg?1477071758',
    u'id': 16599244,
    u'masks': [   {   u'composite_url': u'http://burner.bonanza.com/background_masks/53487685.png?1477072100&composite=true&no_crop=false&transparent=false',
                      u'id': 53487685,
                      u'quality_score': 506,
                      u'url': u'http://burner.bonanza.com/background_masks/53487685.png?',
                      u'variation': u'flooded'},
                  {   u'composite_url': u'http://burner.bonanza.com/background_masks/53487702.png?1477072100&composite=true&no_crop=false&transparent=false',
                      u'id': 53487702,
                      u'quality_score': 495,
                      u'url': u'http://burner.bonanza.com/background_masks/53487702.png?',
                      u'variation': u'adjacent-probable'},
                  {   u'composite_url': u'http://burner.bonanza.com/background_masks/53487703.png?1477072100&composite=true&no_crop=false&transparent=false',
                      u'id': 53487703,
                      u'quality_score': 481,
                      u'url': u'http://burner.bonanza.com/background_masks/53487703.png?',
                      u'variation': u'raw-probable'},
                  {   u'composite_url': u'http://burner.bonanza.com/background_masks/53487704.png?1477072100&composite=true&no_crop=false&transparent=false',
                      u'id': 53487704,
                      u'quality_score': 435,
                      u'url': u'http://burner.bonanza.com/background_masks/53487704.png?',
                      u'variation': u'side_burn-probable'},
                  {   u'composite_url': u'http://burner.bonanza.com/background_masks/53487705.png?1477072100&composite=true&no_crop=false&transparent=false',
                      u'id': 53487705,
                      u'quality_score': 434,
                      u'url': u'http://burner.bonanza.com/background_masks/53487705.png?',
                      u'variation': u'bg-probable'}],
    u'message': u'Saved final mask for burn with id: 16599244',
    u'position_in_queue': 0,
    u'review_complete': False,
    u'selected_mask_id': 53487714,
    u'source_image_url': u'https://images.bonanzastatic.com/uploads/burnees/1477071734-3877314-0001-7229.jpg',
    u'url': u'http://burner.bonanza.com/background_burns/16599244',
    u'user_id': u'1'}