RichContentService   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 69
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A uploadFile() 0 5 1
A refreshUrl() 0 4 1
A requestUpload() 0 12 1
A sendUpload() 0 5 1
1
<?php
2
3
namespace Aosmak\Laravel\Layer\Sdk\Services\Subservices;
4
5
use Aosmak\Laravel\Layer\Sdk\Models\ResponseInterface;
6
use Aosmak\Laravel\Layer\Sdk\Services\Subservices\Interfaces\RichContentServiceInterface;
7
8
/**
9
 * Class RichContentService
10
 * @package namespace Aosmak\Laravel\Layer\Sdk\Services\Subservices
11
 */
12
class RichContentService extends BaseService implements RichContentServiceInterface
13
{
14
    /**
15
     * Request rich content upload
16
     *
17
     * @param string $conversationId conversation ID
18
     * @param string $url file URL
19
     *
20
     * @return \Aosmak\Laravel\Layer\Sdk\Models\Response
21
     */
22 2
    public function requestUpload(string $conversationId, string $path): ?ResponseInterface
23
    {
24 2
        $headers            = [];
25 2
        $headers['headers'] = [
26 2
            'Upload-Content-Type'   => mime_content_type($path),
27
            'Upload-Content-Length' => filesize($path) + 161,
28
        ];
29 2
30 2
        return $this->getRequestService()->makePostRequest(
31 2
            $this->getRouter()->getShortUrl('conversations', $conversationId, 'content'),
32 2
            [],
33
            $headers
34
        );
35
    }
36
37
    /**
38
     * Upload a file
39
     *
40
     * @param string $uploadUrl upload URL
41
     * @param string $url file URL
42
     *
43
     * @return \Aosmak\Laravel\Layer\Sdk\Models\ResponseInterface
44 2
     */
45
    public function uploadFile(string $uploadUrl, string $path): ?ResponseInterface
46 2
    {
47 2
        return $this->getRequestService()->uploadFile(
48 2
            $uploadUrl,
49
            $path
50
        );
51
    }
52
53
    /**
54
     * Send message that contains rich content
55
     *
56
     * @param string $conversationId conversation ID
57
     * @param string $data data
58
     *
59
     * @return \Aosmak\Laravel\Layer\Sdk\Models\ResponseInterface
60 2
     */
61
    public function sendUpload(string $conversationId, array $data): ResponseInterface
62 2
    {
63 2
        return $this->getRequestService()->makePostRequest(
64 2
            $this->getRouter()->getShortUrl('conversations', $conversationId, 'messages'),
65
            $data
66
        );
67
    }
68
69
    /**
70
     * Refresh URL
71
     *
72
     * @param string $conversationId conversation ID
73
     * @param string $contentId content item ID
74
     *
75
     * @return \Aosmak\Laravel\Layer\Sdk\Models\ResponseInterface
76 2
     */
77
    public function refreshUrl(string $conversationId, string $contentId): ResponseInterface
78 2
    {
79 2
        return $this->getRequestService()->makeGetRequest(
80
            $this->getRouter()->getContentUrl($conversationId, $contentId)
81
        );
82
    }
83
}
84