Class: MailchimpAPI::BatchRequest Private

Inherits:
Object
  • Object
show all
Defined in:
lib/mailchimp-api/batch_request.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Internal class for constructing batch operation requests

Constant Summary collapse

API_VERSION_PREFIX =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

API version prefix to be removed from paths

"/#{MailchimpAPI::API_VERSION}"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request, operation_id: nil) ⇒ BatchRequest

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates a new batch request

Parameters:

  • request (MailchimpAPI::Request)

    The original request to be batched

  • operation_id (String, nil) (defaults to: nil)

    Optional operation ID for tracking



19
20
21
22
# File 'lib/mailchimp-api/batch_request.rb', line 19

def initialize(request, operation_id: nil)
  @request = request
  @operation_id = operation_id
end

Instance Attribute Details

#operation_idString? (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns Optional operation ID for tracking batch operations.

Returns:

  • (String, nil)

    Optional operation ID for tracking batch operations



14
15
16
# File 'lib/mailchimp-api/batch_request.rb', line 14

def operation_id
  @operation_id
end

#requestMailchimpAPI::Request (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns The original request object.

Returns:



11
12
13
# File 'lib/mailchimp-api/batch_request.rb', line 11

def request
  @request
end

Instance Method Details

#operationHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts the request into a batch operation format

Examples:

{
  method: "GET",
  path: "/lists",
  params: { count: 10 },
  operation_id: "get_lists"
}

Returns:

  • (Hash)

    The operation in format suitable for ‘/batch` request



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/mailchimp-api/batch_request.rb', line 33

def operation
  operation = {
    method: request.method, # "GET", "POST", "PUT", "PATCH", "DELETE"
    path: request.path.delete_prefix(API_VERSION_PREFIX) # Path relative to version prefix
  }

  body = request.body
  operation[:body] = body if body

  params = request.query
  operation[:params] = params unless params.empty?

  operation[:operation_id] = operation_id if operation_id
  operation
end