|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sausin\Signere; |
|
4
|
|
|
|
|
5
|
|
|
use BadMethodCallException; |
|
6
|
|
|
|
|
7
|
|
|
class DocumentJob extends BaseClass |
|
8
|
|
|
{ |
|
9
|
|
|
/** The URI of the action */ |
|
10
|
|
|
const URI = 'https://api.signere.no/api/DocumentJob'; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Retrieves a document job in the form of a response |
|
14
|
|
|
* object containing the document job parameters. |
|
15
|
|
|
* |
|
16
|
|
|
* @param string $jobId |
|
17
|
|
|
* @return object |
|
18
|
|
|
*/ |
|
19
|
1 |
|
public function get(string $jobId) |
|
20
|
|
|
{ |
|
21
|
|
|
// make the URL for this request |
|
22
|
1 |
|
$url = $this->transformUrl(sprintf('%s/%s', self::URI, $jobId)); |
|
23
|
|
|
|
|
24
|
|
|
// get the headers for this request |
|
25
|
1 |
|
$headers = $this->headers->make('GET', $url); |
|
26
|
|
|
|
|
27
|
|
|
// get the response |
|
28
|
1 |
|
$response = $this->client->get($url, [ |
|
29
|
1 |
|
'headers' => $headers, |
|
30
|
|
|
]); |
|
31
|
|
|
|
|
32
|
|
|
// return the response |
|
33
|
1 |
|
return $response; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Creates a document job. |
|
38
|
|
|
* |
|
39
|
|
|
* @param array $body |
|
40
|
|
|
* @return object |
|
41
|
|
|
*/ |
|
42
|
1 |
|
public function create(array $body) |
|
43
|
|
|
{ |
|
44
|
|
|
// keys that are mandatory for this request |
|
45
|
1 |
|
$needKeys = ['Contact_Email', 'Contact_Phone']; |
|
46
|
|
|
|
|
47
|
|
|
// if the body doesn't have needed fields, throw an exception |
|
48
|
1 |
|
if (! array_has_all_keys($body, $needKeys)) { |
|
49
|
1 |
|
throw new BadMethodCallException( |
|
50
|
1 |
|
'Missing fields in input array. Need '.implode(', ', $needKeys) |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
// make the URL for this request |
|
55
|
1 |
|
$url = $this->transformUrl(self::URI); |
|
56
|
|
|
|
|
57
|
|
|
// get the headers for this request |
|
58
|
1 |
|
$headers = $this->headers->make('POST', $url, $body); |
|
59
|
|
|
|
|
60
|
|
|
// get the response |
|
61
|
1 |
|
$response = $this->client->post($url, [ |
|
62
|
1 |
|
'headers' => $headers, |
|
63
|
1 |
|
'json' => $body, |
|
64
|
|
|
]); |
|
65
|
|
|
|
|
66
|
|
|
// return the response |
|
67
|
1 |
|
return $response; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|