Test Setup Failed
Push — 0.1-dev ( 06ac17...3ceb1a )
by Petr
02:03
created

YourMembershipClient::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 3
1
<?php
2
3
namespace P2A\YourMembership;
4
5
use GuzzleHttp\Client;
6
use P2A\YourMembership\Core\Request;
7
use P2A\YourMembership\Core\Response;
8
9
class YourMembershipClient
10
{
11
12
    /**
13
     * Guzzle Client
14
     * @var \GuzzleHttp\Client
15
     */
16
    private $client;
17
    /**
18
     * YourMembership Request
19
     * @var Request
20
     */
21
    private $request;
22
23
    public function __construct(Client $client, string $apiKey, string $saPasscode)
24
    {
25
        $this->client = $client;
26
        $this->request = new Request($apiKey, $saPasscode);
27
        $sessionID = $this->createSession();
28
        Request::setSessionID($sessionID);
29
30
    }
31
    /**
32
     * Makes API Call to YourMembership
33
     * @method makeCall
34
     * @author PA
35
     * @date   2017-01-10
36
     * @param  string     $method    Your Membership API Method
37
     * @param  array      $arguments  Your Membership API Call Arguments
38
     * @return Response
39
     */
40
    public function makeCall(string $method, array $arguments = [])
41
    {
42
43
        Request::$callId++; //Update the Call ID as they need to be unique per call
44
        $request = $this->request->buildRequest($method, $arguments);
45
46
        $response = $this->client->send($request);
47
48
        return new Response($method, $response);
49
    }
50
51
    /**
52
     * Creates a new Session with YourMembership
53
     * @method createSession
54
     * @author PA
55
     * @date   2017-01-10
56
     * @return string        SessionID
57
     */
58
    private function createSession() : string
59
    {
60
        $response = $this->makeCall('Session.Create')->toObject();
61
        return $response->SessionID;
62
63
    }
64
65
}
66