Completed
Push — feature/self-service-verified-... ( 3ac932...0d092e )
by Michiel
07:47
created

SecondFactorService::searchVetted()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * Copyright 2014 SURFnet bv
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace Surfnet\StepupMiddlewareClient\Identity\Service;
20
21
use Surfnet\StepupMiddlewareClient\Exception\AccessDeniedToResourceException;
22
use Surfnet\StepupMiddlewareClient\Exception\MalformedResponseException;
23
use Surfnet\StepupMiddlewareClient\Exception\ResourceReadException;
24
use Surfnet\StepupMiddlewareClient\Identity\Dto\UnverifiedSecondFactorSearchQuery;
25
use Surfnet\StepupMiddlewareClient\Identity\Dto\VerifiedSecondFactorSearchQuery;
26
use Surfnet\StepupMiddlewareClient\Identity\Dto\VettedSecondFactorSearchQuery;
27
use Surfnet\StepupMiddlewareClient\Service\ApiService;
28
29
/**
30
 * Provides remote read access to the Middleware's second factors.
31
 */
32
class SecondFactorService
33
{
34
    /**
35
     * @var ApiService
36
     */
37
    private $apiService;
38
39
    /**
40
     * @param ApiService $apiService
41
     */
42
    public function __construct(ApiService $apiService)
43
    {
44
        $this->apiService = $apiService;
45
    }
46
47
    /**
48
     * @param string $secondFactorId
49
     * @return null|array
50
     * @throws AccessDeniedToResourceException When the consumer isn't authorised to access given resource.
51
     * @throws ResourceReadException When the server doesn't respond with the resource.
52
     * @throws MalformedResponseException When the server doesn't respond with (well-formed) JSON.
53
     */
54
    public function getUnverified($secondFactorId)
55
    {
56
        return $this->apiService->read('unverified-second-factor/%s', [$secondFactorId]);
57
    }
58
59
    /**
60
     * @param string $secondFactorId
61
     * @return null|array
62
     * @throws AccessDeniedToResourceException When the consumer isn't authorised to access given resource.
63
     * @throws ResourceReadException When the server doesn't respond with the resource.
64
     * @throws MalformedResponseException When the server doesn't respond with (well-formed) JSON.
65
     */
66
    public function getVerified($secondFactorId)
67
    {
68
        return $this->apiService->read('verified-second-factor/%s', [$secondFactorId]);
69
    }
70
71
    /**
72
     * @param string $secondFactorId
73
     * @return null|array
74
     * @throws AccessDeniedToResourceException When the consumer isn't authorised to access given resource.
75
     * @throws ResourceReadException When the server doesn't respond with the resource.
76
     * @throws MalformedResponseException When the server doesn't respond with (well-formed) JSON.
77
     */
78
    public function getVetted($secondFactorId)
79
    {
80
        return $this->apiService->read('vetted-second-factor/%s', [$secondFactorId]);
81
    }
82
83
    /**
84
     * @param UnverifiedSecondFactorSearchQuery $query
85
     * @return null|array
86
     * @throws AccessDeniedToResourceException When the consumer isn't authorised to access given resource.
87
     * @throws ResourceReadException When the server doesn't respond with the resource.
88
     * @throws MalformedResponseException When the server doesn't respond with (well-formed) JSON.
89
     */
90
    public function searchUnverified(UnverifiedSecondFactorSearchQuery $query)
91
    {
92
        return $this->apiService->read('unverified-second-factors' . $query->toHttpQuery());
93
    }
94
95
    /**
96
     * @param VerifiedSecondFactorSearchQuery $query
97
     * @return null|array
98
     * @throws AccessDeniedToResourceException When the consumer isn't authorised to access given resource.
99
     * @throws ResourceReadException When the server doesn't respond with the resource.
100
     * @throws MalformedResponseException When the server doesn't respond with (well-formed) JSON.
101
     */
102
    public function searchVerified(VerifiedSecondFactorSearchQuery $query)
103
    {
104
        return $this->apiService->read('verified-second-factors' . $query->toHttpQuery());
105
    }
106
107
    /**
108
     * @param VerifiedSecondFactorSearchQuery $query
109
     * @return null|array
110
     * @throws AccessDeniedToResourceException When the consumer isn't authorised to access given resource.
111
     * @throws ResourceReadException When the server doesn't respond with the resource.
112
     * @throws MalformedResponseException When the server doesn't respond with (well-formed) JSON.
113
     */
114
    public function searchOwnVerified(VerifiedSecondFactorSearchQuery $query)
115
    {
116
        return $this->apiService->read('self-service-verified-second-factors' . $query->toHttpQuery());
117
    }
118
119
    /**
120
     * @param VettedSecondFactorSearchQuery $query
121
     * @return null|array
122
     * @throws AccessDeniedToResourceException When the consumer isn't authorised to access given resource.
123
     * @throws ResourceReadException When the server doesn't respond with the resource.
124
     * @throws MalformedResponseException When the server doesn't respond with (well-formed) JSON.
125
     */
126
    public function searchVetted(VettedSecondFactorSearchQuery $query)
127
    {
128
        return $this->apiService->read('vetted-second-factors' . $query->toHttpQuery());
129
    }
130
}
131