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

OrcidDataService   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 2
Metric Value
eloc 16
c 4
b 0
f 2
dl 0
loc 32
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A searchPersonRequest() 0 8 1
A searchTermReplacement() 0 2 1
A __construct() 0 1 1
A getPersonData() 0 8 1
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
}