Added groups and organizations
This commit is contained in:
@@ -4,6 +4,7 @@ from .nodes import NodeType
|
||||
from .users import User
|
||||
from .files import File
|
||||
from .tokens import Token
|
||||
from .groups import Group
|
||||
from .binary_files import binaryFile
|
||||
from .exceptions import ResourceNotFound, UnauthorizedAccess, MissingConfig
|
||||
from .config import __version__, __pypi_packagename__
|
||||
|
||||
12
attractsdk/groups.py
Normal file
12
attractsdk/groups.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from .resource import List
|
||||
from .resource import Find
|
||||
from .resource import Create
|
||||
from .resource import Post
|
||||
from .resource import Update
|
||||
from .resource import Delete
|
||||
|
||||
|
||||
class Group(List, Find, Create, Post, Update, Delete):
|
||||
"""Group class wrapping the REST nodes endpoint
|
||||
"""
|
||||
path = "groups"
|
||||
@@ -7,6 +7,7 @@ from .resource import Delete
|
||||
from .resource import Replace
|
||||
|
||||
from . import utils
|
||||
from .api import Api
|
||||
|
||||
|
||||
class Node(List, Find, Create, Post, Update, Delete, Replace):
|
||||
@@ -14,6 +15,22 @@ class Node(List, Find, Create, Post, Update, Delete, Replace):
|
||||
"""
|
||||
path = "nodes"
|
||||
|
||||
@classmethod
|
||||
def find(cls, resource_id, params=None, api=None):
|
||||
"""Locate resource, usually using ObjectID
|
||||
|
||||
Usage::
|
||||
|
||||
>>> Node.find("507f1f77bcf86cd799439011")
|
||||
"""
|
||||
|
||||
api = api or Api.Default()
|
||||
|
||||
url = utils.join_url(cls.path, str(resource_id))
|
||||
if params:
|
||||
url = utils.join_url_params(url, params)
|
||||
return cls(api.get(url))
|
||||
|
||||
|
||||
class NodeType(List, Find, Create, Post, Delete):
|
||||
"""NodeType class wrapping the REST node_types endpoint
|
||||
|
||||
12
attractsdk/organizations.py
Normal file
12
attractsdk/organizations.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from .resource import List
|
||||
from .resource import Find
|
||||
from .resource import Create
|
||||
from .resource import Post
|
||||
from .resource import Update
|
||||
from .resource import Delete
|
||||
|
||||
|
||||
class Organization(List, Find, Create, Post, Update, Delete):
|
||||
"""Organization class wrapping the REST nodes endpoint
|
||||
"""
|
||||
path = "organizations"
|
||||
@@ -114,6 +114,30 @@ class Find(Resource):
|
||||
url = utils.join_url(cls.path, str(resource_id))
|
||||
return cls(api.get(url))
|
||||
|
||||
@classmethod
|
||||
def find_first(cls, params, api=None):
|
||||
"""Get list of resources, allowing some parameters such as:
|
||||
- count
|
||||
- start_time
|
||||
- sort_by
|
||||
- sort_order
|
||||
|
||||
Usage::
|
||||
|
||||
>>> shots = Nodes.all({'count': 2, 'type': 'shot'})
|
||||
"""
|
||||
api = api or Api.Default()
|
||||
|
||||
# Force delivery of only 1 result
|
||||
params['max_results'] = 1
|
||||
url = utils.join_url_params(cls.path, params)
|
||||
|
||||
response = api.get(url)
|
||||
res = cls(response)
|
||||
if res._items:
|
||||
return res._items[0]
|
||||
else:
|
||||
return None
|
||||
|
||||
class List(Resource):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user