HttpServiceApiWrapperPosts.php in HTTP Client Manager 8.2
File
modules/http_client_manager_example/src/Plugin/HttpServiceApiWrapper/HttpServiceApiWrapperPosts.php
View source
<?php
namespace Drupal\http_client_manager_example\Plugin\HttpServiceApiWrapper;
use Drupal\http_client_manager\Plugin\HttpServiceApiWrapper\HttpServiceApiWrapperBase;
use Drupal\http_client_manager_example\api\Commands\Posts;
class HttpServiceApiWrapperPosts extends HttpServiceApiWrapperBase {
public function getHttpClient() {
return $this->httpClientFactory
->get('example_services_yaml');
}
public function createPost($title, $body) {
$args = [
'userId' => $this->currentUser
->id(),
'title' => $title,
'body' => $body,
];
return $this
->call(Posts::CREATE_POST, $args)
->toArray();
}
public function findPosts() {
return $this
->call(Posts::FIND_POSTS)
->toArray();
}
public function findPost($postId) {
$args = [
'postId' => (int) $postId,
];
return $this
->call(Posts::FIND_POST, $args)
->toArray();
}
public function findComments($postId = NULL) {
$args = is_null($postId) ? [] : [
'postId' => (int) $postId,
];
return $this
->call(Posts::FIND_COMMENTS, $args)
->toArray();
}
}