/** * Reload the REST information. * This is only a empty placeholder. The child class can override it. * * @author David Pauli <*****@*****.**> * @since 0.0.0 * @since 0.0.1 Use HTTPRequestMethod enum. * @since 0.1.0 Use a default Locale. * @since 0.1.1 Unstatic every attributes. */ private function load() { // if the REST path empty -> this is the not the implementation or can't get something else if (InputValidator::isEmpty(self::RESTPATH) || !RESTClient::setRequestMethod(HTTPRequestMethod::GET)) { return; } $content = RESTClient::sendWithLocalization(self::RESTPATH, Locales::getLocale()); // if respond is empty if (InputValidator::isEmpty($content)) { return; } // reset values $this->resetValues(); if (!InputValidator::isEmptyArrayKey($content, "name")) { $this->NAME = $content["name"]; } if (!InputValidator::isEmptyArrayKey($content, "navigationCaption")) { $this->NAVIGATIONCAPTION = $content["navigationCaption"]; } if (!InputValidator::isEmptyArrayKey($content, "description")) { $this->DESCRIPTION = $content["description"]; } // update timestamp when make the next request $timestamp = (int) (microtime(true) * 1000); $this->NEXT_REQUEST_TIMESTAMP = $timestamp + RESTClient::$NEXT_RESPONSE_WAIT_TIME; }
/** * Reload the REST information. * * @author David Pauli <*****@*****.**> * @since 0.0.0 * @since 0.0.1 Use HTTPRequestMethod enum. * @since 0.1.0 Use a default Locale. */ private static function load() { // if request method is blocked if (!RESTClient::setRequestMethod(HTTPRequestMethod::GET)) { return; } $content = RESTClient::sendWithLocalization(self::$RESTPATH, Locales::getLocale()); // if respond is empty if (InputValidator::isEmpty($content)) { return; } // reset values self::resetValues(); if (!InputValidator::isEmptyArrayKey($content, "name")) { self::$NAME = $content["name"]; } if (!InputValidator::isEmptyArrayKey($content, "title")) { self::$TITLE = $content["title"]; } if (!InputValidator::isEmptyArrayKey($content, "navigationCaption")) { self::$NAVIGATIONCAPTION = $content["navigationCaption"]; } if (!InputValidator::isEmptyArrayKey($content, "shortDescription")) { self::$SHORTDESCRIPTION = $content["shortDescription"]; } if (!InputValidator::isEmptyArrayKey($content, "description")) { self::$DESCRIPTION = $content["description"]; } if (!InputValidator::isEmptyArrayKey($content, "company")) { self::$COMPANY = $content["company"]; } if (!InputValidator::isEmptyArrayKey($content, "contactPerson")) { self::$CONTACTPERSON = $content["contactPerson"]; } if (!InputValidator::isEmptyArrayKey($content, "contactPersonJobTitle")) { self::$CONTACTPERSONJOBTITLE = $content["contactPersonJobTitle"]; } if (!InputValidator::isEmptyArrayKey($content, "address")) { self::$ADDRESS = $content["address"]; } if (!InputValidator::isEmptyArrayKey($content, "phone")) { self::$PHONE = $content["phone"]; } if (!InputValidator::isEmptyArrayKey($content, "email")) { self::$EMAIL = $content["email"]; } // update timestamp when make the next request $timestamp = (int) (microtime(true) * 1000); self::$NEXT_REQUEST_TIMESTAMP = $timestamp + RESTClient::NEXT_RESPONSE_WAIT_TIME; }
/** * @group utility */ function testSendWithLocalization() { RESTClient::connect("sandbox.epages.com", "EpagesDevD20150929T075829R63", "icgToyl45PKhmkz6E2PUQOriaCoE5Wzq", true); RESTClient::setRequestMethod("GET"); RESTClient::sendWithLocalization("locale", "NoLocale"); $this->assertTrue(RESTClient::error()); $this->assertEquals("RESTC-3", RESTClient::errorNumber()); RESTClient::sendWithLocalization("locales", "NoLocale", "NoArray"); $this->assertTrue(RESTClient::error()); $this->assertEquals("RESTC-3", RESTClient::errorNumber()); RESTClient::sendWithLocalization("locales", "en_GB", "NoArray"); $this->assertTrue(RESTClient::error()); $this->assertEquals("RESTC-5", RESTClient::errorNumber()); RESTClient::disconnect(); RESTClient::sendWithLocalization("locales", "NoLocale"); $this->assertTrue(RESTClient::error()); $this->assertEquals("RESTC-3", RESTClient::errorNumber()); RESTClient::disconnect(); RESTClient::sendWithLocalization("locales", "en_GB"); $this->assertTrue(RESTClient::error()); $this->assertEquals("RESTC-6", RESTClient::errorNumber()); RESTClient::connect("sandbox.epages.com", "EpagesDevD20150929T075829R63", "icgToyl45PKhmkz6E2PUQOriaCoE5Wzq", true); RESTClient::setRequestMethod("GET"); RESTClient::sendWithLocalization("NoValidRessource", "en_GB"); $this->assertFalse(RESTClient::isResponseOk()); $this->assertFalse(RESTClient::isResponseFound()); RESTClient::sendWithLocalization("NoValidRessource", "NoLocale"); $this->assertTrue(RESTClient::error()); $this->assertEquals("RESTC-3", RESTClient::errorNumber()); RESTClient::sendWithLocalization("locales", "de_DE", "noArray"); $this->assertTrue(RESTClient::error()); $this->assertEquals("RESTC-5", RESTClient::errorNumber()); RESTClient::sendWithLocalization("locales", "de_DE"); $this->assertFalse(RESTClient::error()); $this->assertNull(RESTClient::errorNumber()); }
/** * Loads the order. * * @author David Pauli <*****@*****.**> * @since 0.1.3 * @since 0.2.1 Implement REST client fixes. */ private function load() { // if parameter is wrong or GET is blocked if (!RESTClient::setRequestMethod(HTTPRequestMethod::GET)) { self::errorSet("RESTC-9"); return; } RESTClient::sendWithLocalization(self::RESTPATH . "/" . $this->orderId, Locales::getLocale()); $content = RESTClient::getJSONContent(); // if respond is empty if (InputValidator::isEmpty($content)) { self::errorSet("OF-1"); return; } $this->parseData($content); // update timestamp when make the next request $timestamp = (int) (microtime(true) * 1000); $this->NEXT_REQUEST_TIMESTAMP = $timestamp + RESTClient::$NEXT_RESPONSE_WAIT_TIME; }