public function post(array $recipients, $publisherId, $listExternalId)
    {
        $recipientsCount = count($recipients);
        if ($recipientsCount == 0) {
            throw new \Exception('No recipient found!');
        }

        // Recipient sanity check
        foreach ($recipients as $recipient) {
            try {
                $recipient->hasValidData();
            } catch (\Exception $recipientException) {
                throw new \Exception(sprintf(
                    'The recipient email/hash "%s", has invalid data: %s',
                    $recipient->getEmailAddress() ?: $recipient->getHash(),
                    $recipientException->getMessage()
                ));
            }
        }

        $offset = 0;
        while (true) {
            $subscribe = new Subscribe();
            $subscribe->setRecipients(array_slice($recipients, $offset, self::DEFAULT_MAX_RECIPIENTS_PER_REQUEST));

            $requestContent = [
                'headers' => ['Content-Type' => 'application/json'],
                'body'    => json_encode(array('subscribe' => $subscribe)),
                'timeout' => self::DEFAULT_REQUEST_TIMEOUT
            ];

            $response = null;
            try {
                $response = $this->guzzleClient->post(
                    $this->getApiEndpoint($publisherId, $listExternalId),
                    $requestContent
                );
            } catch (ClientException $guzzleException) {
                if ($guzzleException->getCode() == 400) {
                    throw new \Exception('Some errors found on this recipient submission: ' . $this->processErrors(
                        $guzzleException->getResponse()->getBody()->getContents()
                    ));
                }
                throw new \Exception('An expected error occurred: ' . $guzzleException->getMessage());
            }

            // If we do not have a success response, let us process the error a message and throw it as an error
            if ($response->getStatusCode() != self::SUCCESS_HTTP_CODE) {
                throw new \Exception(
                    'Some errors found on this recipient submission: ' . $this->processErrors($response->getBody())
                );
            }

            // If we already send more all the contacts, we can break the loop
            if ($offset + self::DEFAULT_MAX_RECIPIENTS_PER_REQUEST >= $recipientsCount) {
                break;
            }

            // Increment the offset
            $offset += self::DEFAULT_MAX_RECIPIENTS_PER_REQUEST;
        }

        return true;
    }
public function post(array $recipients, $publisherId, $listExternalId)
    {
        $recipientsCount = count($recipients);
        if ($recipientsCount == 0) {
            throw new \Exception('No recipient found!');
        }

        // Recipient sanity check
        foreach ($recipients as $recipient) {
            try {
                $recipient->hasValidData();
            } catch (\Exception $recipientException) {
                throw new \Exception(sprintf(
                    'The recipient email/hash "%s", has invalid data: %s',
                    $recipient->getEmailAddress() ?: $recipient->getHash(),
                    $recipientException->getMessage()
                ));
            }
        }

        $offset = 0;
        while (true) {
            $subscribe = new Subscribe();
            $subscribe->setRecipients(array_slice($recipients, $offset, self::DEFAULT_MAX_RECIPIENTS_PER_REQUEST));

            $requestContent = [
                'headers' => ['Content-Type' => 'application/json'],
                'body'    => json_encode(array('subscribe' => $subscribe)),
                'timeout' => self::DEFAULT_REQUEST_TIMEOUT
            ];

            $response = null;
            try {
                $response = $this->guzzleClient->post(
                    $this->getApiEndpoint($publisherId, $listExternalId),
                    $requestContent
                );
            } catch (ClientException $guzzleException) {
                if ($guzzleException->getCode() == 400) {
                    throw new \Exception('Some errors found on this recipient submission: ' . $this->processErrors(
                        $guzzleException->getResponse()->getBody()->getContents()
                    ));
                }
                throw new \Exception('An expected error occurred: ' . $guzzleException->getMessage());
            }

            // If we do not have a success response, let us process the error a message and throw it as an error
            if ($response->getStatusCode() != self::SUCCESS_HTTP_CODE) {
                throw new \Exception(
                    'Some errors found on this recipient submission: ' . $this->processErrors($response->getBody())
                );
            }

            // If we already send more all the contacts, we can break the loop
            if ($offset + self::DEFAULT_MAX_RECIPIENTS_PER_REQUEST >= $recipientsCount) {
                break;
            }

            // Increment the offset
            $offset += self::DEFAULT_MAX_RECIPIENTS_PER_REQUEST;
        }

        return true;
    }
@param Recipient [] $recipients
@param string       $listExternalId
@param string       $publisherId

@returns bool
@throws \Exception