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: {}, **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.

Returns:


60
61
62
63
64
# File 'lib/parse/api/objects.rb', line 60

def create_object(className, body = {}, headers: {}, **opts)
  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:


72
73
74
75
76
# File 'lib/parse/api/objects.rb', line 72

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, 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.

  • opts (Hash)

    additional options to pass to the Client request.

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

    additional HTTP headers to send with the request.

Returns:


84
85
86
87
88
# File 'lib/parse/api/objects.rb', line 84

def fetch_object(className, id, headers: {}, **opts)
  response = request :get, uri_path(className, id), 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:


97
98
99
100
101
# File 'lib/parse/api/objects.rb', line 97

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: {}, **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.

Returns:


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

def update_object(className, id, body = {}, headers: {}, **opts)
  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


50
51
52
# File 'lib/parse/api/objects.rb', line 50

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