Completed
Push — master ( e41c6a...6a7f08 )
by Saurabh
03:07
created

RequestId::getDetails()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 1
nop 2
dl 0
loc 21
ccs 9
cts 9
cp 1
crap 2
rs 9.3142
c 0
b 0
f 0
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
    public function getDetails(string $requestId, bool $metadata)
19
    {
20
        // make the URL for this request
21 1
        $url = $this->transformUrl(sprintf(
22 1
            '%s/%s?metadata=%s',
23 1
            self::URI,
24
            $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 = $this->transformUrl(sprintf('%s/Completed/%s', self::URI, $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->transformUrl(self::URI);
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)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
94
    {
95
        // make the URL for this request
96 1
        $url = $this->transformUrl(sprintf('%s/Invalidate', self::URI));
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