Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.
Sunti edited this page Apr 1, 2019 · 9 revisions

cryptic-device

Python MicroService for the community project Cryptic-Device

There are two types of models:

Device:

Explanation of data keys:
  1. user_uuid is the unique identifier for a user account in the game.
  2. device_uuid is the unique identifier for a device.
  3. name is the new name for changing a device's name.
There are two types of endpoints:
/public                # The endpoint every user has access to
    /<string:uuid>     # The device's uuid
        /info          # Get information about a device -> device.serialize
        /ping          # Ping a device -> device.powered_on
/private               # The endpoint only the owner has access to
    /<string:uuid>     # The device's uuid
        /info          # Get private information about the device -> device.serialize
        /power         # Turn the device on/off
        /name          # Change the name of the device
        /remove        # Delete a device
    /all               # Get a list of all devices
    /create            # Create a device

File:

Explanation of data keys:
  1. user_uuid is the unique identifier for a user account in the game.
  2. device_uuid is the unique identifier for a device.
  3. file_uuid is the unique identifier for a file of a device.
  4. filename is for creating and updating a file.
  5. content is also for creating and updating a file.
Explanation of endpoints:
/<string:device>        # Endpoint that doesn't require a file uuid
    /<string:uuid>      # Endpoint that requires uuid
        /info           # Get information about a file
        /update         # Update a file
        /remove         # Delete a file
    /all                # Get all files of a device
    /create             # Create a new file

Let's talk about the endpoints:

The first part of the endpoint is either device or file, depending on what you want.

If you want device you now have to choose between public and private.

If you chose public, the next part of the endpoint has to be a device uuid.

Then you have 2 options:

  • The endpoint info provides you information about the device.

input:

{"device_uuid": "aa84a1ea-fd42-4cd0-a5ca-0bc9388d9b14"}  # The device uuid from 3.

returns:

{
    'powered_on': True, 
    'owner': '89f83474-4b65-4467-9bf8-8129d60e3e19',  # The owner
    'uuid': 'aa84a1ea-fd42-4cd0-a5ca-0bc9388d9b14', 
    'power': 1, 
    'name': 'kore'
}
  • The The endpoint ping shows if a device is online.

input:

{"device_uuid": "aa84a1ea-fd42-4cd0-a5ca-0bc9388d9b14"}  # The device uuid from 3.

returns:

{'online': True}

If you chose private you have 2 options.

The next part of the endpoint is either a device uuid, all or create.

The endpoint all returns a list of all devices of a user.

input:

{"user_uuid": "89f83474-4b65-4467-9bf8-8129d60e3e19"}  # The user uuid from your data

returns:

{
    'devices': [{
        'powered_on': True, 
        'owner': '89f83474-4b65-4467-9bf8-8129d60e3e19', 
        'uuid': 'aa84a1ea-fd42-4cd0-a5ca-0bc9388d9b14', 
        'power': 1, 
        'name': 'kore'
    }]
}

The endpoint create creates a new device.

input:

{"user_uuid": "89f83474-4b65-4467-9bf8-8129d60e3e19"}  # The user uuid from your data

returns:

{
    'powered_on': True, 
    'owner': '89f83474-4b65-4467-9bf8-8129d60e3e19', 
    'uuid': 'f817ded2-8f6c-4b58-a5f9-819047d7ff6d', 
    'power': 1, 
    'name': 'dogmatix'
}

If the endpoint is a user uuid you have 4 options.

The endpoint info provides you private information about a device.

input:

{
    'device_uuid': 'aa84a1ea-fd42-4cd0-a5ca-0bc9388d9b14', 
    'user_uuid': '89f83474-4b65-4467-9bf8-8129d60e3e19'
}

returns:

{
    'powered_on': True, 
    'owner': '89f83474-4b65-4467-9bf8-8129d60e3e19', 
    'uuid': 'aa84a1ea-fd42-4cd0-a5ca-0bc9388d9b14', 
    'power': 1, 
    'name': 'kore'
}

The endpoint power turns a device on/off.

input:

{
    'device_uuid': 'aa84a1ea-fd42-4cd0-a5ca-0bc9388d9b14', 
    'user_uuid': '89f83474-4b65-4467-9bf8-8129d60e3e19'
}

returns:

{
    'powered_on': False, 
    'owner': '89f83474-4b65-4467-9bf8-8129d60e3e19', 
    'uuid': 'aa84a1ea-fd42-4cd0-a5ca-0bc9388d9b14', 
    'power': 1, 
    'name': 'kore'
}

The endpoint name changes the name of a device.

input:

{
    'device_uuid': 'aa84a1ea-fd42-4cd0-a5ca-0bc9388d9b14', 
    'user_uuid': '89f83474-4b65-4467-9bf8-8129d60e3e19',
    'name': 'quint'
}

returns:

{
    'powered_on': True, 
    'owner': '89f83474-4b65-4467-9bf8-8129d60e3e19', 
    'uuid': 'aa84a1ea-fd42-4cd0-a5ca-0bc9388d9b14', 
    'power': 1, 
    'name': 'quint'
}

The endpoint remove deletes the device

input:

{
    'device_uuid': 'aa84a1ea-fd42-4cd0-a5ca-0bc9388d9b14', 
    'user_uuid': '89f83474-4b65-4467-9bf8-8129d60e3e19'
}

returns:

{'ok': True}

If you want the file your next part of the endpoint is a device uuid

The next part of the endpoint is a device uuid.

Now you you chose between the endpoints all, create or a user uuid.

If you chose create the input data looks like this:

input:

{
    'user_uuid': '89f83474-4b65-4467-9bf8-8129d60e3e19', 
    'device_uuid': '366a52a1-4f02-4087-a164-7c81a443b7d3', 
    'filename': 'cryptic', 
    'content': 'the best'
}

returns:

{
    'device': '366a52a1-4f02-4087-a164-7c81a443b7d3', 
    'filename': 'cryptic', 
    'uuid': '3fa20793-41cf-4508-bf54-476acc8b4c23', 
    'content': 'the best'
}

If you chose all your input and output looks like this:

input:

{
    'user_uuid': '89f83474-4b65-4467-9bf8-8129d60e3e19', 
    'device_uuid': '366a52a1-4f02-4087-a164-7c81a443b7d3', 
    'filename': 'cryptic', 
    'content': 'the best'
}

returns:

{
    'files': [{
        'device': '366a52a1-4f02-4087-a164-7c81a443b7d3', 
        'content': 'the best', 
        'uuid': '3fa20793-41cf-4508-bf54-476acc8b4c23', 
        'filename': 'cryptic'
    }]
}

Else you next part of the endpoint is a file uuid.

The endpoint info gives you some information about the file.

input:

{
    'user_uuid': '89f83474-4b65-4467-9bf8-8129d60e3e19', 
    'device_uuid': '366a52a1-4f02-4087-a164-7c81a443b7d3', 
    'filename': 'cryptic', 
    'content': 'the best', 
    'file_uuid': '718a808a-4001-46d1-9c36-b036f06d110e'
}

returns:

{
    'device': '366a52a1-4f02-4087-a164-7c81a443b7d3', 
    'content': 'the best', 
    'uuid': '718a808a-4001-46d1-9c36-b036f06d110e', 
    'filename': 'cryptic'
}

The endpoint removes deletes a file:

input:

{
    'user_uuid': '89f83474-4b65-4467-9bf8-8129d60e3e19', 
    'device_uuid': '366a52a1-4f02-4087-a164-7c81a443b7d3', 
    'filename': 'cryptic', 
    'content': 'the best', 
    'file_uuid': '718a808a-4001-46d1-9c36-b036f06d110e'
}

returns:

{'ok': True}

The endpoint update updates a file:

input:

{
    'user_uuid': '9ec72068-5d62-45d5-bedf-612794ae6988', 
    'device_uuid': '42e4d805-c627-413c-98d0-b618ae7e1754', 
    'filename': 'new', 
    'content': 'the better one', 
    'file_uuid': '694f8bf2-b38e-4b0e-8266-b8c6864ab824'
}

returns:

{
    'device': '42e4d805-c627-413c-98d0-b618ae7e1754', 
    'content': 'the better one', 
    'uuid': '694f8bf2-b38e-4b0e-8266-b8c6864ab824', 
    'filename': 'new'
}

If something goes wrong, try to print the ['error'] of the response.

Clone this wiki locally