1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sausin\Signere; |
4
|
|
|
|
5
|
|
|
class RequestId extends BaseClass |
6
|
|
|
{ |
7
|
|
|
/** The URI of the action */ |
8
|
|
|
const URI = 'https://api.signere.no/api/SignereId'; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Retrives a SignereID session to get the |
12
|
|
|
* information about the authorized user. |
13
|
|
|
* |
14
|
|
|
* @param string $requestId |
15
|
|
|
* @param bool $metadata |
16
|
|
|
* @return object |
17
|
|
|
*/ |
18
|
1 |
View Code Duplication |
public function getDetails(string $requestId, bool $metadata) |
|
|
|
|
19
|
|
|
{ |
20
|
|
|
// make the URL for this request |
21
|
1 |
|
$url = sprintf( |
22
|
1 |
|
'%s/%s?metadata=%s', |
23
|
1 |
|
$this->getBaseUrl(), |
24
|
1 |
|
$requestId, |
25
|
1 |
|
$metadata ? 'true' : 'false' |
26
|
|
|
); |
27
|
|
|
|
28
|
|
|
// get the headers for this request |
29
|
1 |
|
$headers = $this->headers->make('GET', $url); |
30
|
|
|
|
31
|
|
|
// get the response |
32
|
1 |
|
$response = $this->client->get($url, [ |
33
|
1 |
|
'headers' => $headers, |
34
|
|
|
]); |
35
|
|
|
|
36
|
|
|
// return the response |
37
|
1 |
|
return $response; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Check if a SignereID session is completed or not. |
42
|
|
|
* |
43
|
|
|
* @param string $requestId |
44
|
|
|
* @return object |
45
|
|
|
*/ |
46
|
1 |
|
public function check(string $requestId) |
47
|
|
|
{ |
48
|
|
|
// make the URL for this request |
49
|
1 |
|
$url = sprintf('%s/Completed/%s', $this->getBaseUrl(), $requestId); |
50
|
|
|
|
51
|
|
|
// get the headers for this request |
52
|
1 |
|
$headers = $this->headers->make('GET', $url); |
53
|
|
|
|
54
|
|
|
// get the response |
55
|
1 |
|
$response = $this->client->get($url, [ |
56
|
1 |
|
'headers' => $headers, |
57
|
|
|
]); |
58
|
|
|
|
59
|
|
|
// return the response |
60
|
1 |
|
return $response; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Creates a SignereID request, and returns a url. |
65
|
|
|
* |
66
|
|
|
* @param array $body |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
1 |
|
public function create(array $body) |
70
|
|
|
{ |
71
|
|
|
// make the URL for this request |
72
|
1 |
|
$url = $this->getBaseUrl(); |
73
|
|
|
|
74
|
|
|
// get the headers for this request |
75
|
1 |
|
$headers = $this->headers->make('POST', $url, $body); |
76
|
|
|
|
77
|
|
|
// get the response |
78
|
1 |
|
$response = $this->client->post($url, [ |
79
|
1 |
|
'headers' => $headers, |
80
|
1 |
|
'json' => $body, |
81
|
|
|
]); |
82
|
|
|
|
83
|
|
|
// return the response |
84
|
1 |
|
return $response; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Invalidates a SignereID request. |
89
|
|
|
* |
90
|
|
|
* @param string $requestId |
91
|
|
|
* @return object |
92
|
|
|
*/ |
93
|
1 |
View Code Duplication |
public function invalidate(string $requestId) |
|
|
|
|
94
|
|
|
{ |
95
|
|
|
// make the URL for this request |
96
|
1 |
|
$url = sprintf('%s/Invalidate', $this->getBaseUrl()); |
97
|
|
|
|
98
|
1 |
|
$body = ['RequestId' => $requestId]; |
99
|
|
|
|
100
|
|
|
// get the headers for this request |
101
|
1 |
|
$headers = $this->headers->make('PUT', $url, $body); |
102
|
|
|
|
103
|
|
|
// get the response |
104
|
1 |
|
$response = $this->client->put($url, [ |
105
|
1 |
|
'headers' => $headers, |
106
|
1 |
|
'json' => $body, |
107
|
|
|
]); |
108
|
|
|
|
109
|
|
|
// return the response |
110
|
1 |
|
return $response; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.