Module: Parse::API::Hooks

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

Overview

Defines the Parse webhooks interface for the Parse REST API

Constant Summary collapse

TRIGGER_NAMES =

The allowed set of Parse triggers.

[:afterCreate, :afterDelete, :afterFind, :afterSave, :beforeDelete, :beforeFind, :beforeSave].freeze

Instance Method Summary collapse

Instance Method Details

#create_function(functionName, url) ⇒ Parse::Response

Register a cloud code webhook function pointing to a endpoint url.

Parameters:

  • functionName (String)

    the name of the cloud code function.

  • url (String)

    the url endpoint for this cloud code function.

Returns:



40
41
42
# File 'lib/parse/api/hooks.rb', line 40

def create_function(functionName, url)
  request :post, "#{HOOKS_PREFIX}functions", body: { functionName: functionName, url: url }
end

#create_trigger(triggerName, className, url) ⇒ Parse::Response

Register a new cloud code webhook trigger with an endpoint url.

Parameters:

  • triggerName (String)

    the name of the trigger. (ex. beforeSave, afterSave)

  • className (String)

    the name of the Parse collection for the trigger.

  • url (String)

    the url endpoint for this webhook trigger.

Returns:

See Also:



87
88
89
90
91
# File 'lib/parse/api/hooks.rb', line 87

def create_trigger(triggerName, className, url)
  triggerName = _verify_trigger(triggerName)
  body = { className: className, triggerName: triggerName, url: url }
  request :post, "#{HOOKS_PREFIX}triggers", body: body
end

#delete_function(functionName) ⇒ Parse::Response

Remove a registered cloud code webhook function.

Parameters:

  • functionName (String)

    the name of the cloud code function.

Returns:



58
59
60
61
# File 'lib/parse/api/hooks.rb', line 58

def delete_function(functionName)
  safe = Parse::API::PathSegment.identifier!(functionName, kind: "function name")
  request :put, "#{HOOKS_PREFIX}functions/#{safe}", body: { __op: "Delete" }
end

#delete_trigger(triggerName, className) ⇒ Parse::Response

Remove a registered cloud code webhook trigger.

Parameters:

  • triggerName (String)

    the name of the trigger. (ex. beforeSave, afterSave)

  • className (String)

    the name of the Parse collection for the trigger.

Returns:

See Also:



110
111
112
113
114
# File 'lib/parse/api/hooks.rb', line 110

def delete_trigger(triggerName, className)
  triggerName = _verify_trigger(triggerName)
  safe_class = Parse::API::PathSegment.identifier!(className, kind: "class name")
  request :put, "#{HOOKS_PREFIX}triggers/#{safe_class}/#{triggerName}", body: { __op: "Delete" }
end

#fetch_function(functionName) ⇒ Parse::Response

Fetch information about a specific registered cloud function.

Parameters:

  • functionName (String)

    the name of the cloud code function.

Returns:



31
32
33
34
# File 'lib/parse/api/hooks.rb', line 31

def fetch_function(functionName)
  safe = Parse::API::PathSegment.identifier!(functionName, kind: "function name")
  request :get, "#{HOOKS_PREFIX}functions/#{safe}"
end

#fetch_trigger(triggerName, className) ⇒ Parse::Response

Fetch information about a registered webhook trigger.

Parameters:

  • triggerName (String)

    the name of the trigger. (ex. beforeSave, afterSave)

  • className (String)

    the name of the Parse collection for the trigger.

Returns:

See Also:



75
76
77
78
79
# File 'lib/parse/api/hooks.rb', line 75

def fetch_trigger(triggerName, className)
  triggerName = _verify_trigger(triggerName)
  safe_class = Parse::API::PathSegment.identifier!(className, kind: "class name")
  request :get, "#{HOOKS_PREFIX}triggers/#{safe_class}/#{triggerName}"
end

#functionsParse::Response

Fetch all defined cloud code functions.

Returns:



23
24
25
26
# File 'lib/parse/api/hooks.rb', line 23

def functions
  opts = { cache: false }
  request :get, "#{HOOKS_PREFIX}functions", opts: opts
end

#triggersParse::Response

Get the set of registered triggers.

Returns:



65
66
67
68
# File 'lib/parse/api/hooks.rb', line 65

def triggers
  opts = { cache: false }
  request :get, "#{HOOKS_PREFIX}triggers", opts: opts
end

#update_function(functionName, url) ⇒ Parse::Response

Updated the endpoint url for a registered cloud code webhook function.

Parameters:

  • functionName (String)

    the name of the cloud code function.

  • url (String)

    the new url endpoint for this cloud code function.

Returns:



48
49
50
51
52
53
# File 'lib/parse/api/hooks.rb', line 48

def update_function(functionName, url)
  # If you add _method => "PUT" to the JSON body,
  # and send it as a POST request and parse will accept it as a PUT.
  safe = Parse::API::PathSegment.identifier!(functionName, kind: "function name")
  request :put, "#{HOOKS_PREFIX}functions/#{safe}", body: { url: url }
end

#update_trigger(triggerName, className, url) ⇒ Parse::Response

Updated the registered endpoint for this cloud code webhook trigger.

Parameters:

  • triggerName (String)

    the name of the trigger. (ex. beforeSave, afterSave)

  • className (String)

    the name of the Parse collection for the trigger.

  • url (String)

    the new url endpoint for this webhook trigger.

Returns:

See Also:



99
100
101
102
103
# File 'lib/parse/api/hooks.rb', line 99

def update_trigger(triggerName, className, url)
  triggerName = _verify_trigger(triggerName)
  safe_class = Parse::API::PathSegment.identifier!(className, kind: "class name")
  request :put, "#{HOOKS_PREFIX}triggers/#{safe_class}/#{triggerName}", body: { url: url }
end