private static function _moSmsFromFields(&$json, &$fields)
    {
        if ($fields->type === 'mo_text') {
            $result = new Api\MoTextSms();
            $result->setBody($fields->body);

            if (isset($fields->keyword)) {
                $result->setKeyword($fields->keyword);
            }
        } else if ($fields->type === 'mo_binary') {
            $result = new Api\MoBinarySms();
            $result->setBody(base64_decode($fields->body));
            $result->setUdh(hex2bin($fields->udh));
        } else {
            throw new UnexpectedResponseException(
                "Received unexpected inbound type " . $fields->type,
                $json
            );
        }

        $result->setMessageId($fields->id);
        $result->setSender($fields->from);
        $result->setRecipient($fields->to);

        if (isset($fields->operator)) {
            $result->setOperator($fields->operator);
        }

        if (isset($fields->sent_at)) {
            $result->setSentAt(
                Deserialize::_dateTime($json, $fields->sent_at)
            );
        }

        if (isset($fields->received_at)) {
            $result->setReceivedAt(
                Deserialize::_dateTime($json, $fields->received_at)
            );
        }

        return $result;
    }
private static function _moSmsFromFields(&$json, &$fields)
    {
        if ($fields->type === 'mo_text') {
            $result = new Api\MoTextSms();
            $result->setBody($fields->body);

            if (isset($fields->keyword)) {
                $result->setKeyword($fields->keyword);
            }
        } else if ($fields->type === 'mo_binary') {
            $result = new Api\MoBinarySms();
            $result->setBody(base64_decode($fields->body));
            $result->setUdh(hex2bin($fields->udh));
        } else {
            throw new UnexpectedResponseException(
                "Received unexpected inbound type " . $fields->type,
                $json
            );
        }

        $result->setMessageId($fields->id);
        $result->setSender($fields->from);
        $result->setRecipient($fields->to);

        if (isset($fields->operator)) {
            $result->setOperator($fields->operator);
        }

        if (isset($fields->sent_at)) {
            $result->setSentAt(
                Deserialize::_dateTime($json, $fields->sent_at)
            );
        }

        if (isset($fields->received_at)) {
            $result->setReceivedAt(
                Deserialize::_dateTime($json, $fields->received_at)
            );
        }

        return $result;
    }
private static function _moSmsFromFields ( & $ json , & $ fields ) { if ( $ fields -> type === 'mo_text' ) { $ result = new Api \ MoTextSms ( ) ; $ result -> setBody ( $ fields -> body ) ; if ( isset ( $ fields -> keyword ) ) { $ result -> setKeyword ( $ fields -> keyword ) ; } } else if ( $ fields -> type === 'mo_binary' ) { $ result = new Api \ MoBinarySms ( ) ; $ result -> setBody ( base64_decode ( $ fields -> body ) ) ; $ result -> setUdh ( hex2bin ( $ fields -> udh ) ) ; } else { throw new UnexpectedResponseException ( "Received unexpected inbound type " . $ fields -> type , $ json ) ; } $ result -> setMessageId ( $ fields -> id ) ; $ result -> setSender ( $ fields -> from ) ; $ result -> setRecipient ( $ fields -> to ) ; if ( isset ( $ fields -> operator ) ) { $ result -> setOperator ( $ fields -> operator ) ; } if ( isset ( $ fields -> sent_at ) ) { $ result -> setSentAt ( Deserialize :: _dateTime ( $ json , $ fields -> sent_at ) ) ; } if ( isset ( $ fields -> received_at ) ) { $ result -> setReceivedAt ( Deserialize :: _dateTime ( $ json , $ fields -> received_at ) ) ; } return $ result ; }
Helper that reads an MO from the given fields.

@param string $json   original JSON formatted text
@param object $fields the result of `json_decode`

@return Api\MoSms the parsed inbound message

@throws UnexpectedResponseException if the JSON contained an
unexpected message type
Helper that reads an MO from the given fields .