Skip to content
This repository has been archived by the owner on Feb 13, 2019. It is now read-only.

Commit

Permalink
add targeting to get_embed_url
Browse files Browse the repository at this point in the history
  • Loading branch information
camsom committed May 5, 2015
1 parent cee9b34 commit 34af763
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
9 changes: 7 additions & 2 deletions videohub_client/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,19 @@ def get_hub_url(self):

return url.format(path)

def get_embed_url(self):
def get_embed_url(self, targeting=None):
"""gets a canonical path to an embedded iframe of the video from the hub
:return: the path to create an embedded iframe of the video
:rtype: str
"""
url = getattr(settings, "VIDEOHUB_EMBED_URL", self.DEFAULT_VIDEOHUB_EMBED_URL)
return url.format(self.id)
url = url.format(self.id)
if targeting is not None:
for k, v in targeting.items():
url += '&{0}={1}'.format(k, v)
return url


def get_api_url(self):
"""gets a canonical path to the api detail url of the video on the hub
Expand Down
13 changes: 13 additions & 0 deletions videohub_client/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ def test_embed_url(self):
embed_url,
"http://onionstudios.com/embed?id={}".format(self.video.id))

def test_embed_url_with_targeting(self):
with self.settings(VIDEOHUB_EMBED_URL="http://onionstudios.com/embed?id={}"):
targeting = {
'target_host_channel': 'specialcoverage',
'target_special_coverage': 'joe-biden'
}
embed_url = self.video.get_embed_url(targeting=targeting)
self.assertEquals(
embed_url,
("http://onionstudios.com/embed?id={}&target_host_channel=specialcoverage"
"&target_special_coverage=joe-biden".format(self.video.id))
)

def test_api_url(self):
with self.settings(VIDEOHUB_API_URL="http://onionstudios.com/api/v0/videos/{}"):
api_url = self.video.get_api_url()
Expand Down

0 comments on commit 34af763

Please sign in to comment.