Passed
Pull Request — master (#213)
by
unknown
33:41 queued 23:20
created

GndDataService::searchKeywordRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
dl 0
loc 5
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
namespace EWW\Dpf\Services\FeUser;
3
4
use \Httpful\Request;
5
6
class GndDataService
7
{
8
9
    protected $apiUrl = 'http://lobid.org/gnd/';
10
11
    public function __construct() {
12
13
    }
14
15
    public function searchTermReplacement($searchTerm) {
16
        $searchTerm = str_replace('ä', 'ae', $searchTerm);
17
        $searchTerm = str_replace('Ä', 'Ae', $searchTerm);
18
        $searchTerm = str_replace('ö', 'oe', $searchTerm);
19
        $searchTerm = str_replace('Ö', 'Oe', $searchTerm);
20
        $searchTerm = str_replace('ü', 'ue', $searchTerm);
21
        $searchTerm = str_replace('Ü', 'Ue', $searchTerm);
22
        return str_replace(' ', '+', $searchTerm);
23
    }
24
25
    public function searchPersonRequest($searchTerm) {
26
        $response = Request::get($this->apiUrl . 'search?filter=type:Person&format=json&q=' . $this->searchTermReplacement($searchTerm))
27
            ->send();
28
29
        return ['entries' => $response->body->member];
30
    }
31
32
    public function getPersonData($gndId) {
33
        $response = Request::get($this->apiUrl . $gndId . '.json')
34
            ->send();
35
36
        return $response->body;
37
    }
38
39
    public function searchOrganisationRequest($searchTerm) {
40
        $response = Request::get($this->apiUrl . 'search?filter=type:CorporateBody&format=json&q=' . $this->searchTermReplacement($searchTerm))
41
            ->send();
42
43
        return ['entries' => $response->body->member];
44
    }
45
46
    public function getOrganisationData($gndId) {
47
        $response = Request::get($this->apiUrl . $gndId . '.json')
48
            ->send();
49
50
        return $response->body;
51
    }
52
53
    public function searchKeywordRequest($searchTerm) {
54
        $response = Request::get($this->apiUrl . 'search?filter=type:SubjectHeading&format=json:suggest&size=100&q=' . $this->searchTermReplacement($searchTerm))
55
            ->send();
56
57
        return $response->body;
58
    }
59
60
}
61