Passed
Pull Request — master (#195)
by
unknown
08:13
created

OrcidDataService::searchPersonRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 2
Metric Value
cc 1
eloc 6
c 3
b 0
f 2
nc 1
nop 1
dl 0
loc 8
rs 10
1
<?php
2
namespace EWW\Dpf\Services\FeUser;
3
4
use \Httpful\Request;
5
6
class OrcidDataService
7
{
8
    protected $apiUrl = 'https://pub.orcid.org/v3.0';
9
10
    protected $params = '&start=0&rows=20';
11
12
    public function __construct() {
13
14
    }
15
16
    public function searchTermReplacement($searchTerm) {
17
        return urlencode($searchTerm);
18
    }
19
20
    public function searchPersonRequest($searchTerm) {
21
        $response = Request::get($this->apiUrl . '/expanded-search/?q=' . $this->searchTermReplacement($searchTerm))
22
            ->expectsJson()
23
            ->addHeader('Accept','*/*')
24
            ->addHeader('Content-Type', 'application/vnd.orcid+json')
25
            ->send();
26
27
        return ['entries' => $response->body->{'expanded-result'}];
28
    }
29
30
    public function getPersonData($orcidId) {
31
        $response = Request::get($this->apiUrl . '/expanded-search/?q=orcid:' . $orcidId)
32
            ->expectsJson()
33
            ->addHeader('Accept','*/*')
34
            ->addHeader('Content-Type', 'application/vnd.orcid+json')
35
            ->send();
36
37
        return $response->body->{'expanded-result'}[0];
38
    }
39
40
}