Ejemplo n.º 1
0
 /**
  * Approved events should show in the upcoming list
  *
  * @param array $events
  * @return bool
  */
 public function areEventsApproved(array &$events)
 {
     $response = $this->httpClient->get($this->joindinEvent->getUrl('users/hosted?username='******''));
     // get the URI for the hosted events
     $usernameInfo = json_decode($response->getBody()->getContents(), true);
     $hostedEventsUri = '';
     if (!empty($usernameInfo['users'])) {
         if (!isset($usernameInfo['users'][0]['hosted_events_uri'])) {
             return false;
         }
         $hostedEventsUri = $usernameInfo['users'][0]['hosted_events_uri'];
     }
     $response = $this->httpClient->get($hostedEventsUri);
     $hostedEvents = json_decode($response->getBody()->getContents(), true)['events'];
     if (empty($hostedEvents)) {
         return false;
     }
     $events = array_reduce($events, function ($carry, $item) {
         $carry[$item->joindin_event_name] = $item;
         return $carry;
     });
     $found = false;
     foreach ($hostedEvents as $event) {
         if (array_key_exists($event['name'], $events)) {
             $found = true;
             $events[$event['name']]->uri = $event['uri'];
         }
     }
     return $found;
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  * @throws JsonException
  */
 public function sendRequest($method, $parameters = [], $options = [])
 {
     $type = 'GET';
     if (array_key_exists('type', $options)) {
         $allowed_types = ['GET', 'POST'];
         if (!in_array($options['type'], $allowed_types)) {
             throw new InvalidArgumentException('Invalid request type ' . $options['type']);
         } else {
             $type = $options['type'];
         }
     }
     $method_name = ucfirst($method);
     $request_parameters = array_merge(['method' => $method_name, 'token' => $this->api_key], $parameters);
     try {
         if ('GET' === $type) {
             $response = $this->client->get($this->url, ['query' => $request_parameters, 'connect_timeout' => 10]);
         } else {
             $response = $this->client->post($this->url, ['form_params' => $request_parameters, 'connect_timeout' => 10]);
         }
         $json_data = $response->getBody()->getContents();
     } catch (\GuzzleHttp\Exception\GuzzleException $error) {
         throw new ApiException($error->getMessage(), ApiException::HTTP_ERROR, $error);
     }
     //Удаление BOM в выводе если есть
     $json_data = preg_replace('~^\\xEF\\xBB\\xBF~isu', '', $json_data);
     $data = json_decode($json_data, false);
     //В случае неудачи разбора JSON кидаем исключение JsonException
     if (NULL === $data) {
         throw new JsonException('Failed to parse received json with message ' . json_last_error_msg(), JsonException::DECODE_EXCEPTION, null, $json_data);
     }
     //Если API вернуло какую-то ошибку
     if (is_array($data) && isset($data[0]) && isset($data[0]->err)) {
         throw new ApiException('Errors occured while processing API request', ApiException::API_ERROR, null, $data[0]->err);
     } elseif (is_object($data) && isset($data->err)) {
         throw new ApiException('Errors occured while processing API request', ApiException::API_ERROR, null, $data->err);
     }
     return $data;
 }
Ejemplo n.º 3
0
 /**
  * @param string $language
  * @return \Psr\Http\Message\ResponseInterface
  */
 public function createJoindinTalk($language = 'English - UK')
 {
     $response = $this->httpClient->post($this->joindinEvent->getUrl('events/' . $this->joindinEvent->getJoindinEventID() . '/talks'), ['json' => $this->joindinEvent->getCreateEventTitlePayload($this->event, $language), 'headers' => $this->joindinEvent->getHeaders()]);
     $this->joindinEvent->setTalkLocation($response->getHeader('location')[0]);
     return $response;
 }