Completed
Push — master ( ca3689...4c26e4 )
by Francesco
04:20
created

AppnexusFacade::getUploadHistory()   A

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 2
1
<?php
2
3
namespace Audiens\AppnexusClient\facade;
4
5
use Audiens\AppnexusClient\Auth;
6
use Audiens\AppnexusClient\authentication\AdnxStrategy;
7
use Audiens\AppnexusClient\CacheableInterface;
8
use Audiens\AppnexusClient\entity\Segment;
9
use Audiens\AppnexusClient\entity\UploadJobStatus;
10
use Audiens\AppnexusClient\entity\UploadTicket;
11
use Audiens\AppnexusClient\repository\RepositoryResponse;
12
use Audiens\AppnexusClient\repository\SegmentRepository;
13
use Audiens\AppnexusClient\service\UserUpload;
14
use Doctrine\Common\Cache\FilesystemCache;
15
use GuzzleHttp\Client;
16
17
/**
18
 * Class AppnexusFacade
19
 */
20
class AppnexusFacade implements CacheableInterface
21
{
22
23
    protected $username;
24
    protected $password;
25
    protected $memberId;
26
27
    /** @var  SegmentRepository */
28
    private $segmentRepository;
29
30
    /**
31
     * AppnexusFacade constructor.
32
     *
33
     * @param $username
34
     * @param $password
35
     * @param $memberId
36
     */
37
    public function __construct($username, $password, $memberId)
38
    {
39
        $this->username = $username;
40
        $this->password = $password;
41
        $this->memberId = $memberId;
42
43
        $client = new Client();
44
        $cache = new FilesystemCache('build');
45
46
        $authStrategy = new AdnxStrategy($client, $cache);
47
48
        $auth = new Auth($username, $password, $client, $authStrategy);
49
50
        $this->segmentRepository = new SegmentRepository($auth, $cache);
51
        $this->userUpload = new UserUpload($auth, $cache);
0 ignored issues
show
Bug introduced by
The property userUpload does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
52
53
    }
54
55
    /**
56
     * @param Segment $segment
57
     *
58
     * @return RepositoryResponse
59
     * @throws \Exception
60
     */
61
    public function add(Segment $segment)
62
    {
63
64
        return $this->segmentRepository->add($segment);
65
66
    }
67
68
    /**
69
     * @param $id
70
     *
71
     * @return RepositoryResponse
72
     */
73
    public function remove($id)
74
    {
75
76
        return $this->segmentRepository->remove($this->memberId, $id);
77
78
    }
79
80
    /**
81
     * @param Segment $segment
82
     *
83
     * @return RepositoryResponse
84
     * @throws \Exception
85
     */
86
    public function update(Segment $segment)
87
    {
88
        return $this->segmentRepository->update($segment);
89
    }
90
91
    /**
92
     * @param $id
93
     *
94
     * @return Segment|null
95
     */
96
    public function findOneById($id)
97
    {
98
        return $this->segmentRepository->findOneById($this->memberId, $id);
99
    }
100
101
    /**
102
     * @param int $start
103
     * @param int $maxResults
104
     *
105
     * @return array|mixed|null
106
     * @throws \Exception
107
     */
108
    public function findAll($start = 0, $maxResults = 100)
109
    {
110
111
        return $this->segmentRepository->findAll($this->memberId, $start, $maxResults);
112
    }
113
114
    /**
115
     * @param $fileAsString
116
     *
117
     * @return \Audiens\AppnexusClient\entity\UploadJobStatus
118
     * @throws \Exception
119
     */
120
    public function upload($fileAsString)
121
    {
122
        return $this->userUpload->upload($this->memberId, $fileAsString);
123
    }
124
125
    /**
126
     * @param int $start
127
     * @param int $maxResults
128
     *
129
     * @return \Audiens\AppnexusClient\entity\UploadJobStatus[]
130
     * @throws \Audiens\AppnexusClient\exceptions\RepositoryException
131
     */
132
    public function getUploadHistory($start = 0, $maxResults = 100)
133
    {
134
        return $this->userUpload->getUploadHistory($this->memberId, $start, $maxResults);
135
    }
136
137
    /**
138
     * @return \Audiens\AppnexusClient\entity\UploadTicket
139
     * @throws \Exception
140
     */
141
    public function getUploadTicket()
142
    {
143
        return $this->userUpload->getUploadTicket($this->memberId);
144
    }
145
146
    /**
147
     * @param UploadTicket $uploadTicket
148
     *
149
     * @return UploadJobStatus $uploadJobStatus
150
     * @throws \Exception
151
     */
152
    public function getJobStatus(UploadTicket $uploadTicket)
153
    {
154
        return $this->userUpload->getJobStatus($uploadTicket);
155
    }
156
157
    /**
158
     * @return bool
159
     */
160
    public function isCacheEnabled()
161
    {
162
        return $this->segmentRepository->isCacheEnabled() || $this->userUpload->isCacheEnabled();
163
    }
164
165
    public function disableCache()
166
    {
167
        $this->segmentRepository->disableCache();
168
        $this->userUpload->disableCache();
169
    }
170
171
    public function enableCache()
172
    {
173
        $this->segmentRepository->enableCache();
174
        $this->userUpload->enableCache();
175
    }
176
}
177