Passed
Branch api-functionality (902732)
by Toby
04:47
created

EventTicketRequest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 16
dl 0
loc 87
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getInstance() 0 3 1
A redeem() 0 13 1
A getByUser() 0 13 1
1
<?php
2
/**
3
 * Event Ticket Request class
4
 */
5
namespace Twigger\UnionCloud\API\Request;
6
7
8
use Twigger\UnionCloud\API\Auth\Authentication;
9
use Twigger\UnionCloud\API\Configuration;
10
use Twigger\UnionCloud\API\Response\EventTicketResponse;
11
12
/**
13
 * Class Event Ticket Request
14
 *
15
 * @package Twigger\UnionCloud\API\Events\EventTicketTypes
16
 *
17
 * @license    https://opensource.org/licenses/GPL-3.0  GNU Public License v3
18
 *
19
 * @author     Toby Twigger <[email protected]>
20
 *
21
 */
22
class EventTicketRequest extends BaseRequest implements IRequest
23
{
24
    /**
25
     * Event Ticket Request constructor.
26
     *
27
     * @param Authentication $authentication
28
     * @param Configuration $configuration
29
     */
30
    public function __construct($authentication, $configuration)
31
    {
32
        parent::__construct($authentication, $configuration, EventTicketResponse::class);
33
    }
34
35
36
    /**
37
     * Gets the current instance
38
     *
39
     * @return $this
40
     *
41
     */
42
    public function getInstance()
43
    {
44
        return $this;
45
    }
46
47
48
49
    /*
50
    |--------------------------------------------------------------------------
51
    | API Endpoint Definitions
52
    |--------------------------------------------------------------------------
53
    |
54
    | Define your API endpoints below here
55
    |
56
    */
57
58
    /**
59
     * Get all event tickets belonging to a user
60
     *
61
     * @param int $uid User ID of the user
62
     *
63
     * @return $this|\Twigger\UnionCloud\API\Response\IResponse|\Twigger\UnionCloud\API\ResourceCollection
64
     *
65
     * @throws \GuzzleHttp\Exception\GuzzleException
66
     * @throws \Twigger\UnionCloud\API\Exception\Request\RequestHistoryNotFound
67
     * @throws \Twigger\UnionCloud\API\Exception\Response\BaseResponseException
68
     */
69
    public function getByUser($uid)
70
    {
71
        $this->setAPIParameters(
72
            'users/'.$uid.'/tickets',
73
            'GET'
74
        );
75
76
        $this->enableMode();
77
        $this->enablePagination();
78
79
        $this->call();
80
81
        return $this->getReturnDetails();
82
    }
83
84
    /**
85
     * Redeem a ticket from a user
86
     *
87
     * @param int $eventID ID of the event
88
     * @param string $ticketNo Ticket number
89
     *
90
     * @return $this|\Twigger\UnionCloud\API\Response\IResponse|\Twigger\UnionCloud\API\ResourceCollection
91
     *
92
     * @throws \GuzzleHttp\Exception\GuzzleException
93
     * @throws \Twigger\UnionCloud\API\Exception\Request\RequestHistoryNotFound
94
     * @throws \Twigger\UnionCloud\API\Exception\Response\BaseResponseException
95
     */
96
    public function redeem($eventID, $ticketNo)
97
    {
98
        $this->setAPIParameters(
99
            'events/'.$eventID.'/ticket_redemption',
100
            'POST',
101
            [
102
                'ticket_number' => $ticketNo
103
            ]
104
        );
105
106
        $this->call();
107
108
        return $this->getReturnDetails();
109
    }
110
}