Streak::threads()   A
last analyzed

Complexity

Conditions 1
Paths 1

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 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Streak;
4
5
use GuzzleHttp\Client as GuzzleClient;
6
use Streak\Endpoint\User;
7
use Streak\Endpoint\Pipeline;
8
use Streak\Endpoint\Box;
9
use Streak\Endpoint\Stage;
10
use Streak\Endpoint\Field;
11
use Streak\Endpoint\Task;
12
use Streak\Endpoint\File;
13
use Streak\Endpoint\Thread;
14
use Streak\Endpoint\Comment;
15
use Streak\Endpoint\Snippet;
16
use Streak\Endpoint\Search;
17
use Streak\Endpoint\Newsfeed;
18
use GuzzleHttp\ClientInterface;
19
20
class Streak
21
{
22
    const BASE_URL = 'https://www.streak.com/api/v1/';
23
24
    protected $client;
25
26
    /**
27
     * Construct the Streak client
28
     * The config only allows a 'handler' parameter to pass a custom handler
29
     *
30
     * @param string $apiKey required api key
31
     * @param array  $config config
32
     */
33
    public function __construct($apiKey, array $config = [])
34
    {
35
        if (isset($config['handler'])) {
36
            if ($config['handler'] instanceof ClientInterface) {
37
                $handler = $config['handler'];
38
            } else {
39
                throw new \InvalidArgumentException('The handler should be an instance of "GuzzleHttp\ClientInterface".');
40
            }
41
        } else {
42
            $handler = new GuzzleClient([
43
                'base_uri' => self::BASE_URL,
44
                'auth'     => [$apiKey, ''],
45
            ]);
46
        }
47
48
        $this->client = new Client($handler);
49
    }
50
51
    public function users()
52
    {
53
        return new User($this->client);
54
    }
55
56
    public function pipelines()
57
    {
58
        return new Pipeline($this->client);
59
    }
60
61
    public function boxes()
62
    {
63
        return new Box($this->client);
64
    }
65
66
    public function stages($pipelineKey)
67
    {
68
        return new Stage($this->client, $pipelineKey);
69
    }
70
71
    public function fields($pipelineKey)
72
    {
73
        return new Field($this->client, $pipelineKey);
74
    }
75
76
    public function tasks()
77
    {
78
        return new Task($this->client);
79
    }
80
81
    public function files()
82
    {
83
        return new File($this->client);
84
    }
85
86
    public function threads()
87
    {
88
        return new Thread($this->client);
89
    }
90
91
    public function comments()
92
    {
93
        return new Comment($this->client);
94
    }
95
96
    public function snippets()
97
    {
98
        return new Snippet($this->client);
99
    }
100
101
    public function search()
102
    {
103
        return new Search($this->client);
104
    }
105
106
    public function newsfeed()
107
    {
108
        return new Newsfeed($this->client);
109
    }
110
}
111