Skip to content

Commit

Permalink
added ability to query stream index by name
Browse files Browse the repository at this point in the history
  • Loading branch information
trshafer committed Sep 8, 2014
1 parent ef68f98 commit e67b0c0
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 23 deletions.
13 changes: 8 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,14 @@
return request.put(requestOptions(url), responseCallback(callback));
};

StreamsHandler.prototype.index = function(callback) {
var params, url;
params = serialize({
secretKey: this.config.secretKey
});
StreamsHandler.prototype.index = function(params, callback) {
var url;
if (typeof params === 'function') {
callback = params;
params = {};
}
params.secretKey = this.config.secretKey;
params = serialize(params);
url = "" + BASE_URL + "/streams?" + params;
return request.get(requestOptions(url), responseCallback(callback));
};
Expand Down
8 changes: 6 additions & 2 deletions src/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,12 @@ class StreamsHandler
request.put requestOptions(url), responseCallback(callback)

# callback(err, streams)
index: (callback)->
params = serialize(secretKey: @config.secretKey)
index: (params, callback)->
if typeof params == 'function'
callback = params
params = {}
params.secretKey = @config.secretKey
params = serialize(params)
url = "#{BASE_URL}/streams?#{params}"
request.get requestOptions(url), responseCallback(callback)

Expand Down
51 changes: 35 additions & 16 deletions test/index_test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,41 @@ describe 'CineIO', ->
@cine = CineIO.init {publicKey: 'my key', secretKey: 'MY SECRET'}

describe 'index', ->
beforeEach ->
@stub = requireFixture('get_streams')

it 'gets the streams', (done)->
@cine.streams.index (err, streams)=>
expect(streams).to.have.length(1)
stream = streams[0]
expect(stream.id).to.equal("the stream id")
expect(stream.streamName).to.equal("the stream name")
expect(stream.expiration).to.equal("2034-05-17T00:00:00.000Z")
expect(stream.password).to.equal("the stream password")
expect(stream.play).to.deep.equal({hls: "the hls url", rtmp: "the rtmp url"})
expect(stream.publish).to.deep.equal({url: "the publish url", stream: "the publish stream"})

expect(@stub.isDone()).to.be.true
done(err)
describe 'without params', ->
beforeEach ->
@stub = requireFixture('get_streams')

it 'gets the streams', (done)->
@cine.streams.index (err, streams)=>
expect(streams).to.have.length(1)
stream = streams[0]
expect(stream.id).to.equal("the stream id")
expect(stream.streamName).to.equal("the stream name")
expect(stream.expiration).to.equal("2034-05-17T00:00:00.000Z")
expect(stream.password).to.equal("the stream password")
expect(stream.play).to.deep.equal({hls: "the hls url", rtmp: "the rtmp url"})
expect(stream.publish).to.deep.equal({url: "the publish url", stream: "the publish stream"})

expect(@stub.isDone()).to.be.true
done(err)

describe 'with name', ->
beforeEach ->
@stub = requireFixture('get_streams_with_name')

it 'gets the streams', (done)->
@cine.streams.index name: 'my name', (err, streams)=>
expect(streams).to.have.length(1)
stream = streams[0]
expect(stream.id).to.equal("the stream id")
expect(stream.streamName).to.equal("the stream name")
expect(stream.expiration).to.equal("2034-05-17T00:00:00.000Z")
expect(stream.password).to.equal("the stream password")
expect(stream.play).to.deep.equal({hls: "the hls url", rtmp: "the rtmp url"})
expect(stream.publish).to.deep.equal({url: "the publish url", stream: "the publish stream"})

expect(@stub.isDone()).to.be.true
done(err)

describe 'get', ->
beforeEach ->
Expand Down
21 changes: 21 additions & 0 deletions test/nock/get_streams_with_name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var response;

response = [{
id: "the stream id",
streamName: "the stream name",
name: 'my name',
play: {
hls: "the hls url",
rtmp: "the rtmp url"
},
publish: {
url: "the publish url",
stream: "the publish stream"
},
expiration: "2034-05-17T00:00:00.000Z",
password: "the stream password"
}];

module.exports = function() {
return nock('https://www.cine.io:443').get('/api/1/-/streams?name=my%20name&secretKey=MY%20SECRET').reply(200, JSON.stringify(response));
};

0 comments on commit e67b0c0

Please sign in to comment.