Completed
Push — master ( 35f9c1...7f1afc )
by Xavier
01:04
created

IdConverter::getRequestOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
namespace PubPeerFoundation\PublicationDataExtractor\Resources;
4
5
use SimpleXMLElement;
6
use PubPeerFoundation\PublicationDataExtractor\Identifiers\Identifier;
7
8
class IdConverter implements Resource
9
{
10
    protected $url = 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi';
11
12
    protected $queryStringParameters = [
13
        'query' => [
14
            'format' => 'json',
15
            'tool' => 'pubpeer',
16
            'email' => '[email protected]',
17
            'version' => 'no',
18
            'ids' => ''
19
        ],
20
    ];
21
22
    protected $input;
23
24
    protected $identifier;
25
26
    public function __construct(Identifier $identifier)
27
    {
28
        $this->queryStringParameters['query']['ids'] = $identifier->getQueryString();
29
    }
30
31
    /**
32
     * @return string
33
     */
34
    public function getApiUrl(): string
35
    {
36
        return $this->url;
37
    }
38
39
    /**
40
     * @return array
41
     */
42
    public function getRequestOptions(): array
43
    {
44
        return $this->queryStringParameters;
45
    }
46
47
    /**
48
     * @param string $document
49
     *
50
     * @return array
51
     */
52
    public function getDataFrom(string $document): array
53
    {
54
        try {
55
            $baseTree = json_decode($document, true);
56
            $extractor = new Extractors\IdConverter($baseTree);
57
58
            return $extractor->extract();
59
        } catch (\Exception $e) {
60
            return [];
61
        }
62
    }
63
}
64