• 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

79.17
/src/WebSocket/ApiResponse.php
1
<?php
2

3
namespace RingCentral\SDK\WebSocket;
4

5
class ApiResponse
6
{
7
    /** @var number */
8
    protected $_status;
9

10
    /** @var array */
11
    protected $_headers = [];
12

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

16
    /** @var string */
17
    protected $_requestId;
18

19
    /** @var WebSocket */
20
    protected $_wsc;
21

22
    public function __construct(array $response, array $body = null)
23
    {
24
        $this->_requestId = $response['messageId'];
12✔
25
        $this->_status = $response['status'];
12✔
26
        $this->_headers = $response['headers'];
12✔
27
        $this->_body = $body ?? [];
12✔
28
        $this->_wsc = $response['wsc'] ?? null;
12✔
29
    }
30

31
    /**
32
     * @return string
33
     */
34
    public function requestId()
35
    {
36
        return $this->_requestId;
6✔
37
    }
38

39
    /**
40
     * @return number
41
     */
42
    public function status()
43
    {
44
        return $this->_status;
3✔
45
    }
46

47
    /**
48
     * @return array
49
     */
50
    public function headers()
51
    {
52
        return $this->_headers;
3✔
53
    }
54

55
    /**
56
     * @return array
57
     */
58
    public function body()
59
    {
60
        return $this->_body;
9✔
61
    }
62

63
     /**
64
     * @return object
65
     */
66
    public function json()
67
    {
68
        return (object) $this->_body;
×
69
    }
70

71
    /**
72
     * @return array
73
     */
74
    public function wsc()
75
    {
76
        return $this->_wsc;
3✔
77
    }
78

79
    public function ok() {
80
        return $this->_status >= 200 && $this->_status < 300;
6✔
81
    }
82

83
    public function error()
84
    {
85
        if (!$this->body()) {
3✔
86
            return null;
×
87
        }
88

89
        if ($this->ok()) {
3✔
90
            return null;
×
91
        }
92

93
        $message = 'Status code ' . $this->status() . '';
3✔
94

95
        if (!empty($this->body()['message'])) {
3✔
96
            $message = $this->body()['message'];
3✔
97
        }
98

99
        if (!empty($this->body()['error_description'])) {
3✔
100
            $message = $this->body()['error_description'];
×
101
        }
102

103
        if (!empty($this->body()['description'])) {
3✔
104
            $message = $this->body()['description'];
×
105
        }
106

107
        return $message;
3✔
108
    }
109
}
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