Skip to content

Commit

Permalink
rminor release for enum34 bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
superdiana committed Jan 11, 2021
1 parent feff9da commit 6481a86
Show file tree
Hide file tree
Showing 29 changed files with 1,806 additions and 2,976 deletions.
12 changes: 7 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Contributing Guidelines

For anyone looking to get involved in this project, we are glad to hear from you. Here are a few types of contributions
For anyone looking to get involved to this project, we are glad to hear from you. Here are a few types of contributions
that we would be interested in hearing about.

* Bug fixes
Expand All @@ -12,12 +12,14 @@ that we would be interested in hearing about.
- If you'd like to accomplish something in the library that it doesn't already do, describe the problem in a new
Github Issue.
- Issues that have been identified as a feature request will be labelled `enhancement`.
- If you'd like to implement the new feature, please wait for feedback from the project maintainers before spending too much time writing the code. In some cases, `enhancement`s may not align well with the project objectives at the time.
- If you'd like to implement the new feature, please wait for feedback from the project maintainers before spending
too much time writing the code. In some cases, `enhancement`s may not align well with the project objectives at
the time.
* Tests, Documentation, Miscellaneous
- If you think the test coverage could be improved, the documentation could be clearer, you've got an alternative
implementation of something that may have more advantages or any other change we would still be glad to hear about
implementation of something that may have more advantages, or any other change we would still be glad hear about
it.
- If it's a trivial change, go ahead and send a Pull Request with the changes you have in mind
- If its a trivial change, go ahead and send a Pull Request with the changes you have in mind
- If not, open a Github Issue to discuss the idea first.

## Requirements
Expand All @@ -35,7 +37,7 @@ continue to add more commits to the branch you have sent the Pull Request from.

1. Fork this repository on GitHub.
1. Clone/fetch your fork to your local development machine.
1. Create a new branch (e.g. `issue-12`, `feat.add_foo`, etc.) and check it out.
1. Create a new branch (e.g. `issue-12`, `feat.add_foo`, etc) and check it out.
1. Make your changes and commit them. (Did the tests pass?)
1. Push your new branch to your fork. (e.g. `git push myname issue-12`)
1. Open a Pull Request from your new branch to the original fork's `master` branch.
Expand Down
65 changes: 27 additions & 38 deletions opentok/archives.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,22 @@
import json
import pytz
from enum import Enum

if PY3:
from datetime import timezone

# compat
from six.moves import map

dthandler = (
lambda obj: obj.isoformat()
if isinstance(obj, datetime) or isinstance(obj, date)
else None
)

dthandler = lambda obj: obj.isoformat() if isinstance(obj, datetime) or isinstance(obj, date) else None

class OutputModes(Enum):
"""List of valid settings for the output_mode parameter of the OpenTok.start_archive()
method."""

composed = u("composed")
composed = u('composed')
"""All streams in the archive are recorded to a single (composed) file."""
individual = u("individual")
individual = u('individual')
"""Each stream in the archive is recorded to an individual file."""


class Archive(object):
"""Represents an archive of an OpenTok session.
Expand Down Expand Up @@ -95,26 +87,22 @@ class Archive(object):

def __init__(self, sdk, values):
self.sdk = sdk
self.id = values.get("id")
self.name = values.get("name")
self.status = values.get("status")
self.session_id = values.get("sessionId")
self.partner_id = values.get("partnerId")
self.id = values.get('id')
self.name = values.get('name')
self.status = values.get('status')
self.session_id = values.get('sessionId')
self.partner_id = values.get('partnerId')
if PY2:
self.created_at = datetime.fromtimestamp(
values.get("createdAt") / 1000, pytz.UTC
)
self.created_at = datetime.fromtimestamp(values.get('createdAt') / 1000, pytz.UTC)
if PY3:
self.created_at = datetime.fromtimestamp(
values.get("createdAt") // 1000, timezone.utc
)
self.size = values.get("size")
self.duration = values.get("duration")
self.has_audio = values.get("hasAudio")
self.has_video = values.get("hasVideo")
self.output_mode = OutputModes[values.get("outputMode", "composed")]
self.url = values.get("url")
self.resolution = values.get("resolution")
self.created_at = datetime.fromtimestamp(values.get('createdAt') // 1000, timezone.utc)
self.size = values.get('size')
self.duration = values.get('duration')
self.has_audio = values.get('hasAudio')
self.has_video = values.get('hasVideo')
self.output_mode = OutputModes[values.get('outputMode', 'composed')]
self.url = values.get('url')
self.resolution = values.get('resolution')

def stop(self):
"""
Expand All @@ -124,7 +112,7 @@ def stop(self):
disconnected from the session being archived.
"""
temp_archive = self.sdk.stop_archive(self.id)
for k, v in iteritems(temp_archive.attrs()):
for k,v in iteritems(temp_archive.attrs()):
setattr(self, k, v)

def delete(self):
Expand All @@ -142,26 +130,29 @@ def attrs(self):
"""
Returns a dictionary of the archive's attributes.
"""
return dict((k, v) for k, v in iteritems(self.__dict__) if k != "sdk")
return dict((k, v) for k, v in iteritems(self.__dict__) if k is not "sdk")

def json(self):
"""
Returns a JSON representation of the archive.
"""
return json.dumps(self.attrs(), default=dthandler, indent=4)


class ArchiveList(object):

def __init__(self, sdk, values):
self.count = values.get("count")
self.items = list(map(lambda x: Archive(sdk, x), values.get("items", [])))
self.count = values.get('count')
self.items = list(map(lambda x: Archive(sdk, x), values.get('items', [])))

def __iter__(self):
for x in self.items:
yield x

def attrs(self):
return {"count": self.count, "items": map(Archive.attrs, self.items)}
return {
'count': self.count,
'items': map(Archive.attrs, self.items)
}

def json(self):
return json.dumps(self.attrs(), default=dthandler, indent=4)
Expand All @@ -170,9 +161,7 @@ def __getitem__(self, key):
return self.items.get(key)

def __setitem__(self, key, item):
raise ArchiveError(
u("Cannot set item {0} for key {1} in Archive object").format(item, key)
)
raise ArchiveError(u('Cannot set item {0} for key {1} in Archive object').format(item, key))

def __len__(self):
return len(self.items)
17 changes: 8 additions & 9 deletions opentok/broadcast.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import json


class Broadcast(object):
"""
Represents a live streaming broadcast
"""

def __init__(self, kwargs):
self.id = kwargs.get("id")
self.sessionId = kwargs.get("sessionId")
self.projectId = kwargs.get("projectId")
self.createdAt = kwargs.get("createdAt")
self.updatedAt = kwargs.get("updatedAt")
self.resolution = kwargs.get("resolution")
self.status = kwargs.get("status")
self.broadcastUrls = kwargs.get("broadcastUrls")
self.id = kwargs.get('id')
self.sessionId = kwargs.get('sessionId')
self.projectId = kwargs.get('projectId')
self.createdAt = kwargs.get('createdAt')
self.updatedAt = kwargs.get('updatedAt')
self.resolution = kwargs.get('resolution')
self.status = kwargs.get('status')
self.broadcastUrls = kwargs.get('broadcastUrls')

def json(self):
"""
Expand Down
105 changes: 21 additions & 84 deletions opentok/endpoints.py
Original file line number Diff line number Diff line change
@@ -1,132 +1,69 @@
import warnings


class Endpoints(object):
"""
For internal use.
Class that provides the endpoint urls
"""

def __init__(self, api_url, api_key):
self.api_url = api_url
self.api_key = api_key

def get_session_url(self):
url = self.api_url + "/session/create"
return url

def session_url(self):
warnings.warn(
"endpoints.session_url is deprecated (use endpoints.get_session_url instead).",
DeprecationWarning,
stacklevel=2,
)

return self.get_session_url()

def get_archive_url(self, archive_id=None):
url = self.api_url + "/v2/project/" + self.api_key + "/archive"
if archive_id:
url = url + "/" + archive_id
url = self.api_url + '/session/create'
return url

def archive_url(self, archive_id=None):
warnings.warn(
"endpoints.archive_url is deprecated (use endpoints.get_archive_url instead).",
DeprecationWarning,
stacklevel=2,
)
return self.get_archive_url(archive_id)
url = self.api_url + '/v2/project/' + self.api_key + '/archive'
if archive_id:
url = url + '/' + archive_id
return url

def get_signaling_url(self, session_id, connection_id=None):
url = self.api_url + "/v2/project/" + self.api_key + "/session/" + session_id
def signaling_url(self, session_id, connection_id=None):
url = self.api_url + '/v2/project/' + self.api_key + '/session/' + session_id

if connection_id:
url += "/connection/" + connection_id
url += '/connection/' + connection_id

url += "/signal"
url += '/signal'
return url

def signaling_url(self, session_id, connection_id=None):
warnings.warn(
"endpoints.signaling_url is deprecated (use endpoints.get_signaling_url instead).",
DeprecationWarning,
stacklevel=2,
)
return self.get_signaling_url(session_id, connection_id)

def get_stream_url(self, session_id, stream_id=None):
""" this method returns the url to get streams information """
url = (
self.api_url
+ "/v2/project/"
+ self.api_key
+ "/session/"
+ session_id
+ "/stream"
)
url = self.api_url + '/v2/project/' + self.api_key + '/session/' + session_id + '/stream'
if stream_id:
url = url + "/" + stream_id
url = url + '/' + stream_id
return url

def broadcast_url(self, broadcast_id=None, stop=False, layout=False):
warnings.warn(
"endpoints.broadcast_url is deprecated (use endpoints.get_broadcast_url instead).",
DeprecationWarning,
stacklevel=2,
)
return self.get_broadcast_url(broadcast_id, stop, layout)

def force_disconnect_url(self, session_id, connection_id):
""" this method returns the force disconnect url endpoint """
url = (
self.api_url
+ "/v2/project/"
+ self.api_key
+ "/session/"
+ session_id
+ "/connection/"
+ connection_id
self.api_url + '/v2/project/' + self.api_key + '/session/' +
session_id + '/connection/' + connection_id
)
return url

def set_archive_layout_url(self, archive_id):
""" this method returns the url to set the archive layout """
url = (
self.api_url
+ "/v2/project/"
+ self.api_key
+ "/archive/"
+ archive_id
+ "/layout"
)
url = self.api_url + '/v2/project/' + self.api_key + '/archive/' + archive_id + '/layout'
return url

def dial_url(self):
""" this method returns the url to initialize a SIP call """
url = self.api_url + "/v2/project/" + self.api_key + "/dial"
url = self.api_url + '/v2/project/' + self.api_key + '/dial'
return url

def set_stream_class_lists_url(self, session_id):
""" this method returns the url to set the stream class list """
url = (
self.api_url
+ "/v2/project/"
+ self.api_key
+ "/session/"
+ session_id
+ "/stream"
)
url = self.api_url + '/v2/project/' + self.api_key + '/session/' + session_id + '/stream'
return url

def get_broadcast_url(self, broadcast_id=None, stop=False, layout=False):
def broadcast_url(self, broadcast_id=None, stop=False, layout=False):
""" this method returns urls for working with broadcast """
url = self.api_url + "/v2/project/" + self.api_key + "/broadcast"
url = self.api_url + '/v2/project/' + self.api_key + '/broadcast'

if broadcast_id:
url = url + "/" + broadcast_id
url = url + '/' + broadcast_id
if stop:
url = url + "/stop"
url = url + '/stop'
if layout:
url = url + "/layout"
url = url + '/layout'
return url
Loading

0 comments on commit 6481a86

Please sign in to comment.