Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit ad26e97a6d3c9435befe130a43194a1bdcd57a9e @TalLevAmi TalLevAmi committed Jun 5, 2013
@@ -0,0 +1 @@
+cloud/cloudinary_config.js
126 README.md
@@ -0,0 +1,126 @@
+# Cloud code
+This package contains Cloudinary's integration pack for Parse Cloud Code.
+The cloudinary library provides a mechanism for storing cloudinary credentials and signing upload requests.
+Also provided in this package is sample code of a simple Cloud Function that signs upload requests for authenticated users.
+
+## Files
+
+* `cloud/main.js` - The main cloud code file loaded by parse. Contains a sample cloud function (`sign_upload_request`) that returns an object with all required parameters to initiate a direct upload to cloudinary.
+The sample function requires an authenticated Parse user and embeds the username into the tags field.
+The returned data can be used to construct an HTML form or passed to cloudinary front-end libraries to initiate an image upload.
+* `cloud/cloudinary/all.js` - The cloudinary library entrypoint. In order to load cloudinary library you must `require('cloud/cloudinary/all')` the result of this expression is the cloudinary namespace. See `cloud/main.js` for sample usage.
+* `cloud/cloudinary_config.js` holds cloudinary configuration as demonstrated in `cloud/cloudinary_config.js.sample`
+
+## Setup the sample project
+
+* [Signup or login to Parse](https://parse.com/#signup)
+* [Create a new app](https://parse.com/apps/new)
+* Install the Cloud Code Command Line Tool (See [Cloud Code Guide](https://parse.com/docs/cloud_code_guide#started) for more info)
+* Create a new project with `parse new`
+* Copy the files in this package to the new project folder
+* Create cloudinary configuration file (`cloudinary_config.js`)
+* Deploy your code `parse deploy`
+
+You're now ready to go
+
+## Configuration
+Supplying cloudinary configuration can be specified either by providing `cloudinary_config.js` in the `cloud` directory, or by directly calling `cloudinary.config` with a configuration object (See comment in `main.js` for sample usage).
+
+# Sample usage with cURL
+## Signup
+
+ curl -X POST \
+ -H "X-Parse-Application-Id: PARSE_APP_ID" \
+ -H "X-Parse-REST-API-Key: PARSE_REST_API_KEY" \
+ -H "Content-Type: application/json" \
+ -d '{"username":"MY_USER","password":"MY_PASS"}' \
+ https://api.parse.com/1/users
+
+## Login
+
+ curl -X GET \
+ -H "X-Parse-Application-Id: PARSE_APP_ID" \
+ -H "X-Parse-REST-API-Key: PARSE_REST_API_KEY" \
+ -G \
+ --data-urlencode 'username=MY_USER' \
+ --data-urlencode 'password=MY_PASS' \
+ https://api.parse.com/1/login
+
+Response:
+
+ {
+ "username":"MY_USER",
+ "createdAt":"2013-04-21T12:55:41.891Z",
+ "updatedAt":"2013-04-21T12:55:41.891Z",
+ "objectId":"JovCXZZxk7",
+ "sessionToken":"SESSION-TOKEN"
+ }
+
+
+## Get signature
+
+Use `sessionToken` from login response
+
+ curl -X POST \
+ -H "X-Parse-Application-Id: PARSE_APP_ID" \
+ -H "X-Parse-REST-API-Key: PARSE_REST_API_KEY" \
+ -H "X-Parse-Session-Token: SESSION-TOKEN" \
+ -H "Content-Type: application/json" \
+ -d '{}' \
+ https://api.parse.com/1/functions/sign_upload_request
+
+Resposne:
+
+ {
+ "result": {
+ "timestamp":1366555048,
+ "tags":"MY_USER",
+ "signature":"CLOUDINARY_SIGNATURE",
+ "api_key":"CLOUDINARY_API_KEY"
+ }
+ }
+
+## Upload image to Cloudinary using obtained signature
+
+Using the response from `sign_upload_request`:
+
+ curl -X POST \
+ -F timestamp=1366555048 \
+ -F tags=MY_USER \
+ -F signature=CLOUDINARY_SIGNATURE \
+ -F api_key="CLOUDINARY_API_KEY" \
+ -F file=@MY_IMAGE.jpg \
+ http://api.cloudinary.com/v1_1/MY_CLOUD_NAME/image/upload
+
+Response:
+
+ {
+ "public_id":"k3vmeifbepxddbzjuop9",
+ "version":1366555348,
+ "signature":"CLOUDINARY_RESULT_SIGNATURE",
+ "width":453,
+ "height":604,
+ "format":"jpg",
+ "resource_type":"image",
+ "created_at":"2013-04-21T15:31:06Z",
+ "tags":["MY_USER"],
+ "bytes":52534,
+ "type":"upload",
+ "url":"http://res.cloudinary.com/my_cloud_name/image/upload/v1366555348/k3vmeifbepxddbzjuop9.jpg",
+ "secure_url":"https://cloudinary-a.akamaihd.net/my_cloud_name/image/upload/v1366555348/k3vmeifbepxddbzjuop9.jpg"
+ }
+
+# Support
+
+You can [open an issue through GitHub](https://github.com/cloudinary/cloudinary_parse/issues).
+
+Contact us at [info@cloudinary.com](mailto:info@cloudinary.com)
+
+Or via Twitter: [@cloudinary](https://twitter.com/#!/cloudinary)
+
+# License
+Released under the MIT license.
+
+* [underscore.js](http://underscorejs.org/) is also released under the MIT license.
+* [crypto-js](https://code.google.com/p/crypto-js/) is released under the New BSD license.
+
@@ -0,0 +1,4 @@
+_ = require('cloud/cloudinary/lib/underscore.js')
+
+_.extend(exports, require('cloud/cloudinary/sign.js'))
+exports.config = require('cloud/cloudinary/config.js')
@@ -0,0 +1,17 @@
+_ = require("cloud/cloudinary/lib/underscore")
+cloudinary_config = undefined
+module.exports = (new_config, new_value) ->
+ if cloudinary_config == undefined || new_config == true
+ try
+ cloudinary_config = require('cloud/cloudinary_config').config
+ catch err
+ console.log("Couldn't find configuration file at 'cloud/cloudinary_config.js'")
+ cloudinary_config = {}
+ if not _.isUndefined(new_value)
+ cloudinary_config[new_config] = new_value
+ else if _.isString(new_config)
+ return cloudinary_config[new_config]
+ else if _.isObject(new_config)
+ cloudinary_config = new_config
+ cloudinary_config
+

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,5 @@
+
+0.0.1 / 2010-01-03
+==================
+
+ * Initial release
@@ -0,0 +1,8 @@
+# crypto #
+
+JavaScript implementations of standard and secure cryptographic algorithms.
+
+## Install ##
+
+ npm install crypto
+
Oops, something went wrong.

0 comments on commit ad26e97

Please sign in to comment.