Skip to content

Commit 99eed02

Browse files
committed
Add team member and collaborator management, improve upload/download returns, and improve doc strings
1 parent c83ff04 commit 99eed02

7 files changed

Lines changed: 156 additions & 20 deletions

File tree

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"python.formatting.provider": "black"
3+
}

examples/invite_users.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import os
2+
from frameioclient import FrameioClient
3+
4+
5+
def get_team_list(account_id):
6+
token = os.getenv('FRAMEIO_TOKEN')
7+
client = FrameioClient(token, host='https://api.frame.io')
8+
pass
9+
10+
11+
def invite_users():
12+
pass
13+
14+
15+
if __name__ == "__main__":
16+
invite_users()

examples/user_management.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import os
2+
from frameioclient import FrameioClient
3+
4+
token = os.getenv("FRAMEIO_TOKEN")
5+
6+
users_list = [
7+
"example_2@example.com",
8+
"example_2@example.com"
9+
]
10+
11+
team_id = "35543cd2-954a-c6ee-4aa1-ce9e19602aa9"
12+
13+
client = FrameioClient(token)
14+
client.teams.add_members(team_id, users_list)
15+
client.teams.remove_members(team_id, users_list)

frameioclient/service/assets.py

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,20 @@ def build_asset_info(self, filepath):
181181

182182
return file_info
183183

184-
def upload(self, destination_id, filepath):
184+
def upload(self, destination_id, filepath, asset=None):
185+
"""
186+
Upload a file. The method will exit once the file is downloaded.
187+
188+
:Args:
189+
destination_id (uuid): The destination Project or Folder ID.
190+
filepath (string): The locaiton of the file on your local filesystem \
191+
that you want to upload.
192+
193+
Example::
194+
195+
client.assets.upload('1231-12414-afasfaf-aklsajflaksjfla', "./file.mov")
196+
"""
197+
185198
# Check if destination is a project or folder
186199
# If it's a project, well then we look up its root asset ID, otherwise we use the folder id provided
187200
# Then we start our upload
@@ -194,19 +207,27 @@ def upload(self, destination_id, filepath):
194207
folder_id = Project(self.client).get_project(destination_id)['root_asset_id']
195208
finally:
196209
file_info = self.build_asset_info(filepath)
197-
try:
198-
asset = self.create(folder_id,
199-
type="file",
200-
name=file_info['filename'],
201-
filetype=file_info['mimetype'],
202-
filesize=file_info['filesize']
203-
)
204210

205-
with open(file_info['filepath'], "rb") as fp:
206-
self._upload(asset, fp)
211+
if not asset:
212+
try:
213+
asset = self.create(folder_id,
214+
type="file",
215+
name=file_info['filename'],
216+
filetype=file_info['mimetype'],
217+
filesize=file_info['filesize']
218+
)
219+
220+
except Exception as e:
221+
print(e)
222+
223+
try:
224+
with open(file_info['filepath'], "rb") as fp:
225+
self._upload(asset, fp)
226+
227+
except Exception as e:
228+
print(e)
207229

208-
except Exception as e:
209-
print(e)
230+
return asset
210231

211232
def download(self, asset, download_folder, prefix=None, multi_part=False, concurrency=5):
212233
"""
@@ -218,7 +239,7 @@ def download(self, asset, download_folder, prefix=None, multi_part=False, concur
218239
219240
Example::
220241
221-
client.download(asset, "~./Downloads")
242+
client.assets.download(asset, "~./Downloads")
222243
"""
223244
downloader = FrameioDownloader(asset, download_folder, prefix, multi_part, concurrency)
224245
return downloader.download_handler()

frameioclient/service/projects.py

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,26 @@ def create(self, team_id, **kwargs):
1111
(optional) kwargs: additional request parameters.
1212
1313
Example::
14-
15-
client.projects.create_project(
14+
client.projects.create(
1615
team_id="123",
1716
name="My Awesome Project",
1817
)
1918
"""
2019
endpoint = '/teams/{}/projects'.format(team_id)
2120
return self.client._api_call('post', endpoint, payload=kwargs)
2221

23-
def get_project(self, project_id):
22+
def get(self, project_id):
2423
"""
2524
Get an individual project
2625
2726
:Args:
28-
project_id (string): the project's id
27+
project_id (string): The project's id
28+
29+
Example::
30+
client.project.get(
31+
project_id="123",
32+
)
33+
2934
"""
3035
endpoint = '/projects/{}'.format(project_id)
3136
return self.client._api_call('get', endpoint)
@@ -35,7 +40,13 @@ def get_collaborators(self, project_id, **kwargs):
3540
Get collaborators for a project
3641
3742
:Args:
38-
project_id (string): the project's id
43+
project_id (uuid): The project's id
44+
45+
Example::
46+
client.projects.get_collaborators(
47+
project_id="123"
48+
)
49+
3950
"""
4051
endpoint = "/projects/{}/collaborators?include=project_role".format(project_id)
4152
return self.client._api_call('get', endpoint, kwargs)
@@ -45,7 +56,48 @@ def get_pending_collaborators(self, project_id, **kwargs):
4556
Get pending collaborators for a project
4657
4758
:Args:
48-
project_id (string): the project's id
59+
project_id (uuid): The project's id
60+
61+
Example::
62+
client.projects.get_pending_collaborators(
63+
project_id="123"
64+
)
65+
4966
"""
5067
endpoint = "/projects/{}/pending_collaborators".format(project_id)
5168
return self.client._api_call('get', endpoint, kwargs)
69+
70+
def add_collaborator(self, project_id, email):
71+
"""
72+
Add Collaborator to a Project Collaborator.
73+
74+
:Args:
75+
project_id (uuid): The project id
76+
email (string): Email user's e-mail address
77+
78+
Example::
79+
client.projects.add_collaborator(
80+
project_id="123",
81+
email="",
82+
)
83+
"""
84+
payload = {"email": email}
85+
endpoint = '/projects/{}/collaborators'.format(project_id)
86+
return self._api_call('post', endpoint, payload=payload)
87+
88+
def remove_collaborator(self, project_id, email):
89+
"""
90+
Remove Collaborator from Project.
91+
92+
:Args:
93+
project_id (uuid): The Project ID.
94+
email (string): The user's e-mail address
95+
96+
Example::
97+
client.projects.remove_collaborator(
98+
project_id="123",
99+
email="",
100+
)
101+
"""
102+
endpoint = '/projects/{}/collaborators/_?email={}'.format(project_id, email)
103+
return self._api_call('delete', endpoint)

frameioclient/service/teams.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,32 @@ def list_projects(self, team_id, **kwargs):
7272
"""
7373
endpoint = '/teams/{}/projects'.format(team_id)
7474
return self.client._api_call('get', endpoint, kwargs)
75+
76+
def add_members(self, team_id, emails):
77+
"""
78+
Add a list of users via their e-mail address to a given Team.
79+
80+
:Args:
81+
team_id (string): The team id.
82+
emails (list): The e-mails you want to add.
83+
"""
84+
payload = dict()
85+
payload['batch'] = list(map(lambda email: {"email": email}, emails))
86+
87+
endpoint = '/batch/teams/{}/members'.format(team_id)
88+
return self._api_call('post', endpoint, payload=payload)
89+
90+
def remove_members(self, team_id, emails):
91+
"""
92+
Remove a list of users via their e-mail address from a given Team.
93+
94+
:Args:
95+
team_id (string): The team id.
96+
emails (list): The e-mails you want to add.
97+
"""
98+
99+
payload = dict()
100+
payload['batch'] = list(map(lambda email: {"email": email}, emails))
101+
102+
endpoint = '/batch/teams/{}/members'.format(team_id)
103+
return self._api_call('delete', endpoint, payload=payload)

tests/integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def test_download(client, override=False):
124124
def test_upload(client):
125125
print("Beginning upload test")
126126
# Create new parent asset
127-
project_info = client.projects.get_project(project_id)
127+
project_info = client.projects.get(project_id)
128128
root_asset_id = project_info['root_asset_id']
129129

130130
print("Creating new folder to upload to")

0 commit comments

Comments
 (0)