Provide the unregistered tokens of the sent notification.

@param array $devices_token
@return array $tokenUnRegistered
15624
public function getUnregisteredDeviceTokens(array $devices_token)
    {
        /**
         * If there is any failure sending the notification
         */
        if ($this->feedback && isset($this->feedback->failure)) {
            $unRegisteredTokens = $devices_token;

            /**
             * Walk the array looking for any error.
             * If no error, unset it from all token list which will become the unregistered tokens array.
             */
            foreach ($this->feedback->results as $key => $message) {
                if (!isset($message->error)) {
                    unset($unRegisteredTokens[$key]);
                }
            }

            return $unRegisteredTokens;
        }

        return [];
    }
129487
def hosting_devices_unassigned_from_cfg_agent(self, context, payload):
        """"""
        try:
            if payload['hosting_device_ids']:
                #TODO(hareeshp): implement unassignment of hosting devices
                pass
        except KeyError as e:
            LOG.error("Invalid payload format for received RPC message "
                      "`hosting_devices_unassigned_from_cfg_agent`. Error "
                      "is %(error)s. Payload is %(payload)s",
                      {'error': e, 'payload': payload})
548112
public function subscribeDevicesToTopic($topicId = null, $deviceTokens = array())
    {
        if(!$topicId || empty($deviceTokens)){
            throw new \InvalidArgumentException("Please check arguments!");
        }

        return $this->client->addTopicSubscription($topicId, $deviceTokens);
    }
750787
public function getCompletedTokens($tokenIds, $sourceSurveyId)
    {
        $lsDb       = $this->getSourceDatabase();
        $lsToken   = $this->_getTokenTableName($sourceSurveyId);

        // Make sure we use tokens in the format LimeSurvey likes
        $tokens = array_map(array($this, '_getToken'), $tokenIds);

        $sql = $lsDb->select()
                ->from($lsToken, array('token'))
                ->where('token IN (?)', $tokens)
                ->where('completed != ?', 'N');

        $completedTokens = $lsDb->fetchCol($sql);

        // Now make sure we return tokens GemsTracker likes
        if ($completedTokens) {
            $translatedTokens = array();

            // Can not use the map function here since we need a second parameter
            foreach($completedTokens as $token) {
                $translatedTokens[] = $this->_getToken($token, true);
            }

            return $translatedTokens;
        }

        return $completedTokens;
    }
812554
public function getTokenGuard(Token $token, $guards)
    {
        $providers = GuardChecker::getGuardsProviders($guards);

        // use only guard associated to access token provider
        return $providers->has($token->provider) ? [$providers->get($token->provider)] : [];
    }
1156537
def hosting_devices_unassigned_from_cfg_agent(self, context, ids, host):
        
        self._host_notification(context,
                                'hosting_devices_unassigned_from_cfg_agent',
                                {'hosting_device_ids': ids}, host)
708018
private function prepareRequest($method, $deviceToken, $endPoint)
    {
        $tokenId = md5($deviceToken);
        return $this->sendRequest(
            $method,
            str_replace(':token_id', $tokenId, $endPoint)
        );
    }
57378
public function getTokens(): array
    {
        $response = $this
            ->httpClient
            ->get(
                sprintf(
                    '/%s/tokens',
                    $this->getAppUUID()->getId()
                ),
                'get',
                [],
                [],
                Http::getApisearchHeaders($this)
            );

        self::throwTransportableExceptionIfNeeded($response);

        return array_map(function (array $token) {
            return Token::createFromArray($token);
        }, $response['body']);
    }
728176
protected function addRequestFields($deviceTokens, $message)
    {

        $params = $this->cleanConfigParams();

        $message = $this->buildMessage($message);

        return array_merge($params, $message, ['registration_ids'  => $deviceTokens]);
    }
1319491
private function setDeviceToken($deviceToken)
	{
		// Check if a devicetoken is given
		if (null == $deviceToken) {
			throw new \InvalidArgumentException('No device token given.');
		}

		// Check if the devicetoken is a valid hexadecimal string
		if (!ctype_xdigit($deviceToken)) {
			throw new \InvalidArgumentException('Invalid device token given, no hexadecimal: ' . $deviceToken);
		}

		// Check if the length of the devicetoken is correct
		if (64 != strlen($deviceToken)) {
			throw new \InvalidArgumentException('Invalid device token given, incorrect length: ' . $deviceToken . ' (' . strlen($deviceToken) . ')');
		}

		// Set the devicetoken
		$this->deviceToken = $deviceToken;
	}
846395
protected function processTopicSubscription($topic_id, $recipients_tokens, $url)
    {
        if (!is_array($recipients_tokens))
            $recipients_tokens = [$recipients_tokens];

        return $this->guzzleClient->post(
            $url,
            [
                'headers' => [
                    'Authorization' => sprintf('key=%s', $this->apiKey),
                    'Content-Type' => 'application/json'
                ],
                'body' => json_encode([
                    'to' => '/topics/' . $topic_id,
                    'registration_tokens' => $recipients_tokens,
                ])
            ]
        );
    }
1205663
public function hasRequiredTokens(array $tokens, array $tokenIds) {
		foreach ($tokenIds as $id) {
			if (in_array($tokens[$id]['id'], $this->requiredTokens)) {
				return true;
			}
		}
		return false;
	}
1025
protected function getTokenStrings(int $row, array $tokens): array
    {
        $pieces = [];
        foreach ($tokens as $key => $token) {
            if ($token['line'] > $row) {
                break;
            }
            if ($token['line'] < $row) {
                continue;
            }
            if ($this->verbose) {
                $type = $token['type'];
                $content = $token['content'];
                $content = '`' . str_replace(["\r\n", "\n", "\r", "\t"], ['\r\n', '\n', '\r', '\t'], $content) . '`';

                unset($token['type']);
                unset($token['content']);
                $token['content'] = $content;

                $tokenList = [];
                foreach ($token as $k => $v) {
                    if (is_array($v)) {
                        if (empty($v)) {
                            continue;
                        }
                        $v = json_encode($v);
                    }
                    $tokenList[] = $k . '=' . $v;
                }
                $pieces[] = $type . ' (' . $key . ') ' . implode(', ', $tokenList);
            } else {
                $pieces[] = $token['type'];
            }
        }
        if ($this->verbose) {
            return $pieces;
        }
        return [implode(' ', $pieces)];
    }
207877
public function getTokens()
    {
        $pool = null;
        $session = \PHPSession::singleton();
        if($session->hasAttribute(self::TOKEN_KEY)){
            $pool = $session->getAttribute(self::TOKEN_KEY);
        }
        if(is_null($pool)){
            $pool = [];
        }

        return $pool;
    }
312587
public function Send($deviceToken, $message, $method = "HTTP")
	{
		$output = new stdClass();
		$output->date = date('Y-m-d H:i:s');

		// TODO: add in CCS with XMPP services alongside of the vanilla HTTP
		if ($method == "HTTP")
		{
			$fields = array(
				'registration_ids' => array($deviceToken),
				'data' => array("message" => $message)
			);

			$headers = array(
				'Authorization: key=' . $this->googlePushRegistrationId,
				'Content-Type: application/json'
			);

			// Open connection
			$ch = curl_init();

			curl_setopt($ch, CURLOPT_URL, $this->gatewayUrl);
			curl_setopt($ch, CURLOPT_POST, true);
			curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

			// Disabling SSL Certificate support temporarily
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

			curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));

			// Execute post
			$result = curl_exec($ch);

			if ($result === FALSE)
			{
				$output->success = false;
				$output->message = 'Communication Error: Unable to deliver message';
			}
			else
			{
				$output->success = true;
				$output->message = print_r($result,1);
			}

			curl_close($ch);
		}

		return $output;
	}
956895
public function getNextUnansweredToken()
    {
        $tokenSelect = $this->tracker->getTokenSelect();
        $tokenSelect
                ->andReceptionCodes()
                // ->andRespondents()
                // ->andRespondentOrganizations()
                // ->andConsents
                ->andRounds(array())
                ->andSurveys(array())
                ->forRespondent($this->getRespondentId())
                ->forGroupId($this->getSurvey()->getGroupId())
                ->onlySucces()
                ->onlyValid()
                ->forWhere('gsu_active = 1')
                ->forWhere('gro_active = 1 OR gro_active IS NULL')
                ->order(array('gto_valid_from', 'gto_round_order'));

        $this->_addRelation($tokenSelect);

        if ($tokenData = $tokenSelect->fetchRow()) {
            return $this->tracker->getToken($tokenData);
        }
    }
505739
public function sendNotificationToDevices($data)
    {
        if(!isset($data['device_tokens']) || empty($data['device_tokens'])) {
            throw new Exception('need param: device_tokens');
        }
        $newData = array(
            'type' => 'listcast',
            'payload' => array(
                'body' => array(
                    'title' => $data['title'],
                    'text' => $data['text'],
                )
            ),
        );
        if(is_array($data['device_tokens'])) {
            $newData['device_tokens'] = implode(',', $data['device_tokens']);
        } else {
            $newData['device_tokens'] = $data['device_tokens'];
        }

        return $this->send($newData);
    }