Permalink
Browse files

support Cloud Functions

  • Loading branch information...
1 parent bb836f2 commit 7358aa6851f895b79140bad3cc1aab9e3b35e3bf @adelevie committed Oct 9, 2012
Showing with 66 additions and 3 deletions.
  1. +3 −1 .gitignore
  2. +2 −1 lib/parse-ruby-client.rb
  3. +23 −0 lib/parse/cloud.rb
  4. +7 −1 lib/parse/protocol.rb
  5. +4 −0 test/cloud_functions/MyCloudCode/cloud/main.js
  6. +27 −0 test/test_cloud.rb
View
@@ -2,4 +2,6 @@
/pkg
lib/.DS_Store
-lib/parse/.DS_Store
+lib/parse/.DS_Store
+
+test/cloud_functions/MyCloudCode/config/global.json
View
@@ -22,4 +22,5 @@
require 'parse/util'
require 'parse/protocol'
require 'parse/user'
-require 'parse/push'
+require 'parse/push'
+require 'parse/cloud'
View
@@ -0,0 +1,23 @@
+module Parse
+ module Cloud
+
+ class Function
+ attr_accessor :function_name
+
+ def initialize(function_name)
+ @function_name = function_name
+ end
+
+ def uri
+ Protocol.cloud_function_uri(@function_name)
+ end
+
+ def call(params={})
+ response = Parse.client.post(self.uri, params.to_json)
+ result = response["result"]
+ result
+ end
+ end
+
+ end
+end
View
@@ -69,7 +69,7 @@ module Protocol
# increment/decrement API call.
KEY_AMOUNT = "amount"
- RESERVED_KEYS = [ KEY_CLASS_NAME, KEY_CREATED_AT, KEY_OBJECT_ID, KEY_UPDATED_AT]
+ RESERVED_KEYS = [ KEY_CLASS_NAME, KEY_CREATED_AT, KEY_OBJECT_ID, KEY_UPDATED_AT]
# Other Constants
# ----------------------------------------
@@ -114,6 +114,8 @@ module Protocol
KEY_USER_SESSION_TOKEN = "sessionToken"
+ CLOUD_FUNCTIONS_PATH = "functions"
+
# URI Helpers
# ----------------------------------------
@@ -147,5 +149,9 @@ def Protocol.file_uri(file_name)
def Protocol.push_uri
"/#{VERSION}/push"
end
+
+ def Protocol.cloud_function_uri(function_name)
+ "/#{VERSION}/#{CLOUD_FUNCTIONS_PATH}/#{function_name}"
+ end
end
end
@@ -0,0 +1,4 @@
+Parse.Cloud.define('trivial', function(request, response) {
+ console.log(request);
+ response.success(request.params);
+});
View
@@ -0,0 +1,27 @@
+require 'helper'
+
+Parse.init
+
+class TestCloud < Test::Unit::TestCase
+ # functions stored in test/cloud_functions/MyCloudCode
+ # see https://parse.com/docs/cloud_code_guide to learn how to use Parse Cloud Code
+ #
+ # Parse.Cloud.define('trivial', function(request, response) {
+ # response.success(request.params);
+ # });
+
+ def setup
+ Parse.init
+ end
+
+ def test_cloud_function_initialize
+ assert_not_equal nil, Parse::Cloud::Function.new("trivial")
+ end
+
+ def test_cloud_function
+ function = Parse::Cloud::Function.new("trivial")
+ params = {}
+ resp = function.call(params)
+ assert_equal resp, params
+ end
+end

0 comments on commit 7358aa6

Please sign in to comment.