This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Reorganize the Cloudinary Parse Module

  • Loading branch information...
TalLevAmi committed Mar 3, 2014
1 parent 8045d5c commit 08015ed5202a8974fd8157cef4ab5b6c1f1b7a61
View
@@ -1 +1,4 @@
-cloud/cloudinary_config.js
+sample/cloud/cloudinary_config.js
+sample/config
+sample/public
+.project
View
134 README.md
@@ -1,125 +1,61 @@
# Cloudinary Parse Module
-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.
+This package contains Cloudinary's Parse Cloud Module.
+The cloudinary library provides a mechanism for storing cloudinary credentials, signing upload requests and generating Cloudinary URLs.
-## Files
+## What is Cloudinary?
-* `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 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.
- * A sample beforeSave factory (`beforeSaveFactory`). When given an `object_name` and a `field_name`, creates a beforeSave function that verifies updates to `field_name` are only done with a signed cloudinary identifier.
- The beforeSave function also removes the signatures when saving to the database.
-* `cloud/cloudinary.js` - The cloudinary library entrypoint. In order to load cloudinary library you must `require('cloud/cloudinary')` 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`
+Cloudinary is a cloud-based service that provides an end-to-end image management solution including uploads, storage, manipulations,
+optimizations and delivery.
-## Setup the sample project
+With Cloudinary you can easily upload images to the cloud, automatically perform smart image manipulations without installing any complex software.
+All your images are then seamlessly delivered through a fast CDN, optimized and using industry best practices.
+Cloudinary offers comprehensive APIs and administration capabilities and is easy to integrate with new and existing web and mobile applications.
-* [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`
+## Files
-You're now ready to go
+* `cloud/cloudinary.js` - The cloudinary library entrypoint. In order to load cloudinary library you must `require('cloud/cloudinary')` the result of this expression is the cloudinary namespace. See `cloud/main.js` for sample usage.
## 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"
- }
+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).
+## Functions
-## Get signature
+ * beforeSaveFactory - When given an `object_name` and a `field_name`, creates a beforeSave function that verifies updates to `field_name` are only done with a signed cloudinary identifier.
+ The beforeSave function also removes the signatures when saving to the database.
+ * url - builds a cloudinary URL given the image identifier and transformation parameters. As a reference you can check the [nodejs documentation](http://cloudinary.com/documentation/node_image_manipulation)
+ * sign_upload_request - created a signed request that can be used to construct an HTML form or passed to Cloudinary front-end libraries to initiate an image upload.
-Use `sessionToken` from login response
+## Usage Example
- 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
+````
+cloudinary = require("cloud/cloudinary");
-Resposne:
+cloudinary.beforeSaveFactory("Photo", "cloudinaryIdentifier");
- {
- "result": {
- "timestamp":1366555048,
- "tags":"MY_USER",
- "signature":"CLOUDINARY_SIGNATURE",
- "api_key":"CLOUDINARY_API_KEY"
- }
+Parse.Cloud.define("sign_cloudinary_upload_request", function(request, response) {
+ if (!request.user || !request.user.authenticated()) {
+ response.error("Needs an authenticated user");
+ return;
}
+ response.success(
+ cloudinary.sign_upload_request({tags: request.user.getUsername(), eager: {crop: "fill", width: 150, height: 100, gravity: "face"}})
+ );
+});
-## 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"
- }
+````
+
+## Sample project
+
+See the [Cloudinary Parse sample project](https://github.com/cloudinary/cloudinary_parse/edit/master/sample)
# 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)
+Contact us [http://cloudinary.com/contact](http://cloudinary.com/contact)
-Or via Twitter: [@cloudinary](https://twitter.com/#!/cloudinary)
+Stay tuned for updates, tips and tutorials: [Blog](http://cloudinary.com/blog), [Twitter](https://twitter.com/cloudinary), [Facebook](http://www.facebook.com/Cloudinary).
# License
Released under the MIT license.
View
@@ -1,15 +1,14 @@
GLOBAL = Parse.Cloudinary ?= {}
GLOBAL.get_cloudinary_path = ->
return GLOBAL.PREFIX if GLOBAL.PREFIX?
- prefices = ['cloud', '']
+ prefixes = ['cloud', '']
cloudinary_path = "cloudinary"
require_test_file = "version"
- for prefix in prefices
+ for prefix in prefixes
try
require [prefix, cloudinary_path, require_test_file].join("/")
GLOBAL.PREFIX = [prefix, cloudinary_path, ""].join("/")
- console.log "Cloudinary prefix: " + GLOBAL.PREFIX
return GLOBAL.PREFIX
catch e
throw e unless e.message.match(/Module \S+ not found/)
@@ -21,15 +20,15 @@ GLOBAL.require = (file) ->
_ = GLOBAL.require 'lib/underscore.js'
-_.extend exports, GLOBAL.require('sign.js')
+_.extend exports, GLOBAL.require('core.js')
exports.config = GLOBAL.require('config.js')
exports.initialize = (cloud_name, api_key, api_secret) ->
exports.config(cloud_name: cloud_name, api_key: api_key, api_secret: api_secret)
exports.version = Parse.Cloudinary.VERSION
###
This factory creates a beforeSave filter that verifies that a given
- cloudinary-identifier field in your object is a valid (has correct signature)
+ cloudinaryIdentifier field in your object is a valid (has correct signature)
@note This function allows changing of other fields without validation
###
View

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

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 08015ed

Please sign in to comment.