Module: Parse::API::CloudFunctions

Included in:
Client
Defined in:
lib/parse/api/cloud_functions.rb

Overview

Defines the CloudCode interface for the Parse REST API

Instance Method Summary collapse

Instance Method Details

#call_function(name, body = {}, opts: {}) ⇒ Parse::Response

Call a cloud function.

Parameters:

  • name (String)

    the name of the cloud function.

  • body (Hash) (defaults to: {})

    the parameters to forward to the function.

  • opts (Hash) (defaults to: {})

    additional options for the request.

Options Hash (opts:):

  • :session_token (String)

    The session token for authenticated requests.

  • :master_key (String)

    Whether to use the master key for this request.

Returns:



16
17
18
19
# File 'lib/parse/api/cloud_functions.rb', line 16

def call_function(name, body = {}, opts: {})
  safe = Parse::API::PathSegment.identifier!(name, kind: "function name")
  request :post, "functions/#{safe}", body: body, opts: opts
end

#call_function_with_session(name, body = {}, session_token) ⇒ Parse::Response

Call a cloud function with a specific session token. This is a convenience method that ensures the session token is properly passed.

Parameters:

  • name (String)

    the name of the cloud function.

  • body (Hash) (defaults to: {})

    the parameters to forward to the function.

  • session_token (String)

    the session token for authenticated requests.

Returns:



39
40
41
42
43
# File 'lib/parse/api/cloud_functions.rb', line 39

def call_function_with_session(name, body = {}, session_token)
  opts = {}
  opts[:session_token] = session_token if session_token.present?
  call_function(name, body, opts: opts)
end

#trigger_job(name, body = {}, opts: {}) ⇒ Parse::Response

Trigger a job.

Parameters:

  • name (String)

    the name of the job to trigger.

  • body (Hash) (defaults to: {})

    the parameters to forward to the job.

  • opts (Hash) (defaults to: {})

    additional options for the request.

Options Hash (opts:):

  • :session_token (String)

    The session token for authenticated requests.

  • :master_key (String)

    Whether to use the master key for this request.

Returns:



28
29
30
31
# File 'lib/parse/api/cloud_functions.rb', line 28

def trigger_job(name, body = {}, opts: {})
  safe = Parse::API::PathSegment.identifier!(name, kind: "job name")
  request :post, "jobs/#{safe}", body: body, opts: opts
end

#trigger_job_with_session(name, body = {}, session_token) ⇒ Parse::Response

Trigger a job with a specific session token. This is a convenience method that ensures the session token is properly passed.

Parameters:

  • name (String)

    the name of the job to trigger.

  • body (Hash) (defaults to: {})

    the parameters to forward to the job.

  • session_token (String)

    the session token for authenticated requests.

Returns:



51
52
53
54
55
# File 'lib/parse/api/cloud_functions.rb', line 51

def trigger_job_with_session(name, body = {}, session_token)
  opts = {}
  opts[:session_token] = session_token if session_token.present?
  trigger_job(name, body, opts: opts)
end