Skip to content

Commit ca5c5ef

Browse files
committed
fix errors with ArchiveList object related to iterating over items
1 parent cf379d7 commit ca5c5ef

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

opentok/archives.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from datetime import datetime, date
2-
from six import iteritems, PY2, PY3
2+
from six import iteritems, PY2, PY3, u
33
import json
44
import pytz
55
if PY3:
@@ -75,7 +75,7 @@ def __init__(self, sdk, values):
7575
def stop(self):
7676
"""
7777
Stops an OpenTok archive that is being recorded.
78-
78+
7979
Archives automatically stop recording after 90 minutes or when all clients have disconnected
8080
from the session being archived.
8181
"""
@@ -86,7 +86,7 @@ def stop(self):
8686
def delete(self):
8787
"""
8888
Deletes an OpenTok archive.
89-
89+
9090
You can only delete an archive which has a status of "available" or "uploaded". Deleting an
9191
archive removes its record from the list of archives. For an "available" archive, it also
9292
removes the archive file, making it unavailable for download.
@@ -108,9 +108,9 @@ def json(self):
108108

109109
class ArchiveList(object):
110110

111-
def __init__(self, values):
111+
def __init__(self, sdk, values):
112112
self.count = values.get('count')
113-
self.items = map(lambda x: Archive(self, x), values.get('items', []))
113+
self.items = list(map(lambda x: Archive(sdk, x), values.get('items', [])))
114114

115115
def __iter__(self):
116116
for x in self.items:
@@ -125,4 +125,11 @@ def attrs(self):
125125
def json(self):
126126
return json.dumps(self.attrs(), default=dthandler, indent=4)
127127

128+
def __getitem__(self, key):
129+
return self.items.get(key)
130+
131+
def __setitem__(self, key, item):
132+
raise ArchiveError(u('Cannot set item {0} for key {1} in Archive object').format(item, key))
128133

134+
def __len__(self):
135+
return len(self.items)

opentok/opentok.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ def get_archives(self, offset=None, count=None):
370370
response = requests.get(self.archive_url() + "?" + urlencode(params), headers=self.archive_headers())
371371

372372
if response.status_code < 300:
373-
return ArchiveList(response.json())
373+
return ArchiveList(self, response.json())
374374
elif response.status_code == 403:
375375
raise AuthError()
376376
elif response.status_code == 404:

0 commit comments

Comments
 (0)