Skip to content

Commit 94daa41

Browse files
author
Amir Tocker
committed
Add streaming profiles API
1 parent f324619 commit 94daa41

File tree

14 files changed

+245
-10
lines changed

14 files changed

+245
-10
lines changed

lib/api.js

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/api.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/utils.js

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/utils.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/v2/api.js

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/v2/api.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api.coffee

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ call_api = (method, uri, params, callback, options) ->
1414
api_key = options["api_key"] ? config().api_key ? throw("Must supply api_key")
1515
api_secret = options["api_secret"] ? config().api_secret ? throw("Must supply api_secret")
1616
api_url = [cloudinary, "v1_1", cloud_name].concat(uri).join("/")
17-
1817
query_params = querystring.stringify(params)
1918
if method == "get"
2019
api_url += "?" + query_params
@@ -256,6 +255,23 @@ exports.publish_by_tag = (tag, callback, options={})->
256255
exports.publish_by_ids = (public_ids, callback, options={})->
257256
publishResource("public_ids", public_ids, callback,options)
258257

258+
exports.list_streaming_profiles = (callback, options = {})->
259+
call_api("get", "streaming_profiles", {}, callback, options)
260+
261+
exports.get_streaming_profile = (name, callback, options = {})->
262+
call_api("get", "streaming_profiles/#{name}", {}, callback, options)
263+
264+
exports.delete_streaming_profile = (name, callback, options = {})->
265+
call_api("delete", "streaming_profiles/#{name}", {}, callback, options)
266+
267+
exports.update_streaming_profile = (name, callback, options = {})->
268+
params = utils.build_streaming_profiles_param(options)
269+
call_api("put", "streaming_profiles/#{name}", params, callback, options)
270+
271+
exports.create_streaming_profile = (name, callback, options = {})->
272+
params = utils.build_streaming_profiles_param(options)
273+
params["name"] = name
274+
call_api("post", 'streaming_profiles', params, callback, options)
259275

260276
exports.only = (hash, keys...) ->
261277
result = {}

src/utils.coffee

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,20 @@ exports.generate_responsive_breakpoints_string = (breakpoints)->
867867
breakpoint_settings.transformation = utils.generate_transformation_string(_.clone(transformation))
868868
JSON.stringify(breakpoints)
869869

870+
exports.build_streaming_profiles_param = (options={})->
871+
params = utils.only(options, "display_name", "representations")
872+
if _.isArray(params["representations"])
873+
params["representations"] = JSON.stringify(params["representations"].map (r)->
874+
{transformation: utils.generate_transformation_string(r.transformation)}
875+
)
876+
params
877+
878+
exports.only = (hash, keys...) ->
879+
result = {}
880+
for key in keys
881+
result[key] = hash[key] if hash[key]?
882+
result
883+
870884
###*
871885
# @private
872886
###

src/v2/api.coffee

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ utils.v1_adapters exports, api,
3535
delete_upload_mapping: 1,
3636
update_upload_mapping: 1,
3737
create_upload_mapping: 1,
38+
list_streaming_profiles: 0,
39+
get_streaming_profile: 1,
40+
delete_streaming_profile: 1,
41+
update_streaming_profile: 1,
42+
create_streaming_profile: 1,
3843
publish_by_ids: 1,
3944
publish_by_tag: 1,
4045
publish_by_prefix: 1

test/api_spec.coffee

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,20 @@ sharedExamples "accepts next_cursor", (testFunc, args...)->
6060
sinon.assert.calledWith requestSpy, sinon.match(query: sinon.match(/next_cursor=23452342/))
6161

6262

63-
6463
describe "api", ->
65-
return console.warn("**** Please setup environment for api test to run!") if !cloudinary.config().api_secret?
64+
before "Verify Configuration", ->
65+
config = cloudinary.config(true)
66+
if(!(config.api_key && config.api_secret))
67+
expect().fail("Missing key and secret. Please set CLOUDINARY_URL.")
6668

6769
after (done)->
6870
if cloudinary.config().keep_test_products
6971
done()
7072
else
73+
config = cloudinary.config()
74+
if(!(config.api_key && config.api_secret))
75+
expect().fail("Missing key and secret. Please set CLOUDINARY_URL.")
76+
7177
cloudinary.v2.api.delete_resources_by_tag helper.TEST_TAG, (error, result) ->
7278
if error?
7379
done(new Error error.message)

0 commit comments

Comments
 (0)