/** * Subcribe user to newsletter * * @param string $email * @param array $additionalParams * @throws SyneriseException * @return \Synerise\Response\Newsletter */ public function subscribe($email, array $additionalParams = array()) { try { $baseParams = array(); $baseParams['email'] = $email; $uuid = $this->getUuid(); if (!empty($uuid)) { $baseParams['uuid'] = $uuid; } if (isset($additionalParams['sex'])) { //@todo $baseParams['sex'] = $additionalParams['sex']; } try { $response = $this->put(SyneriseAbstractHttpClient::BASE_API_URL . "/client/subscribe", array('json' => array_merge($baseParams, array('params' => $additionalParams)))); $responseArray = json_decode($response->getBody(), true); $responseNewsletter = new SyneriseResponseNewsletter($responseArray); return $responseNewsletter->success(); } catch (RequestException $e) { $responseArray = json_decode($e->getResponse()->getBody(), true); $responseNewsletter = new SyneriseResponseNewsletter($responseArray); return $responseNewsletter->fail(); } throw new SyneriseException('Unknown error', SyneriseException::UNKNOWN_ERROR); } catch (\Exception $e) { if ($this->getLogger()) { $this->getLogger()->alert($e->getMessage()); } throw $e; } }
public function subscribe($email, $additionalParams = array()) { try { $baseParams = array(); $baseParams['email'] = $email; if (!empty($this->getUuid())) { $baseParams['uuid'] = $this->getUuid(); } if (isset($additionalParams['sex'])) { //@todo $baseParams['sex '] = $additionalParams['sex']; } /** * @var Response */ $request = $this->createRequest("PUT", SyneriseAbstractHttpClient::BASE_API_URL . "/client/subscribe", array('body' => array_merge($baseParams, array('params' => $additionalParams)))); $this->_log($request, 'NEWSLETTER'); $response = $this->send($request); $this->_log($response, 'NEWSLETTER'); $class = 'GuzzleHttp\\Message\\Response'; if ($response instanceof $class && $response->getStatusCode() == '200') { $responseNewsletter = new SyneriseResponseNewsletter($response->json()); return $responseNewsletter->success(); } throw new SyneriseException('API Synerise not responsed 200.', SyneriseException::API_RESPONSE_ERROR); } catch (\Exception $e) { $this->_log($e->getMessage(), 'NEWSLETTER'); throw $e; } }