Completed
Push — master ( 21003f...1e77f8 )
by Sergey
04:08 queued 01:24
created

Artifacts::photos()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace seregazhuk\HeadHunterApi\EndPoints;
4
5
class Artifacts extends Endpoint
6
{
7
    const RESOURCE = 'artifacts';
8
9
    public function photos()
10
    {
11
        return $this->getResource('photo');
12
    }
13
14
    public function portfolio()
15
    {
16
        return $this->getResource('portfolio');
17
    }
18
19
    public function editPhoto($id, $attributes)
20
    {
21
        return $this->putResource($id, $attributes);
22
    }
23
24
    public function deletePhoto($id)
25
    {
26
        $this->deleteResource($id);
27
    }
28
29
    /**
30
     * @param string $file
31
     * @param string $description
32
     * @return array|null
33
     */
34
    public function uploadPhoto($file, $description = '')
35
    {
36
        return $this->upload('photo', $file, $description);
37
    }
38
39
    /**
40
     * @param string $file
41
     * @param string $description
42
     * @return array|null
43
     */
44
    public function uploadPortfolio($file, $description = '')
45
    {
46
        return $this->upload('portfolio', $file, $description);
47
    }
48
49
    /**
50
     * @param string $type
51
     * @param string $description
52
     * @param string $file
53
     * @return array|null
54
     */
55
    public function upload($type, $file, $description = '')
56
    {
57
        $data = [
58
            [
59
                'name' => 'type',
60
                'contents' => $type,
61
            ],
62
            [
63
                'name' => 'description',
64
                'contents' => $description,
65
            ],
66
            [
67
                'name' => 'file',
68
                'contents' => fopen($file, 'r'),
69
            ],
70
        ];
71
72
        return $this->postResourceFile('', $data);
73
    }
74
}