You are here

class RemoteManager in Entity Share 8

Same name and namespace in other branches
  1. 8.3 modules/entity_share_client/src/Service/RemoteManager.php \Drupal\entity_share_client\Service\RemoteManager
  2. 8.2 modules/entity_share_client/src/Service/RemoteManager.php \Drupal\entity_share_client\Service\RemoteManager

Class RemoteManager.

@package Drupal\entity_share_client\Service

Hierarchy

Expanded class hierarchy of RemoteManager

1 string reference to 'RemoteManager'
entity_share_client.services.yml in modules/entity_share_client/entity_share_client.services.yml
modules/entity_share_client/entity_share_client.services.yml
1 service uses RemoteManager
entity_share_client.remote_manager in modules/entity_share_client/entity_share_client.services.yml
Drupal\entity_share_client\Service\RemoteManager

File

modules/entity_share_client/src/Service/RemoteManager.php, line 14

Namespace

Drupal\entity_share_client\Service
View source
class RemoteManager implements RemoteManagerInterface {

  /**
   * The HTTP client factory.
   *
   * @var \Drupal\Core\Http\ClientFactory
   */
  protected $httpClientFactory;

  /**
   * RemoteManager constructor.
   *
   * @param \Drupal\Core\Http\ClientFactory $http_client_factory
   *   The HTTP client factory.
   */
  public function __construct(ClientFactory $http_client_factory) {
    $this->httpClientFactory = $http_client_factory;
  }

  /**
   * {@inheritdoc}
   */
  public function prepareClient(RemoteInterface $remote) {
    $http_client = $this->httpClientFactory
      ->fromOptions([
      'base_uri' => $remote
        ->get('url'),
      'cookies' => TRUE,
      'allow_redirects' => TRUE,
    ]);
    $http_client
      ->post('/user/login', [
      'form_params' => [
        'name' => $remote
          ->get('basic_auth_username'),
        'pass' => $remote
          ->get('basic_auth_password'),
        'form_id' => 'user_login_form',
      ],
    ]);
    return $http_client;
  }

  /**
   * {@inheritdoc}
   */
  public function prepareJsonApiClient(RemoteInterface $remote) {
    return $this->httpClientFactory
      ->fromOptions([
      'base_uri' => $remote
        ->get('url'),
      'auth' => [
        $remote
          ->get('basic_auth_username'),
        $remote
          ->get('basic_auth_password'),
      ],
      'headers' => [
        'Content-type' => 'application/vnd.api+json',
      ],
    ]);
  }

  /**
   * {@inheritdoc}
   */
  public function getChannelsInfos(RemoteInterface $remote) {
    $http_client = $this
      ->prepareJsonApiClient($remote);
    $json_response = $http_client
      ->get('entity_share')
      ->getBody()
      ->getContents();
    $json = Json::decode($json_response);
    return $json['data']['channels'];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RemoteManager::$httpClientFactory protected property The HTTP client factory.
RemoteManager::getChannelsInfos public function Get the channels infos of a remote website. Overrides RemoteManagerInterface::getChannelsInfos
RemoteManager::prepareClient public function Prepare an HTTP client authenticated to handle private files. Overrides RemoteManagerInterface::prepareClient
RemoteManager::prepareJsonApiClient public function Prepare an HTTP client for the JSON API endpoints. Overrides RemoteManagerInterface::prepareJsonApiClient
RemoteManager::__construct public function RemoteManager constructor.