You are here

class HttpServiceApiWrapperPosts in HTTP Client Manager 8.2

Class HttpServiceApiWrapperPosts.

@package Drupal\http_client_manager\Plugin\HttpServiceApiWrapper

Hierarchy

Expanded class hierarchy of HttpServiceApiWrapperPosts

1 string reference to 'HttpServiceApiWrapperPosts'
http_client_manager_example.services.yml in modules/http_client_manager_example/http_client_manager_example.services.yml
modules/http_client_manager_example/http_client_manager_example.services.yml
1 service uses HttpServiceApiWrapperPosts
http_client_manager_example.api_wrapper.posts in modules/http_client_manager_example/http_client_manager_example.services.yml
Drupal\http_client_manager_example\Plugin\HttpServiceApiWrapper\HttpServiceApiWrapperPosts

File

modules/http_client_manager_example/src/Plugin/HttpServiceApiWrapper/HttpServiceApiWrapperPosts.php, line 13

Namespace

Drupal\http_client_manager_example\Plugin\HttpServiceApiWrapper
View source
class HttpServiceApiWrapperPosts extends HttpServiceApiWrapperBase {

  /**
   * {@inheritdoc}
   */
  public function getHttpClient() {
    return $this->httpClientFactory
      ->get('example_services_yaml');
  }

  /**
   * Create Post.
   *
   * @param string $title
   *   The Post title.
   * @param mixed $body
   *   The Post body.
   *
   * @return array
   *   The service response array.
   */
  public function createPost($title, $body) {
    $args = [
      'userId' => $this->currentUser
        ->id(),
      'title' => $title,
      'body' => $body,
    ];
    return $this
      ->call(Posts::CREATE_POST, $args)
      ->toArray();
  }

  /**
   * Find Posts.
   *
   * @return array
   *   An array of posts.
   */
  public function findPosts() {
    return $this
      ->call(Posts::FIND_POSTS)
      ->toArray();
  }

  /**
   * Find Post.
   *
   * @param int $postId
   *   The Post id.
   *
   * @return array
   *   An array representing the Post matching the provided id.
   */
  public function findPost($postId) {
    $args = [
      'postId' => (int) $postId,
    ];
    return $this
      ->call(Posts::FIND_POST, $args)
      ->toArray();
  }

  /**
   * Find Comments.
   *
   * @param null|int $postId
   *   The Post id from which extract the related Comments.
   *
   * @return array
   *   An array of Comments related to the given Post.
   */
  public function findComments($postId = NULL) {
    $args = is_null($postId) ? [] : [
      'postId' => (int) $postId,
    ];
    return $this
      ->call(Posts::FIND_COMMENTS, $args)
      ->toArray();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
HttpServiceApiWrapperBase::$cache protected property Drupal\Core\Cache\CacheBackendInterface definition.
HttpServiceApiWrapperBase::$currentUser protected property The current user.
HttpServiceApiWrapperBase::$httpClientFactory protected property The Http Client Factory Service.
HttpServiceApiWrapperBase::$languageManager protected property The Language Manager Service.
HttpServiceApiWrapperBase::$messenger protected property The Messenger Service.
HttpServiceApiWrapperBase::CACHE_ID_PREFIX constant The cache id prefix.
HttpServiceApiWrapperBase::call protected function Call REST web services.
HttpServiceApiWrapperBase::callByRequest protected function Call by Request.
HttpServiceApiWrapperBase::getCachedHttpConfigRequest protected function Get cached HTTP Config Request.
HttpServiceApiWrapperBase::getResponse protected function Get response.
HttpServiceApiWrapperBase::httpConfigRequest public function Executes an HTTP Config Request. Overrides HttpServiceApiWrapperInterface::httpConfigRequest
HttpServiceApiWrapperBase::logError protected function Logs a command exception.
HttpServiceApiWrapperBase::__construct public function HttpServiceApiWrapperBase constructor.
HttpServiceApiWrapperPosts::createPost public function Create Post.
HttpServiceApiWrapperPosts::findComments public function Find Comments.
HttpServiceApiWrapperPosts::findPost public function Find Post.
HttpServiceApiWrapperPosts::findPosts public function Find Posts.
HttpServiceApiWrapperPosts::getHttpClient public function Get HTTP Client. Overrides HttpServiceApiWrapperInterface::getHttpClient
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.