Skip to content

Commit 5d82a2c

Browse files
author
James Taylor
committed
GET method should be fun and work now
1 parent 6c7c413 commit 5d82a2c

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

src/PleskX/Api/Operator/Forwards.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace PleskX\Api\Struct\Mail;
4+
5+
use PleskX\Api\XmlResponse;
6+
7+
class Forwards extends \PleskX\Api\Struct
8+
{
9+
/** @var integer */
10+
public $id;
11+
12+
/** @var string */
13+
public $name;
14+
15+
/** @var string */
16+
public $address;
17+
18+
/**
19+
* @param XmlResponse $apiResponse
20+
* @throws \Exception
21+
*/
22+
public function __construct(XMLResponse $apiResponse)
23+
{
24+
$line = new \stdClass();
25+
$line->id = $apiResponse->id;
26+
$line->name = $apiResponse->name;
27+
$line->address = $apiResponse->forwarding->address;
28+
29+
$this->_initScalarProperties($line, [
30+
'id',
31+
'name',
32+
'address',
33+
]);
34+
}
35+
}

src/PleskX/Api/Operator/Mail.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Copyright 1999-2016. Parallels IP Holdings GmbH.
33

44
namespace PleskX\Api\Operator;
5+
use PleskX\Api\Client;
56
use PleskX\Api\Struct\Mail as Struct;
67

78
class Mail extends \PleskX\Api\Operator
@@ -33,19 +34,24 @@ public function create(string $name, int $siteId, string $forwardAddress): Struc
3334

3435
/**
3536
* @param int $siteId
36-
* @return \PleskX\Api\XmlResponse
37+
* @return array
3738
*/
38-
public function get(int $siteId)
39+
public function get(int $siteId): array
3940
{
4041
$packet = $this->_client->getPacket();
4142
$info = $packet->addChild($this->_wrapperTag)->addChild('get_info');
4243
$filter = $info->addChild('filter');
43-
$filter->addChild('site_id', $siteId);
44-
$filter->addChild('forwarding', 'true');
44+
$filter->addChild('site-id', $siteId);
45+
$info->addChild('forwarding');
4546

46-
$response = $this->_client->request($packet);
47+
$response = $this->_client->request($packet, Client::RESPONSE_FULL);
48+
49+
$forwards = [];
50+
foreach ($response->mail->get_info->result as $forwardInfo) {
51+
$forwards[] = new Struct\Forwards($forwardInfo->mailname);
52+
}
4753

48-
return $response;
54+
return $forwards;
4955
}
5056

5157
/**

0 commit comments

Comments
 (0)