• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ringcentral / ringcentral-php / 5130932145

pending completion
5130932145

push

github

web-flow
feat: websocket subscription support (#122)

* feat: support websocket subscription

* chore: update webhook demo

* misc: use Exception

* chore: update phpunit.xml

* fix: syntax error at php 7.4

* misc: refactor and add tests for websocket

* chore: require react/async at dev

* chore: add tests for ws subscription

* chore: add more tests

* chore: add more tests

216 of 216 new or added lines in 11 files covered. (100.0%)

664 of 732 relevant lines covered (90.71%)

30.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.67
/src/WebSocket/ApiRequest.php
1
<?php
2

3
namespace RingCentral\SDK\WebSocket;
4

5
class ApiRequest
6
{
7
    /** @var string */
8
    protected $_method;
9

10
    /** @var string */
11
    protected $_path;
12

13
    /** @var array */
14
    protected $_query = [];
15

16
    /** @var array */
17
    protected $_headers = [];
18

19
    /** @var array */
20
    protected $_body = [];
21

22
    /** @var string */
23
    protected $_requestId;
24

25
    /**
26
     * ApiRequest constructor.
27
     *
28
     * @param string $method
29
     * @param string $path
30
     * @param array  $query
31
     * @param array  $headers
32
     * @param array  $body
33
     */
34
    public function __construct(array $options = [])
35
    {
36
        $this->_requestId = uniqid();
6✔
37
        $this->_method = $options['method'] ?? 'GET';
6✔
38
        $this->_path = $options['path'];
6✔
39
        $this->_query = $options['query'] ?? [];
6✔
40
        $this->_headers = $options['headers'] ?? [];
6✔
41
        $this->_body = $options['body'] ?? [];
6✔
42
    }
43

44
    /**
45
     * @return string
46
     */
47
    public function method()
48
    {
49
        return $this->_method;
6✔
50
    }
51

52
    /**
53
     * @return string
54
     */
55
    public function path()
56
    {
57
        return $this->_path;
6✔
58
    }
59

60
    /**
61
     * @return array
62
     */
63
    public function query()
64
    {
65
        return $this->_query;
6✔
66
    }
67

68
    /**
69
     * @return array
70
     */
71
    public function headers()
72
    {
73
        return $this->_headers;
×
74
    }
75

76
    /**
77
     * @return array
78
     */
79
    public function body()
80
    {
81
        return $this->_body;
6✔
82
    }
83

84
    public function requestId()
85
    {
86
        return $this->_requestId;
6✔
87
    }
88

89
    public function toJson() {
90
        $request = [
6✔
91
            'type' => 'ClientRequest',
6✔
92
            'messageId' => $this->requestId(),
6✔
93
            'method' => $this->method(),
6✔
94
            'path' => $this->path(),
6✔
95
        ];
6✔
96
        if (!empty($this->query())) {
6✔
97
            $request['query'] = $this->query();
×
98
        }
99
        $requestData = array($request);
6✔
100
        if (!empty($this->body())) {
6✔
101
            array_push($requestData, $this->body());
6✔
102
        }
103
        return json_encode($requestData);
6✔
104
    }
105
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc