Skip to content

Instantly share code, notes, and snippets.

@seanhess
Created July 22, 2010 17:51
Show Gist options
  • Save seanhess/486327 to your computer and use it in GitHub Desktop.
Save seanhess/486327 to your computer and use it in GitHub Desktop.
diff --git a/lib/itv/app/programs.coffee b/lib/itv/app/programs.coffee
index 3556a38..e43a02c 100644
--- a/lib/itv/app/programs.coffee
+++ b/lib/itv/app/programs.coffee
@@ -9,6 +9,11 @@ exports.load: (dep) ->
# cb (err, program)
exports.details: (programId, cb) ->
db.programs.findOne { _id: programId }, cb
+
+ # Returns all episodes for seriesId
+ # cb (err, episodes)
+ exports.episodes: (seriesId, cb) ->
+ db.programs.find({ seriesId: seriesId }).toArray cb
# Returns the information that one event needs
# cb (err, programWithLimitedFields)
diff --git a/lib/itv/testapi.coffee b/lib/itv/testapi.coffee
index 585eb98..7ce1140 100644
--- a/lib/itv/testapi.coffee
+++ b/lib/itv/testapi.coffee
@@ -9,7 +9,26 @@ exports.load: (dep) ->
if not host? or not port? or not secure? then return "missing host, port or secure. Calls should look like this: cake test:api localhost 6001 false"
api: http.createClient port, host, secure, (cb) ->
-
+
+ #first create a user and get a token
+ user: ''
+ token: ''
+
+ body: call.body
+ length: body.length
+ host: {'host':'localhost', 'Content-Type':'application/json', "User-Agent": "NodeJS HTTP Client", "Content-Length": length}
+ request: api.request POST, '/user', host
+ request.write call.body
+ request.end()
+ request.on 'response', (response) ->
+ response.on 'data', (chunk) ->
+ result+=chunk
+ response.on 'end', () ->
+ result: JSON.parse result
+
+
+
+
for call in calls
result: ''
@@ -126,4 +145,4 @@ if module is require.main
http: require 'http'
dep: require('../../dependency').main()
exports.load dep
- exports.test 'localhost', 6001, false
\ No newline at end of file
+ exports.test 'app1.i.tv', 80, false
\ No newline at end of file
diff --git a/web/apiweb.coffee b/web/apiweb.coffee
index cf94a2c..49bce85 100644
--- a/web/apiweb.coffee
+++ b/web/apiweb.coffee
@@ -500,13 +500,17 @@ app.get '/programs/:programId/credits', (request, response, params) ->
return response.sendfile path.join __dirname, "../lib/mock/show.credits.json"
# @method: GET, implement
-# @uri: '/programs/:programId/episodes'
+# @uri: '/programs/:seriesId/episodes'
# @description: get episodes associated with the program
# @result: {"_id" : "183870","name" : "The X-Files","episodes" : [{"TMSId" : "EP000809550035","season" : "2","episode" : "9","title" : "Firewalker","description" : "Scientists studying an erupting volcano meet mysterious deaths.","origAirDate" : "1994-11-18","datetime" : "2010-06-12T13:00","sourceId" : "65121","prgSvcId" : "55204","new" : "false"},{"TMSId" : "EP000809550038","season" : "2","episode" : "10","title" : "Red Museum","description" : "The detectives probe a link between a cult and disappearances of several Wisconsin children.","origAirDate" : "1994-12-09","datetime" : "2010-06-12T14:00","sourceId" : "65121","prgSvcId" : "55204","new" : "true"},{"TMSId" : "EP000809550039","season" : "2","episode" : "11","title" : "Excelsius Dei","description" : "Mulder and Scully investigate reports of nursing-home occupants encountering supernatural forces.","origAirDate" : "1994-12-16","datetime" : "2010-06-12T15:00","sourceId" : "65121","prgSvcId" : "55204","new" : "false"},]}
-app.get '/programs/:programId/episodes', (request, response, params) ->
- programId: params.programId
- if not programId? then return response.send "Bad Request - missing parameters", 400
- return response.sendfile path.join __dirname, "../lib/mock/show.episodes.json"
+app.get '/programs/:seriesId/episodes', (request, response, params) ->
+ seriesId: params.seriesId
+ if not seriesId? then return response.send "Bad Request - missing parameters", 400
+ programs.episodes seriesId, (err, episodes) ->
+ if err then return response.send err, 500
+ response.send episodes, 200
+
+ #return response.sendfile path.join __dirname, "../lib/mock/show.episodes.json"
# @method: GET, implement
# @uri: '/programs/upcoming/:seriesId/:lineupId'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment