Completed
Push — master ( 8ae406...7a819f )
by Mārtiņš
01:47
created

Inktale::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 2
eloc 2
nc 2
nop 1
1
<?php
2
3
4
namespace Inktale\Api;
5
6
7
use Inktale\Api\Exceptions\InktaleApiException;
8
use Inktale\Api\Structures\ProductItem;
9
use Inktale\Api\Structures\StoreItem;
10
11
class Inktale
12
{
13
    /** @var InktaleApiClient */
14
    private $api;
15
16
    /**
17
     * @param InktaleApiClient|null $apiClient
18
     */
19
    public function __construct(InktaleApiClient $apiClient = null)
20
    {
21
        $this->api = $apiClient ?: new InktaleApiClient;
22
    }
23
24
    /**
25
     * Set api key to be used for next requests
26
     *
27
     * @param string|null $apiKey
28
     */
29
    public function setApiKey($apiKey)
30
    {
31
        $this->api->setApiKey($apiKey);
32
    }
33
34
    /**
35
     * Create a new store and retrieve the api key. This request does not require an api key to be set
36
     *
37
     * @param string $email
38
     * @param string $name
39
     *
40
     * @return StoreItem
41
     * @throws InktaleApiException
42
     */
43
    public function createStore($email, $name)
44
    {
45
        $response = $this->api->post('store', [
46
            'email' => $email,
47
            'name' => $name,
48
        ]);
49
50
        return StoreItem::fromArray($response['store']);
51
    }
52
53
    /**
54
     * Fetch list of available products that artwork can be created on
55
     *
56
     * @return ProductItem[]
57
     * @throws InktaleApiException
58
     */
59
    public function getProducts()
60
    {
61
        $response = $this->api->get('products');
62
63
        $re = [];
64
        foreach ($response['products'] as $v) {
65
            $re[] = ProductItem::fromArray($v);
66
        }
67
68
        return $re;
69
    }
70
}