/**
  * Processes incoming messages
  */
 public function inbound()
 {
     // Get the received data
     $data = array_merge($_GET, $_POST);
     // Verify the API key and incoming messageId parameters
     if (!empty($data['key']) and !empty($data['messageId']) and Nexmo_Model::is_valid_api_key($data['key'], 'inbound_message_key')) {
         // Extract fields from the submitted data
         $log_data = array('message_id' => $data['messageId'], 'message_type' => 1, 'message_sender' => $data['msisdn']);
         // Initialize model for updating the internal nexmo message log
         $log_entry = new Nexmo_Message_Log_Model();
         if ($log_entry->validate($log_data)) {
             // Success, save
             $log_entry->save();
         }
         //  Add entry to the main messages list
         sms::add($data['msisdn'], $data['text']);
     } else {
         Kohana::log('error', Kohana::lang('nexmo.invalid_url_auth_key'));
     }
 }
 /**
  * Callback function for the update_message_log event. This method is
  * called when a message has been sent via the Nexmo plugin and a response
  * has been received from the gateway. This function extracts the information
  * from the response and updates the message log
  */
 public function update_message_log()
 {
     // Get the event data and decode it to json
     $response = Event::$data;
     // Get each message in the response and update the log
     foreach ($response->messages as $message) {
         // Only process successful messages
         if ($message->status == 0) {
             // Model for the message logs
             $log_entry = new Nexmo_Message_Log_Model();
             $log_entry->message_id = $message->messageid;
             $log_entry->message_type = 0;
             $log_entry->delivery_status = 0;
             // Save
             $log_entry->save();
         } else {
             // Log failure
             Kohana::log('error', Kohana::lang('nexmo.response_codes.' . $message->status));
         }
     }
 }