public function setUp() { parent::setUp(); $this->_model = Application_Model_Factory::getModel($this->_targetServer); $this->_adapter = new Zend_Http_Client_Adapter_Test(); $this->_model->getHttpClient()->setAdapter($this->_adapter); }
/** * Zakladni akce vyhledavani v obchode */ public function basicAction() { $isTest = Zend_Registry::get('config')->mtgim->isTest; $cardname = trim($this->_request->getParam('cardname')); $adapterName = $this->_request->getParam('adapter'); $foilType = $this->_request->getParam('foil'); if (!empty($cardname) && !empty($adapterName)) { //get adapter $adapter = Application_Model_Factory::getModel($adapterName, $foilType, $isTest); } try { if (isset($adapter) && $adapter->doCardRequest($cardname)) { $data = $adapter->getData(); $this->view->success = TRUE; $this->view->total = count($data); $this->view->results = $data; } else { $this->view->success = FALSE; $this->view->reason = 'NO_VALID_DATA'; } } catch (Exception $e) { $this->view->success = FALSE; $this->view->reason = 'PARSE_ERROR'; if (1 == $isTest) { $this->view->message = $e->getMessage(); $this->view->trace = $e->getTraceAsString(); } } }
public function testAvailableAdapters() { // production only adapters $this->assertEquals(Application_Model_Factory::getAvailableModels(0), array('cernyrytir' => 'Černý Rytíř', 'mystic' => 'Mystic Shop', 'najada' => 'Najáda', 'rishada' => 'Rishada')); // testing adapters $this->assertEquals(Application_Model_Factory::getAvailableModels(1), array('cernyrytir' => 'Černý Rytíř', 'mystic' => 'Mystic Shop', 'najada' => 'Najáda', 'rishada' => 'Rishada', 'fake' => 'Fake Adapter', 'fake_rishada' => 'Fake Rishada', 'fake_cr' => 'Fake Černý Rytíř')); // adapters without conditional parameter $this->assertEquals(Application_Model_Factory::getAvailableModels(), array('cernyrytir' => 'Černý Rytíř', 'mystic' => 'Mystic Shop', 'najada' => 'Najáda', 'rishada' => 'Rishada')); }
/** * Akce pro nalezeni ceny karty - odpovida vyhledavani karty na webu */ public function findPriceAction() { // --- nacteni vstupnich parametru --- $accKey = $this->_request_data['AccessKey']; $acc = $this->_getAccData($accKey); // overim, ze shop je validni i kdyz pouziju fake if (array_key_exists('Shop', $this->_request_data)) { if (!array_key_exists($this->_request_data['Shop'], Application_Model_Factory::getAvailableModels())) { return $this->_invalidResponse('Invalid Shop specified'); } // pokud je ucet testovaci, pouzivam fake adapter nezavisle na tom, co specifikoval if ($acc['isTest']) { $shop = 'fake'; $isTest = 1; } else { $shop = $this->_request_data['Shop']; $isTest = Zend_Registry::get('config')->mtgim->isTest; } } else { return $this->_invalidResponse('Missing Shop'); } if (array_key_exists('FoilType', $this->_request_data)) { $foil = $this->_request_data['FoilType']; if (!in_array($foil, array('A', 'R', 'F'))) { return $this->_invalidResponse('Invalid FoilType specified'); } } else { return $this->_invalidResponse('Missing FoilType'); } if (array_key_exists('CardName', $this->_request_data)) { $name = $this->_request_data['CardName']; } else { return $this->_invalidResponse('Missing CardName'); } // --- overeni podpisu --- // zde opravdu musi byt request data shop, protoze podpis se overuje z toho, co zaslal uzivatel // ne z toho co mu podstrcim ja if (!array_key_exists('Signature', $this->_request_data) || $this->_getFindPriceSignature($acc, $name, $this->_request_data['Shop'], $foil) != $this->_request_data['Signature']) { return $this->_invalidResponse('Invalid Signature', 401); } // --- inicializace a pouziti adapteru --- $adapter = Application_Model_Factory::getModel($shop, $foil, $isTest); try { $adapter->doCardRequest($name); $data = array('data' => $adapter->getData()); } catch (Exception $e) { return $this->_invalidResponse('Error communicating with shop', 500); } // --- odpoved --- $this->_response_data = $data; }
/** * Stranka pro vyhledavani */ public function searchAction() { $cardname = $this->_request->getParam('card'); if (empty($cardname)) { $this->getHelper('redirector')->goto('index', 'index'); } else { $this->view->meta['robots']['content'] = 'noindex,nofollow'; $this->view->meta['keywords']['content'] = 'Magic v mobilu, Výsledky hledání ceny karty ' . htmlspecialchars($cardname); $this->view->meta['description']['content'] = 'Výsledky hledání ceny karty \'' . htmlspecialchars($cardname) . '\' v MtGiM.cz'; //get adapter $adapters = array(); $availableAdapters = Application_Model_Factory::getAvailableModels(Zend_Registry::get('config')->mtgim->isTest); foreach ($availableAdapters as $key => $name) { $adapters[] = $this->_getSearchResultArr($key, $name); } $this->view->adapters = $adapters; $this->view->pageId = 'page-search'; } }