Пример #1
0
 /**
  * @param UserInterface             $user
  * @param NamedNumberInterface[]    $recipient
  * @param string                    $coverPage
  * @param string                    $coverPageText
  * @param string                    $resolution
  * @param \DateTime                 $sendTime
  * @param array                     $attachments
  * @return string
  */
 public function sendFax(UserInterface $user, array $recipient, $coverPage, $coverPageText, $resolution, \DateTime $sendTime, array $attachments)
 {
     $form = new FormRequest();
     $form->setResource(self::FAX_OUT_ENDPOINT);
     $recipients = array();
     foreach ($recipient as $rec) {
         $recipients[] = $rec->getNumber() . ($rec->getName() ? '|' . $rec->getName() : '');
     }
     $uploads = array();
     foreach ($attachments as $attachment) {
         $uploads[] = new FormUpload($attachment);
     }
     $fields = array('Username' => $user->getUserNumber(), 'Password' => $user->getPassword(), 'Extension' => $user->getExtension(), 'Recipient' => $recipients, 'Coverpage' => $coverPage, 'Coverpagetext' => $coverPageText, 'Resolution' => $resolution, 'Sendtime' => $sendTime->format('d:m:y h:i'), 'Attachment' => $uploads);
     $form->addFields($fields);
     return $this->browser->post(self::FAX_OUT_ENDPOINT, $form->getHeaders(), $form->getContent());
 }
Пример #2
0
 /**
  * Authenticate on OAuth server with the specific authorization code.
  *
  * @param string $code The authorization code
  *
  * @return array The struct array('access_token' => string, 'expires_in' => integer)
  *
  * @throws Exception\AuthException
  * @throws Exception\NetworkException
  */
 public function authenticate($code)
 {
     $request = new FormRequest();
     $response = new Response();
     $request->setHost(self::BASEURL);
     $request->setResource('/token');
     $request->setField('grant_type', 'authorization_code');
     $request->setField('code', $code);
     $request->setField('client_id', $this->appId);
     $request->setField('client_secret', $this->appSecret);
     try {
         $this->client->send($request, $response);
     } catch (ClientException $ex) {
         throw new Exception\NetworkException($ex, $request, $response);
     }
     if ($response->getStatusCode() === 200) {
         return json_decode($response->getContent(), true);
     }
     throw new Exception\AuthException('Could not authenticate. Reason: ' . $response->getContent(), $response->getStatusCode());
 }
 /**
  * @param $referenceFull
  *
  * @return Response
  *
  * @throws MediaStorageClientApiException
  */
 public function getMedia($referenceFull)
 {
     if (empty($referenceFull)) {
         throw new MediaStorageClientApiException('Param referenceFull is empty');
     }
     try {
         $request = new FormRequest();
         $request->setMethod(FormRequest::METHOD_GET);
         $request->setHost($this->getApiUrlConfig('base_url'));
         $url = $this->getApiUrlConfig('get_media_by_reference_full_url') . '/' . ltrim($referenceFull, '/');
         $request->setResource($url);
         $this->logger->debug('Send ' . $this->getApiUrlConfig('base_url') . $url);
         /** @var Response $response */
         $response = $this->client->send($request, null);
         $this->logger->debug('Response: ' . $response->getStatusCode() . ' ' . substr($response->getContent(), 0, 300));
     } catch (\Exception $e) {
         throw new MediaStorageClientApiException($e->getMessage());
     }
     return $response;
 }