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

GroupRequest::someFunction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 14
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * Group 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\GroupResponse;
11
12
/**
13
 * Class Group Request
14
 *
15
 * @package Twigger\UnionCloud\API\Groups\Groups
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 GroupRequest extends BaseRequest implements IRequest
23
{
24
    /**
25
     * Group Request constructor.
26
     *
27
     * @param Authentication $authentication
28
     * @param Configuration $configuration
29
     */
30
    public function __construct($authentication, $configuration)
31
    {
32
        parent::__construct($authentication, $configuration, GroupResponse::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 groups from the union
60
     * 
61
     * @return $this|\Twigger\UnionCloud\API\Response\IResponse|\Twigger\UnionCloud\API\ResourceCollection
62
     * 
63
     * @throws \GuzzleHttp\Exception\GuzzleException
64
     * @throws \Twigger\UnionCloud\API\Exception\Request\RequestHistoryNotFound
65
     * @throws \Twigger\UnionCloud\API\Exception\Response\BaseResponseException
66
     */
67
    public function getAll()
68
    {
69
        $this->setAPIParameters(
70
            'groups',
71
            'GET'
72
        );
73
        
74
        $this->enableMode();
75
        $this->enablePagination();
76
        $this->enableTimes();
77
        
78
        $this->call();
79
        
80
        return $this->getReturnDetails();
81
    }
82
83
    /**
84
     * Get a group from UnionCloud
85
     *
86
     * @param integer $groupID ID of the group to get
87
     *
88
     * @return $this|\Twigger\UnionCloud\API\Response\IResponse|\Twigger\UnionCloud\API\ResourceCollection
89
     *
90
     * @throws \GuzzleHttp\Exception\GuzzleException
91
     * @throws \Twigger\UnionCloud\API\Exception\Request\RequestHistoryNotFound
92
     * @throws \Twigger\UnionCloud\API\Exception\Response\BaseResponseException
93
     */
94
    public function getByID($groupID)
95
    {
96
        $this->setAPIParameters(
97
            'groups/'.$groupID,
98
            'GET'
99
        );
100
101
        $this->enableMode();
102
103
        $this->call();
104
105
        return $this->getReturnDetails();
106
    }
107
108
    /**
109
     * Join a Group on UnionCloud
110
     *
111
     * @param integer $groupID ID of the group to join
112
     * @param integer $uid UID of the User joining the group
113
     * @param integer $group_membership_id ID of the group membership for the user
114
     *
115
     * @return $this|\Twigger\UnionCloud\API\Response\IResponse|\Twigger\UnionCloud\API\ResourceCollection
116
     *
117
     * @throws \GuzzleHttp\Exception\GuzzleException
118
     * @throws \Twigger\UnionCloud\API\Exception\Request\RequestHistoryNotFound
119
     * @throws \Twigger\UnionCloud\API\Exception\Response\BaseResponseException
120
     */
121
    public function join($groupID, $uid, $group_membership_id)
122
    {
123
        $this->setAPIParameters(
124
            'groups/'.$groupID.'/join',
125
            'POST',
126
            [
127
                'uid' => $uid,
128
                'membership_type_id' => $group_membership_id
129
            ]
130
        );
131
132
        $this->call();
133
134
        return $this->getReturnDetails();
135
    }
136
137
}