original_string: public function send(Message $message)
      {
  
          if (!$this->serverApiKey) {
              throw new Exception("Server API Key not set", Exception::ILLEGAL_API_KEY);
          }
  
          //GCM response: Number of messages on bulk (1001) exceeds maximum allowed (1000)
          if (count($message->getRegistrationIds()) > 1000) {
              throw new Exception(
                  "Malformed request: Registration Ids exceed the GCM imposed limit of 1000",
                  Exception::MALFORMED_REQUEST
              );
          }
  
          $rawData = $this->formMessageData($message);
          $this->validatePayloadSize($rawData, 'data', 4096);
          $this->validatePayloadSize($rawData, 'notification', 2048);
          $data = json_encode($rawData);
  
          $headers = array(
              'Authorization: key='.$this->serverApiKey,
              'Content-Type: application/json'
          );
  
          $ch = curl_init();
  
          curl_setopt($ch, CURLOPT_URL, $this->gcmUrl);
  
          curl_setopt($ch, CURLOPT_POST, true);
          curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  
          if ($this->caInfoPath !== false) {
              curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
              curl_setopt($ch, CURLOPT_CAINFO, $this->caInfoPath);
          } else {
              curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
          }
  
          curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  
          $resultBody = curl_exec($ch);
          $resultHttpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  
          curl_close($ch);
  
          switch ($resultHttpCode) {
              case "200":
                  //All fine. Continue response processing.
                  break;
  
              case "400":
                  throw new Exception('Malformed request. '.$resultBody, Exception::MALFORMED_REQUEST);
                  break;
  
              case "401":
                  throw new Exception('Authentication Error. '.$resultBody, Exception::AUTHENTICATION_ERROR);
                  break;
  
              default:
                  //TODO: Retry-after
                  throw new Exception("Unknown error. ".$resultBody, Exception::UNKNOWN_ERROR);
                  break;
          }
  
          return new Response($message, $resultBody);
      }
code: public function send(Message $message)
      {
  
          if (!$this->serverApiKey) {
              throw new Exception("Server API Key not set", Exception::ILLEGAL_API_KEY);
          }
  
          //GCM response: Number of messages on bulk (1001) exceeds maximum allowed (1000)
          if (count($message->getRegistrationIds()) > 1000) {
              throw new Exception(
                  "Malformed request: Registration Ids exceed the GCM imposed limit of 1000",
                  Exception::MALFORMED_REQUEST
              );
          }
  
          $rawData = $this->formMessageData($message);
          $this->validatePayloadSize($rawData, 'data', 4096);
          $this->validatePayloadSize($rawData, 'notification', 2048);
          $data = json_encode($rawData);
  
          $headers = array(
              'Authorization: key='.$this->serverApiKey,
              'Content-Type: application/json'
          );
  
          $ch = curl_init();
  
          curl_setopt($ch, CURLOPT_URL, $this->gcmUrl);
  
          curl_setopt($ch, CURLOPT_POST, true);
          curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  
          if ($this->caInfoPath !== false) {
              curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
              curl_setopt($ch, CURLOPT_CAINFO, $this->caInfoPath);
          } else {
              curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
          }
  
          curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  
          $resultBody = curl_exec($ch);
          $resultHttpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  
          curl_close($ch);
  
          switch ($resultHttpCode) {
              case "200":
                  //All fine. Continue response processing.
                  break;
  
              case "400":
                  throw new Exception('Malformed request. '.$resultBody, Exception::MALFORMED_REQUEST);
                  break;
  
              case "401":
                  throw new Exception('Authentication Error. '.$resultBody, Exception::AUTHENTICATION_ERROR);
                  break;
  
              default:
                  //TODO: Retry-after
                  throw new Exception("Unknown error. ".$resultBody, Exception::UNKNOWN_ERROR);
                  break;
          }
  
          return new Response($message, $resultBody);
      }
code_tokens: public function send ( Message $ message ) { if ( ! $ this -> serverApiKey ) { throw new Exception ( "Server API Key not set" , Exception :: ILLEGAL_API_KEY ) ; } //GCM response: Number of messages on bulk (1001) exceeds maximum allowed (1000) if ( count ( $ message -> getRegistrationIds ( ) ) > 1000 ) { throw new Exception ( "Malformed request: Registration Ids exceed the GCM imposed limit of 1000" , Exception :: MALFORMED_REQUEST ) ; } $ rawData = $ this -> formMessageData ( $ message ) ; $ this -> validatePayloadSize ( $ rawData , 'data' , 4096 ) ; $ this -> validatePayloadSize ( $ rawData , 'notification' , 2048 ) ; $ data = json_encode ( $ rawData ) ; $ headers = array ( 'Authorization: key=' . $ this -> serverApiKey , 'Content-Type: application/json' ) ; $ ch = curl_init ( ) ; curl_setopt ( $ ch , CURLOPT_URL , $ this -> gcmUrl ) ; curl_setopt ( $ ch , CURLOPT_POST , true ) ; curl_setopt ( $ ch , CURLOPT_HTTPHEADER , $ headers ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , true ) ; if ( $ this -> caInfoPath !== false ) { curl_setopt ( $ ch , CURLOPT_SSL_VERIFYPEER , true ) ; curl_setopt ( $ ch , CURLOPT_CAINFO , $ this -> caInfoPath ) ; } else { curl_setopt ( $ ch , CURLOPT_SSL_VERIFYPEER , false ) ; } curl_setopt ( $ ch , CURLOPT_POSTFIELDS , $ data ) ; $ resultBody = curl_exec ( $ ch ) ; $ resultHttpCode = curl_getinfo ( $ ch , CURLINFO_HTTP_CODE ) ; curl_close ( $ ch ) ; switch ( $ resultHttpCode ) { case "200" : //All fine. Continue response processing. break ; case "400" : throw new Exception ( 'Malformed request. ' . $ resultBody , Exception :: MALFORMED_REQUEST ) ; break ; case "401" : throw new Exception ( 'Authentication Error. ' . $ resultBody , Exception :: AUTHENTICATION_ERROR ) ; break ; default : //TODO: Retry-after throw new Exception ( "Unknown error. " . $ resultBody , Exception :: UNKNOWN_ERROR ) ; break ; } return new Response ( $ message , $ resultBody ) ; }
docstring: Send message to GCM
  
  @param \CodeMonkeysRu\GCM\Message $message
  @throws \CodeMonkeysRu\GCM\Exception
  @return \CodeMonkeysRu\GCM\Response
docstring_tokens: Send message to GCM