Skip to content

Instantly share code, notes, and snippets.

@martastain
Last active July 27, 2016 14:04
Show Gist options
  • Save martastain/2317fa6deb6783e5799465ad5b17f60c to your computer and use it in GitHub Desktop.
Save martastain/2317fa6deb6783e5799465ad5b17f60c to your computer and use it in GitHub Desktop.
MAM API Draft

MAM API draft

This draft only handles asset creation, editing and viewing. It does not deal with:

  • API versioning
  • authentication
  • job control
  • rundown edit

All requests are http posts to api entry point. POST payload is JSON request specified below. API server always returns HTTP response code 200, and JSON reply in the body.

Get object data

Request /api/get

{
    "fulltext" : "interview",
    "filters" : {
            "ctime" : ["gt", 1467200000]
        },
    "ids" : [],
    "count" : true,
    "limit" : 100,
    "offset" : 0,
    "result" : false,
}
  • fulltext - fulltext query
  • filters - additional filters. TBD
  • ids - if specified, result will return list of object specified by ids in this list. fulltext and filters will be ignored
  • count - (optional, default false). Return count of all matching objects (for pagination)
  • limit - (optional, default 0). Max count per page
  • offset - (optional, default 0)
  • object_type - (optional, default "asset")
  • result - (optional, default false) type of the result. See "Result specification" section

Result

{
    "response" : 200,
    "message" : "one asset found in 0.0000001 second",
    "count" : 1,
    "data" : [
        {
            "id_asset" : 1,
            "title" : "Interview part 1",
            "ctime" : 1467184934,
            "mtime" : 1467220000,
        }
    ]
}

Result specification

####full

"result" : false

if not specified or false, result will contain list of asset metadata dicts (previous example)

id

"result" : "id"

returns list of matching ids:

"data" : [1]

list of keys

"result" : ["id", "title", "duration"]

returns list of list of requested values.

"data" : [
    [1, "Interview part 1"]
]

Object creation and update

Request /api/set

{
    "data" : {
            "title" : "Interview part 2",
        },
    "echo" : true
}
  • data
  • object_type - (optional, default "asset")
  • echo

Response

{
    "response" : 201,
    "message" : "Asset created",
    "data" : {
            "id" : 2,
            "title" : "Interview part 2",
            "ctime" : 1467219595,
            "mtime" : 1467219595,
        }
}
  • response - status code. always present
  • message - human readable message. always present
  • data - metadata of the created object. present only if "echo" param in request is true.

Additionaly, if list of object ids is specified, set method allows single object or batch metadata editing.

{
   "ids" : [1,2],
   "data" : {
            "editorial_format" : "interview",
            "director" : "John Doe"
       },
    "echo" : true
}

Result

{
    "response" : 200,
    "message" : "2 assets updated",
    "data" : [
        {
            "id" : 1,
            "title" : "Interview part 1",
            "editorial_format" : "interview",
            "director" : "John Doe",
            "ctime" : 1467184934,
            "mtime" : 1467220000,
        },

        {
            "id" : 2,
            "title" : "Interview part 2",
            "editorial_format" : "interview",
            "director" : "John Doe",
            "ctime" : 1467219595,
            "mtime" : 1467220000,
        }
    ]
}
  • response - status code. always present
  • message - human readable message. always present
  • data - metadata of the updated objects (list of dicts). present only if "echo" param in request is true.

Asset deletion

Since deletion is just a metadata flag, trashing can be done using set request.

import json
import requests
class NebulaApi():
def __init__(self, host, login, password):
self.host = host
self.cookies = None
self.login(login, password)
def login(self, login, password):
data = {"login" : login, "password" : password}
response = requests.post(self.host + "/login", data)
self.cookies = response.cookies
def run(self, method, **kwargs):
response = requests.post(
self.host + "/api/" + method,
data=json.dumps(kwargs),
cookies=self.cookies
)
self.cookies = response.cookies
return json.loads(response.text)
def __getattr__(self, method_name):
def wrapper(**kwargs):
return self.run(method_name, **kwargs)
return wrapper
if __name__ == "__main__":
import time
api = NebulaApi("http://localhost:8001", "demo", "demo")
print api.get(fulltext="furiko")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment