Module: Parse::API::Batch
- Included in:
- Client
- Defined in:
- lib/parse/api/batch.rb
Overview
Defines the Batch interface for the Parse REST API
Instance Method Summary collapse
Instance Method Details
#batch_request(requests) ⇒ Array<Parse::Response>, Parse::Response #batch_request(operation) ⇒ Array<Parse::Response>, Parse::Response
You cannot use batch_requests with User instances that need to be created.
Every request is sent through this client, as Client#request sends a single request through the client it is called on, even when the request was built for another object's class client.
Each Request's own credentials (its session_token: /
use_master_key: options and its session-token or master-key
suppression headers) are honored.
When every request resolves to this client and one set of
credentials, the batch is one call. A transaction that would mix
credentials raises BatchOperation::MixedAuthorityError
before anything is sent. A non-transactional batch with mixed
credentials is sent as one call per set of credentials, through
BatchOperation#submit, with responses in request order.
Elements that are not Request instances are ignored, as
BatchOperation#add ignores them.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/parse/api/batch.rb', line 49 def batch_request(batch_operations, **opts) unless batch_operations.is_a?(Parse::BatchOperation) batch_operations = Parse::BatchOperation.new batch_operations end call_auth = opts.slice(:session_token, :use_master_key, :suppress_master_key) groups = batch_operations.send(:authority_groups, self, call_auth, force_client: true) if groups.empty? return post_batch_operation(batch_operations, opts.except(:suppress_master_key)) end if groups.size == 1 && Parse::BatchOperation.credential_fingerprint(groups.first[:client]) == Parse::BatchOperation.credential_fingerprint(self) send_opts = opts.except(:session_token, :use_master_key, :suppress_master_key) .merge(groups.first[:opts]) return post_batch_operation(batch_operations, send_opts) end if batch_operations.transaction raise Parse::BatchOperation::MixedAuthorityError, "A transaction cannot mix requests built for different credentials or " \ "another client. Parse Server runs a batch under one credential, so it " \ "cannot honor each request's own. Save these objects in separate transactions." end # Mixed credentials, not a transaction: send one call per set of # credentials, keeping responses in request order. # Assigned, not re-added: `add` would drop tagged duplicates and leave # fewer responses than requests. routed = Parse::BatchOperation.new routed.requests = batch_operations.requests.dup routed.client = self routed.batch_defaults = call_auth routed.submit end |