/** * Executes a service listed on ServiceEnum class. * * @param string $action * @param array $arguments * * @throws \LeroyMerlin\ExactTarget\Exception\ActionNotFoundException * @throws \LeroyMerlin\ExactTarget\Exception\RequestException * * @return \Psr\Http\Message\ResponseInterface */ public function __call($action, $arguments) { $token = $this->getToken(); $actionInfo = ServiceEnum::toEndpoint($action); $parameters = count($arguments) ? $arguments[0] : []; $data = isset($parameters['data']) ? $parameters['data'] : []; return $this->requestBuilder->request($this->urlBuilder->build($actionInfo['subdomain'], $actionInfo['action'], $actionInfo['service'], $parameters), $actionInfo['method'], ['json' => $data, 'headers' => ['Authorization' => 'Bearer ' . $token]]); }
/** * Retrieves a new token to API authentication * * @return string */ public function request() { $requestInfo = ServiceEnum::toEndpoint('requestToken'); $parameters = ['clientId' => $this->clientId, 'clientSecret' => $this->clientSecret]; return $this->requestBuilder->request((new UrlBuilder())->build($requestInfo['subdomain'], $requestInfo['action'], $requestInfo['service']), $requestInfo['method'], ['json' => $parameters]); }