client.php 680 Bytes
Newer Older
1
2
3
4
<?php

namespace local_asystgrade\api;

5
6
use Exception;

7
8
9
10
11
12
defined('MOODLE_INTERNAL') || die();

class client {
    private $endpoint;
    private $httpClient;

13
14
15
16
    /**
     * @param string $endpoint
     * @param http_client|null $httpClient
     */
17
18
19
20
21
    public function __construct(string $endpoint, http_client $httpClient = null) {
        $this->endpoint = $endpoint;
        $this->httpClient = $httpClient ?: new http_client();
    }

22
23
24
25
26
27
    /**
     * @param array $data
     * @return bool|string
     * @throws Exception
     */
    public function send_data(array $data) {
28
29
30
31
32
        $response = $this->httpClient->post($this->endpoint, $data);

        return $response;
    }
}