Module: Parse::API::Aggregate

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

Overview

REST API methods for fetching CRUD operations on Parse objects.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#aggregate_objects(className, query = {}, headers: {}, **opts) ⇒ Parse::Response

Aggregate a set of matching objects for a query.

Parameters:

  • className (String)

    the name of the Parse collection.

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

    The set of query constraints.

  • opts (Hash)

    additional options to pass to the Client request.

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

    additional HTTP headers to send with the request.

Returns:

See Also:



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

def aggregate_objects(className, query = {}, headers: {}, **opts)
  response = request :get, aggregate_uri_path(className), query: query, headers: headers, opts: opts
  response.parse_class = className if response.present?
  response
end

#aggregate_pipeline(className, pipeline = [], headers: {}, raw_values: false, raw_field_names: false, **opts) ⇒ Parse::Response

Execute a MongoDB-style aggregation pipeline on a Parse collection.

Parameters:

  • className (String)

    the name of the Parse collection.

  • pipeline (Array) (defaults to: [])

    the MongoDB aggregation pipeline stages.

  • opts (Hash)

    additional options to pass to the Client request.

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

    additional HTTP headers to send with the request.

  • raw_values (Boolean) (defaults to: false)

    when true, adds +rawValues: true+ to the request so Parse Server returns un-decoded field values (PS 9.9.0+, #10438).

  • raw_field_names (Boolean) (defaults to: false)

    when true, adds +rawFieldNames: true+ to the request so Parse Server returns original (un-decoded) field names (PS 9.9.0+).

Returns:

See Also:



75
76
77
78
79
80
81
82
# File 'lib/parse/api/aggregate.rb', line 75

def aggregate_pipeline(className, pipeline = [], headers: {}, raw_values: false, raw_field_names: false, **opts)
  query = { pipeline: pipeline.to_json }
  query[:rawValues] = true if raw_values
  query[:rawFieldNames] = true if raw_field_names
  response = request :get, aggregate_uri_path(className), query: query, headers: headers, opts: opts
  response.parse_class = className if response.present?
  response
end

#aggregate_uri_path(className) ⇒ String

Get the API path for this class.

Parameters:

  • className (String)

    the name of the Parse collection.

Returns:

  • (String)

    the API uri path



47
48
49
# File 'lib/parse/api/aggregate.rb', line 47

def aggregate_uri_path(className)
  self.class.aggregate_uri_path(className)
end