PageRenderTime 44ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/canoo/tests/testcases/level0/2.8.0/plug-ins/www/admin/plugins/oxMarket/pcApiClient/oxPublisherConsoleClient.php

https://bitbucket.org/valmy/openx
PHP | 238 lines | 100 code | 23 blank | 115 comment | 1 complexity | e388a3933281b1a9770e050322733062 MD5 | raw file
  1. <?php
  2. /*
  3. +---------------------------------------------------------------------------+
  4. | OpenX v2.8 |
  5. | ========== |
  6. | |
  7. | Copyright (c) 2003-2009 OpenX Limited |
  8. | For contact details, see: http://www.openx.org/ |
  9. | |
  10. | This program is free software; you can redistribute it and/or modify |
  11. | it under the terms of the GNU General Public License as published by |
  12. | the Free Software Foundation; either version 2 of the License, or |
  13. | (at your option) any later version. |
  14. | |
  15. | This program is distributed in the hope that it will be useful, |
  16. | but WITHOUT ANY WARRANTY; without even the implied warranty of |
  17. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
  18. | GNU General Public License for more details. |
  19. | |
  20. | You should have received a copy of the GNU General Public License |
  21. | along with this program; if not, write to the Free Software |
  22. | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
  23. +---------------------------------------------------------------------------+
  24. $Id: oxPublisherConsoleClient.php 29196 2008-11-20 14:16:53Z apetlyovanyy $
  25. */
  26. require_once MAX_PATH . '/lib/OA.php';
  27. require_once MAX_PATH . '/lib/OX/M2M/M2MProtectedRpc.php';
  28. require_once MAX_PATH . '/lib/OX/M2M/XmlRpcExecutor.php';
  29. require_once dirname(__FILE__) . '/oxPublisherConsoleClientException.php';
  30. /**
  31. * OpenX Market plugin - Publisher Console API client
  32. *
  33. * @package OpenXPlugin
  34. * @subpackage openXMarket
  35. * @author Andriy Petlyovanyy <apetlyovanyy@lohika.com>
  36. * @author Lukasz Wikierski <lukasz.wikierski@openx.net>
  37. */
  38. class Plugins_admin_oxMarket_PublisherConsoleClient
  39. {
  40. /**
  41. * @var OX_M2M_M2MProtectedRpc
  42. */
  43. protected $m2mprotected_xml_rpc_client;
  44. /**
  45. * @var OX_M2M_XmlRpcExecutor
  46. */
  47. protected $xml_rpc_client;
  48. /**
  49. * @var integer
  50. */
  51. protected $publisher_account_id;
  52. /**
  53. * @param OX_M2M_M2MProtectedRpc $m2mprotected_xml_rpc_client
  54. * @param OX_M2M_XmlRpcExecutor $xml_rpc_client
  55. * @param integer $publisher_account_id
  56. */
  57. public function __construct(OX_M2M_M2MProtectedRpc $m2mprotected_xml_rpc_client,
  58. OX_M2M_XmlRpcExecutor $xml_rpc_client,
  59. $publisher_account_id = null)
  60. {
  61. $this->publisher_account_id = $publisher_account_id;
  62. $this->m2mprotected_xml_rpc_client = $m2mprotected_xml_rpc_client;
  63. $this->xml_rpc_client = $xml_rpc_client;
  64. }
  65. protected function ensurePublisherAccountIdIsSet()
  66. {
  67. if (!isset($this->publisher_account_id)) {
  68. throw new Plugins_admin_oxMarket_PublisherConsoleClientException(
  69. 'publisher_account_id can not be null');
  70. }
  71. }
  72. protected function callXmlRpcClient($function, $params) {
  73. return $this->xml_rpc_client->call($function, $params);
  74. }
  75. protected function callM2mprotectedXmlRpcClient($function, $params) {
  76. return $this->m2mprotected_xml_rpc_client->call($function, $params);
  77. }
  78. protected function callXmlRpcFunctionWithPCAccount($function, $params = array())
  79. {
  80. $this->ensurePublisherAccountIdIsSet();
  81. $paramsWithPCAccount = array_merge(
  82. array($this->publisher_account_id), $params);
  83. return $this->callM2mprotectedXmlRpcClient($function, $paramsWithPCAccount);
  84. }
  85. /**
  86. * @param integer $publisher_account_id
  87. */
  88. public function setPublisherAccountId($publisher_account_id)
  89. {
  90. $this->publisher_account_id = $publisher_account_id;
  91. $this->ensurePublisherAccountIdIsSet();
  92. }
  93. /**
  94. * @param string $username
  95. * @param string $password
  96. * @return integer publisher_account_id
  97. */
  98. public function linkOxp($username, $password)
  99. {
  100. return $this->callM2mprotectedXmlRpcClient('linkOxp',
  101. array($username, md5($password)));
  102. }
  103. /**
  104. * @param integer $lastUpdate
  105. * @return string statistics file content
  106. */
  107. public function oxmStatistics($lastUpdate)
  108. {
  109. return $this->callXmlRpcFunctionWithPCAccount('oxmStatistics',
  110. array($lastUpdate));
  111. }
  112. /**
  113. * @param integer $lastUpdate
  114. * @return string statistics file content
  115. */
  116. public function oxmStatisticsLimited($lastUpdate)
  117. {
  118. return $this->callXmlRpcFunctionWithPCAccount('oxmStatisticsLimited',
  119. array($lastUpdate));
  120. }
  121. /**
  122. * @param string $websiteUrl
  123. * @return integer website id
  124. */
  125. public function newWebsite($websiteUrl)
  126. {
  127. return $this->callXmlRpcFunctionWithPCAccount('newWebsite', array(
  128. $websiteUrl));
  129. }
  130. /**
  131. * @param integer $websiteId
  132. * @param string $websiteUrl
  133. * @param array $att_ex
  134. * @param array $cat_ex
  135. * @param array $typ_ex
  136. * @return integer website id
  137. */
  138. public function updateWebsite($websiteId, $websiteUrl, $att_ex,
  139. $cat_ex, $typ_ex)
  140. {
  141. return $this->callXmlRpcFunctionWithPCAccount('updateWebsite',
  142. array($websiteId, $websiteUrl, $att_ex, $cat_ex, $typ_ex));
  143. }
  144. /**
  145. * Get Publisher Console account status
  146. *
  147. * @return integer account status
  148. */
  149. public function getAccountStatus()
  150. {
  151. return $this->callXmlRpcFunctionWithPCAccount('getAccountStatus',
  152. array());
  153. }
  154. /**
  155. * Create sso account and link this account to Publisher account for this Platform
  156. *
  157. * @param string $email user email address
  158. * @param string $username user name
  159. * @param string $md5password md5 hash of user password
  160. * @param string $captcha captcha value
  161. * @param string $captcha_random captcha random parameter
  162. * @return string publisher account UUID
  163. */
  164. public function createAccount($email, $username, $md5password, $captcha, $captcha_random)
  165. {
  166. return $this->callM2mprotectedXmlRpcClient('createAccount',
  167. array($email, $username, $md5password, $captcha, $captcha_random));
  168. }
  169. /**
  170. * Check if given sso user name is available
  171. *
  172. * @param string $userName
  173. * @return bool
  174. */
  175. public function isSsoUserNameAvailable($userName)
  176. {
  177. return $this->callXmlRpcClient('isSsoUserNameAvailable', array($userName));
  178. }
  179. /**
  180. * Returns array of Creative Attributes used in marketplace
  181. *
  182. * @return array array of attributes names where array keys are ids
  183. */
  184. public function getCreativeAttributes()
  185. {
  186. return $this->callXmlRpcClient('dictionary.getCreativeAttributes', array());
  187. }
  188. /**
  189. * Returns array of Creative Types used in marketplace
  190. *
  191. * @return array array of types names where array keys are ids
  192. */
  193. public function getCreativeTypes()
  194. {
  195. return $this->callXmlRpcClient('dictionary.getCreativeTypes', array());
  196. }
  197. /**
  198. * Returns array of Ad Categories used in marketplace
  199. *
  200. * @return array array of categories names where array keys are ids
  201. */
  202. public function getAdCategories()
  203. {
  204. return $this->callXmlRpcClient('dictionary.getAdCategories', array());
  205. }
  206. /**
  207. * Returns default restrictions.
  208. *
  209. * @return array default settings
  210. */
  211. public function getDefaultRestrictions()
  212. {
  213. return $this->callXmlRpcClient('dictionary.getDefaultRestrictions', array());
  214. }
  215. }