Module: Parse::API::Objects

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

Overview

REST API methods for fetching CRUD operations on Parse objects.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#create_object(className, body = {}, headers: {}, context: nil, **opts) ⇒ Parse::Response

Create an object in a collection.

Parameters:

  • className (String)

    the name of the Parse collection.

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

    the body of the request.

  • opts (Hash)

    additional options to pass to the Client request.

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

    additional HTTP headers to send with the request.

  • context (Hash, nil) (defaults to: nil)

    an optional caller context forwarded as the +X-Parse-Cloud-Context+ header. Parse Server maps it to +req.info.context+ inside beforeSave/afterSave cloud triggers. Omit or pass +nil+ to leave behavior unchanged.

Returns:



92
93
94
95
96
97
98
99
# File 'lib/parse/api/objects.rb', line 92

def create_object(className, body = {}, headers: {}, context: nil, **opts)
  unless context.nil?
    headers = headers.merge(Parse::Protocol::CLOUD_CONTEXT => context.to_json)
  end
  response = request :post, uri_path(className), body: body, headers: headers, opts: opts
  response.parse_class = className if response.present?
  response
end

#delete_object(className, id, headers: {}, **opts) ⇒ Parse::Response

Delete an object in a collection.

Parameters:

  • className (String)

    the name of the Parse collection.

  • id (String)

    The objectId of the record in the collection.

  • opts (Hash)

    additional options to pass to the Client request.

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

    additional HTTP headers to send with the request.

Returns:



107
108
109
110
111
# File 'lib/parse/api/objects.rb', line 107

def delete_object(className, id, headers: {}, **opts)
  response = request :delete, uri_path(className, id), headers: headers, opts: opts
  response.parse_class = className if response.present?
  response
end

#fetch_object(className, id, query: nil, headers: {}, **opts) ⇒ Parse::Response

Fetch a specific object from a collection.

Parameters:

  • className (String)

    the name of the Parse collection.

  • id (String)

    The objectId of the record in the collection.

  • query (Hash) (defaults to: nil)

    optional query parameters like keys and include.

  • opts (Hash)

    additional options to pass to the Client request.

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

    additional HTTP headers to send with the request.

Returns:



120
121
122
123
124
# File 'lib/parse/api/objects.rb', line 120

def fetch_object(className, id, query: nil, headers: {}, **opts)
  response = request :get, uri_path(className, id), query: query, headers: headers, opts: opts
  response.parse_class = className if response.present?
  response
end

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

Fetch 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:



133
134
135
136
137
# File 'lib/parse/api/objects.rb', line 133

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

#update_object(className, id, body = {}, headers: {}, context: nil, **opts) ⇒ Parse::Response

Update an object in a collection.

Parameters:

  • className (String)

    the name of the Parse collection.

  • id (String)

    The objectId of the record in the collection.

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

    The key value pairs to update.

  • opts (Hash)

    additional options to pass to the Client request.

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

    additional HTTP headers to send with the request.

  • context (Hash, nil) (defaults to: nil)

    an optional caller context forwarded as the +X-Parse-Cloud-Context+ header. Parse Server maps it to +req.info.context+ inside beforeSave/afterSave cloud triggers. Omit or pass +nil+ to leave behavior unchanged.

Returns:



150
151
152
153
154
155
156
157
# File 'lib/parse/api/objects.rb', line 150

def update_object(className, id, body = {}, headers: {}, context: nil, **opts)
  unless context.nil?
    headers = headers.merge(Parse::Protocol::CLOUD_CONTEXT => context.to_json)
  end
  response = request :put, uri_path(className, id), body: body, headers: headers, opts: opts
  response.parse_class = className if response.present?
  response
end

#uri_path(className, id = nil) ⇒ String

Get the API path for this class.

Parameters:

  • className (String)

    the name of the Parse collection.

  • id (String) (defaults to: nil)

    optional objectId to add at the end of the path.

Returns:

  • (String)

    the API uri path



78
79
80
# File 'lib/parse/api/objects.rb', line 78

def uri_path(className, id = nil)
  self.class.uri_path(className, id)
end