Completed
Push — master ( fbdd5a...4063fa )
by Mike
04:02
created

ClassroomApi::createPermaClas()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
ccs 8
cts 8
cp 1
rs 9.4286
cc 1
eloc 8
nc 1
nop 1
crap 1
1
<?php
2
namespace mikemix\Wiziq\API;
3
4
use mikemix\Wiziq\API\Request;
5
use mikemix\Wiziq\Common\Api\ClassroomApiInterface;
6
use mikemix\Wiziq\Entity\Classroom;
7
use mikemix\Wiziq\Entity\PermaClassroom;
8
9
class ClassroomApi implements ClassroomApiInterface
10
{
11
    /** @var Gateway */
12
    protected $gateway;
13
14 3
    public function __construct(Gateway $requester)
15
    {
16 3
        $this->gateway = $requester;
17 3
    }
18
19
    /**
20
     * {@inheritdoc}
21
     */
22 1
    public function create(Classroom $classroom)
23
    {
24 1
        $response = $this->gateway->sendRequest(new Request\Create($classroom));
25
26
        return [
27 1
            'class_id'      => (int)$response->create[0]->class_details[0]->class_id,
28 1
            'recording_url' => (string)$response->create[0]->class_details[0]->recording_url,
29 1
            'presenters'    => $this->getPresentersFromResponse($response)
30 1
        ];
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 1
    public function createPermaClas(PermaClassroom $classroom)
37
    {
38 1
        $response = $this->gateway->sendRequest(new Request\CreatePermaClass($classroom));
39 1
        $details  = $response->create_perma_class[0]->perma_class_details[0];
40
41
        return [
42 1
            'class_id'        => (int)$details->class_master_id,
43 1
            'attendee_url'    => (string)$details->common_perma_attendee_url,
44 1
            'presenter_email' => (string)$details->presenter[0]->presenter_email,
45 1
            'presenter_url'   => (string)$details->presenter[0]->presenter_url,
46 1
        ];
47
    }
48
49
    /**
50
     * @param \SimpleXMLElement $response
51
     * @return array
52
     */
53 1
    protected function getPresentersFromResponse(\SimpleXMLElement $response)
54
    {
55 1
        $presenters = [];
56 1
        foreach ($response->create[0]->class_details[0]->presenter_list[0] as $presenter) {
57 1
            $presenters[] = [
58 1
                'email' => (string)$presenter->presenter_email,
59 1
                'url'   => (string)$presenter->presenter_url,
60
            ];
61 1
        }
62
63 1
        return $presenters;
64
    }
65
}
66