|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Codenixsv\MessariApi\Api; |
|
6
|
|
|
|
|
7
|
|
|
use Exception; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class News |
|
11
|
|
|
* @package Codenixsv\MessariApi\Api |
|
12
|
|
|
*/ |
|
13
|
|
|
class News extends Api |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @param int|null $page Page number, starts at 1. Increment to paginate through results (until |
|
17
|
|
|
* result is empty array) |
|
18
|
|
|
* @param string|null $fields pare down the returned fields (comma , separated, drill down with a slash /) |
|
19
|
|
|
* @return array |
|
20
|
|
|
* @throws Exception |
|
21
|
|
|
*/ |
|
22
|
2 |
|
public function getAll(?int $page = null, ?string $fields = null): array |
|
23
|
|
|
{ |
|
24
|
|
|
$params = array_filter(compact('fields', 'page'), function ($value) { |
|
25
|
2 |
|
return !is_null($value); |
|
26
|
2 |
|
}); |
|
27
|
|
|
|
|
28
|
2 |
|
$query = http_build_query($params); |
|
29
|
2 |
|
$query = empty($query) ? $query : ('?' . $query); |
|
30
|
2 |
|
$response = $this->client->getBaseClient()->get('/news' . $query); |
|
31
|
|
|
|
|
32
|
2 |
|
return $this->transformer->transform($response); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param string $assetKey This "key" can be the asset's ID (unique), slug (unique), or symbol (non-unique) |
|
38
|
|
|
* @param string|null $fields pare down the returned fields (comma , separated, drill down with a slash /) |
|
39
|
|
|
* @param bool|null $asMarkdown formatting (other than HTML links) is hidden. Use this query param to return |
|
40
|
|
|
* content with markdown syntax |
|
41
|
|
|
* @return array |
|
42
|
|
|
* @throws Exception |
|
43
|
|
|
*/ |
|
44
|
2 |
|
public function getForAsset(string $assetKey, ?string $fields = null, ?bool $asMarkdown = null): array |
|
45
|
|
|
{ |
|
46
|
2 |
|
$params = []; |
|
47
|
|
|
|
|
48
|
2 |
|
if (!is_null($fields)) { |
|
49
|
1 |
|
$params['fields'] = $fields; |
|
50
|
|
|
} |
|
51
|
2 |
|
if (!is_null($asMarkdown)) { |
|
52
|
1 |
|
$params['as_markdown'] = $asMarkdown; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
2 |
|
$query = empty($params) ? '' : ('?' . http_build_query($params)); |
|
56
|
2 |
|
$response = $this->client->getBaseClient()->get('/news/' . strtolower($assetKey) . $query); |
|
57
|
|
|
|
|
58
|
2 |
|
return $this->transformer->transform($response); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|