Skip to content

Commit

Permalink
Added an API to get channel info
Browse files Browse the repository at this point in the history
  • Loading branch information
ineentho committed May 24, 2015
1 parent 5599d12 commit 918844f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
8 changes: 7 additions & 1 deletion server/api_channel.py
Expand Up @@ -84,6 +84,12 @@ def register_channel():
if not params:
return invalid_request('The request body is not valid JSON')

# Hosted By: The name of the hoster
if 'hosted-by' not in params:
return invalid_parameter('hosted-by', 'Hosted by is required')
if len(params['hosted-by']) > 80:
return invalid_parameter('hosted-by', 'Hosted by is too long (max 80 chars)')

# name: The channel name, required. Can contain any letters.
if 'name' not in params:
return invalid_parameter('name', 'A channel name is required')
Expand Down Expand Up @@ -115,7 +121,7 @@ def register_channel():
return invalid_parameter('password', 'A password is required')

try:
create_channel(params['name'], params['slug'], params['url'], params['password'])
create_channel(params['name'], params['slug'], params['url'], params['password'], params['hosted-by'])
except ChannelExistsError:
return invalid_parameter('slug', 'The slug is already in use')

Expand Down
11 changes: 11 additions & 0 deletions server/api_public.py
Expand Up @@ -38,6 +38,17 @@ def list_channels(page=1):
})
return jsonify(dict(base_resp, channels=channel_list))

@app.route('/api/channel/<int:id>')
def channel_by_url(id):
ch = Channel.query.filter_by(id=id).first()

return jsonify({
'channel': ch.name,
'slug': ch.slug,
'url': ch.url,
'hosted-by': ch.hosted_by
})

@app.route('/api/videos/')
@app.route('/api/videos/<int:page>')
def list_videos(page=1):
Expand Down
8 changes: 5 additions & 3 deletions server/channel.py
Expand Up @@ -31,8 +31,8 @@ def authenticate_channel(slug, password):
return channel


def create_channel(name, slug, url, password):
channel = Channel(name, slug, url, password)
def create_channel(name, slug, url, password, hosted_by):
channel = Channel(name, slug, url, password, hosted_by)

db.session.add(channel)

Expand Down Expand Up @@ -60,15 +60,17 @@ class Channel(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(80))
slug = db.Column(db.String(80), unique=True)
hosted_by = db.Column(db.String(80))
url = db.Column(db.String(256))
password = db.Column(db.LargeBinary(256), unique=True)
videos = db.relationship('Video', backref='channel')

def __init__(self, name, slug, url, password):
def __init__(self, name, slug, url, password, hosted_by):
self.name = name
self.password = hash_password(password)
self.url = url
self.slug = slug
self.hosted_by = hosted_by


class Video(db.Model):
Expand Down

0 comments on commit 918844f

Please sign in to comment.