Python

  • This will work in any operating system but the library requires Python 3. It won't work with Python 2.
  • The first thing to do is to load your API key. There are two ways to do this. If you store your API key in an environment variable $API_KEY,
from os import environ
from nonlocalbox import NonlocalBox

my_user = NonlocalBox(environ['API_KEY'])
  • If you want, you can copy your API key as a string to the constructor:
from nonlocalbox import NonlocalBox

my_user = NonlocalBox('apikey')
  • Every subsequent API call will return a dictionary that contains the response from the server. The status code is usually not included in this dictionary. If the server returns a non-zero status code, an exception will be raised.

 

List the box types

boxtypes = myuser.list_box_types()

 

Invite a partner

  • An invitation is a two-step process.
  • First, you need to invite your partner, Bob in this case to use the box with ID 1, naming the newly created box 'playwithme'. This call will return the ID of the new box.
  • Second, you need to initialize the my_user object. This will set your role to 'Alice' if you invited someone, and to 'Bob' otherwise.
  • However, if you are the invitee, then you need to ask your partner the ID of the box and initialize your object with that box ID. You don't need to invite anyone in that case.
box_id = my_user.invite('bob', 1, 'playwithme')
my_user.initialize(box_id)

 

List available boxes in which you are the inviter

boxes = my_user.list_boxes()

 

Use a box

  • The object you use will know if you are in role 'Alice' or 'Bob'. This is done by the initialize() call in a previous subsection.
  • This API call will return an integer, the output of the box.
resp = my_user.use(0, '20220914001')