playwright-ruby-client 1.17.beta1 → 1.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/documentation/docs/api/api_request.md +7 -0
- data/documentation/docs/api/api_request_context.md +161 -0
- data/documentation/docs/api/api_response.md +104 -0
- data/documentation/docs/api/browser_context.md +4 -0
- data/documentation/docs/api/download.md +1 -3
- data/documentation/docs/api/frame.md +1 -1
- data/documentation/docs/api/frame_locator.md +10 -1
- data/documentation/docs/api/locator.md +19 -47
- data/documentation/docs/api/page.md +5 -1
- data/documentation/docs/include/api_coverage.md +35 -13
- data/lib/playwright/api_response_impl.rb +73 -0
- data/lib/playwright/channel_owners/api_request_context.rb +232 -0
- data/lib/playwright/channel_owners/browser_context.rb +8 -1
- data/lib/playwright/channel_owners/frame.rb +2 -2
- data/lib/playwright/channel_owners/local_utils.rb +14 -0
- data/lib/playwright/channel_owners/page.rb +6 -2
- data/lib/playwright/frame_locator_impl.rb +2 -1
- data/lib/playwright/locator_impl.rb +62 -3
- data/lib/playwright/tracing_impl.rb +21 -7
- data/lib/playwright/version.rb +2 -2
- data/lib/playwright_api/android.rb +6 -6
- data/lib/playwright_api/android_device.rb +8 -8
- data/lib/playwright_api/api_request.rb +20 -0
- data/lib/playwright_api/api_request_context.rb +61 -14
- data/lib/playwright_api/api_response.rb +81 -0
- data/lib/playwright_api/browser.rb +6 -6
- data/lib/playwright_api/browser_context.rb +12 -12
- data/lib/playwright_api/browser_type.rb +6 -6
- data/lib/playwright_api/cdp_session.rb +6 -6
- data/lib/playwright_api/console_message.rb +6 -6
- data/lib/playwright_api/dialog.rb +6 -6
- data/lib/playwright_api/download.rb +0 -4
- data/lib/playwright_api/element_handle.rb +6 -6
- data/lib/playwright_api/frame.rb +8 -8
- data/lib/playwright_api/frame_locator.rb +11 -2
- data/lib/playwright_api/js_handle.rb +6 -6
- data/lib/playwright_api/local_utils.rb +9 -0
- data/lib/playwright_api/locator.rb +16 -46
- data/lib/playwright_api/page.rb +17 -12
- data/lib/playwright_api/playwright.rb +6 -6
- data/lib/playwright_api/request.rb +6 -6
- data/lib/playwright_api/response.rb +6 -6
- data/lib/playwright_api/route.rb +6 -6
- data/lib/playwright_api/selectors.rb +6 -6
- data/lib/playwright_api/web_socket.rb +6 -6
- data/lib/playwright_api/worker.rb +8 -8
- data/playwright.gemspec +1 -1
- metadata +15 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4743c153d270bd3343d7f59b53e1ef03ebecf65495804c79ef4561e5db1263ac
|
4
|
+
data.tar.gz: 2f5db2b025b62ebece498cce6edc8f02f85a07377dee2945fbbcfb60e6718c48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36f2d941a86f2533ad494013346f68a3840e33065bf1d3021ff071f6caec635e890378eb7a88df3d096ffa85a86b037e93dae68535c0d30baacc699cb62292a5
|
7
|
+
data.tar.gz: 38757489faccca207351dfc8ff1d5519ee7fe329726a0024fe80fe83eb772abed986dbfcde5ad0b1cd5987a5b79666a4675cb360bb3333b1b29e4065087b2b75
|
@@ -8,3 +8,164 @@ This API is used for the Web API testing. You can use it to trigger API endpoint
|
|
8
8
|
environment or the service to your e2e test. When used on [Page](./page) or a [BrowserContext](./browser_context), this API will automatically use
|
9
9
|
the cookies from the corresponding [BrowserContext](./browser_context). This means that if you log in using this API, your e2e test will be
|
10
10
|
logged in and vice versa.
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
playwright.chromium.launch do |browser|
|
14
|
+
# This will launch a new browser, create a context and page. When making HTTP
|
15
|
+
# requests with the internal APIRequestContext (e.g. `context.request` or `page.request`)
|
16
|
+
# it will automatically set the cookies to the browser page and vise versa.
|
17
|
+
context = browser.new_context(base_url: 'https://api.github,com')
|
18
|
+
api_request_context = context.request
|
19
|
+
|
20
|
+
|
21
|
+
# Create a repository.
|
22
|
+
response = api_request_context.post(
|
23
|
+
"/user/repos",
|
24
|
+
headers: {
|
25
|
+
"Accept": "application/vnd.github.v3+json",
|
26
|
+
"Authorization": "Bearer #{API_TOKEN}",
|
27
|
+
},
|
28
|
+
data: { name: 'test-repo-1' },
|
29
|
+
)
|
30
|
+
response.ok? # => true
|
31
|
+
response.json['name'] # => "tes≈-repo-1"
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
|
36
|
+
## delete
|
37
|
+
|
38
|
+
```
|
39
|
+
def delete(
|
40
|
+
url,
|
41
|
+
data: nil,
|
42
|
+
failOnStatusCode: nil,
|
43
|
+
form: nil,
|
44
|
+
headers: nil,
|
45
|
+
ignoreHTTPSErrors: nil,
|
46
|
+
multipart: nil,
|
47
|
+
params: nil,
|
48
|
+
timeout: nil)
|
49
|
+
```
|
50
|
+
|
51
|
+
Sends HTTP(S) [DELETE](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE) request and returns its
|
52
|
+
response. The method will populate request cookies from the context and update context cookies from the response. The
|
53
|
+
method will automatically follow redirects.
|
54
|
+
|
55
|
+
## dispose
|
56
|
+
|
57
|
+
```
|
58
|
+
def dispose
|
59
|
+
```
|
60
|
+
|
61
|
+
All responses returned by [APIRequestContext#get](./api_request_context#get) and similar methods are stored in the memory, so that you
|
62
|
+
can later call [APIResponse#body](./api_response#body). This method discards all stored responses, and makes
|
63
|
+
[APIResponse#body](./api_response#body) throw "Response disposed" error.
|
64
|
+
|
65
|
+
## fetch
|
66
|
+
|
67
|
+
```
|
68
|
+
def fetch(
|
69
|
+
urlOrRequest,
|
70
|
+
data: nil,
|
71
|
+
failOnStatusCode: nil,
|
72
|
+
form: nil,
|
73
|
+
headers: nil,
|
74
|
+
ignoreHTTPSErrors: nil,
|
75
|
+
method: nil,
|
76
|
+
multipart: nil,
|
77
|
+
params: nil,
|
78
|
+
timeout: nil)
|
79
|
+
```
|
80
|
+
|
81
|
+
Sends HTTP(S) request and returns its response. The method will populate request cookies from the context and update
|
82
|
+
context cookies from the response. The method will automatically follow redirects.
|
83
|
+
|
84
|
+
## get
|
85
|
+
|
86
|
+
```
|
87
|
+
def get(
|
88
|
+
url,
|
89
|
+
failOnStatusCode: nil,
|
90
|
+
headers: nil,
|
91
|
+
ignoreHTTPSErrors: nil,
|
92
|
+
params: nil,
|
93
|
+
timeout: nil)
|
94
|
+
```
|
95
|
+
|
96
|
+
Sends HTTP(S) [GET](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET) request and returns its response. The
|
97
|
+
method will populate request cookies from the context and update context cookies from the response. The method will
|
98
|
+
automatically follow redirects.
|
99
|
+
|
100
|
+
## head
|
101
|
+
|
102
|
+
```
|
103
|
+
def head(
|
104
|
+
url,
|
105
|
+
failOnStatusCode: nil,
|
106
|
+
headers: nil,
|
107
|
+
ignoreHTTPSErrors: nil,
|
108
|
+
params: nil,
|
109
|
+
timeout: nil)
|
110
|
+
```
|
111
|
+
|
112
|
+
Sends HTTP(S) [HEAD](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD) request and returns its response.
|
113
|
+
The method will populate request cookies from the context and update context cookies from the response. The method will
|
114
|
+
automatically follow redirects.
|
115
|
+
|
116
|
+
## patch
|
117
|
+
|
118
|
+
```
|
119
|
+
def patch(
|
120
|
+
url,
|
121
|
+
data: nil,
|
122
|
+
failOnStatusCode: nil,
|
123
|
+
form: nil,
|
124
|
+
headers: nil,
|
125
|
+
ignoreHTTPSErrors: nil,
|
126
|
+
multipart: nil,
|
127
|
+
params: nil,
|
128
|
+
timeout: nil)
|
129
|
+
```
|
130
|
+
|
131
|
+
Sends HTTP(S) [PATCH](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH) request and returns its response.
|
132
|
+
The method will populate request cookies from the context and update context cookies from the response. The method will
|
133
|
+
automatically follow redirects.
|
134
|
+
|
135
|
+
## post
|
136
|
+
|
137
|
+
```
|
138
|
+
def post(
|
139
|
+
url,
|
140
|
+
data: nil,
|
141
|
+
failOnStatusCode: nil,
|
142
|
+
form: nil,
|
143
|
+
headers: nil,
|
144
|
+
ignoreHTTPSErrors: nil,
|
145
|
+
multipart: nil,
|
146
|
+
params: nil,
|
147
|
+
timeout: nil)
|
148
|
+
```
|
149
|
+
|
150
|
+
Sends HTTP(S) [POST](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST) request and returns its response.
|
151
|
+
The method will populate request cookies from the context and update context cookies from the response. The method will
|
152
|
+
automatically follow redirects.
|
153
|
+
|
154
|
+
## put
|
155
|
+
|
156
|
+
```
|
157
|
+
def put(
|
158
|
+
url,
|
159
|
+
data: nil,
|
160
|
+
failOnStatusCode: nil,
|
161
|
+
form: nil,
|
162
|
+
headers: nil,
|
163
|
+
ignoreHTTPSErrors: nil,
|
164
|
+
multipart: nil,
|
165
|
+
params: nil,
|
166
|
+
timeout: nil)
|
167
|
+
```
|
168
|
+
|
169
|
+
Sends HTTP(S) [PUT](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT) request and returns its response. The
|
170
|
+
method will populate request cookies from the context and update context cookies from the response. The method will
|
171
|
+
automatically follow redirects.
|
@@ -0,0 +1,104 @@
|
|
1
|
+
---
|
2
|
+
sidebar_position: 10
|
3
|
+
---
|
4
|
+
|
5
|
+
# APIResponse
|
6
|
+
|
7
|
+
[APIResponse](./api_response) class represents responses returned by [APIRequestContext#get](./api_request_context#get) and similar methods.
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
playwright.chromium.launch do |browser|
|
11
|
+
context = browser.new_context
|
12
|
+
response = context.request.get("https://example.com/user/repos")
|
13
|
+
|
14
|
+
response.ok? # => true
|
15
|
+
response.status # => 200
|
16
|
+
response.headers["content-type"] # => "application/json; charset=utf-8"
|
17
|
+
response.json # => { "name" => "Foo" }
|
18
|
+
response.body # => "{ \"name\" => \"Foo\" }"
|
19
|
+
end
|
20
|
+
```
|
21
|
+
|
22
|
+
|
23
|
+
## body
|
24
|
+
|
25
|
+
```
|
26
|
+
def body
|
27
|
+
```
|
28
|
+
|
29
|
+
Returns the buffer with response body.
|
30
|
+
|
31
|
+
## dispose
|
32
|
+
|
33
|
+
```
|
34
|
+
def dispose
|
35
|
+
```
|
36
|
+
|
37
|
+
Disposes the body of this response. If not called then the body will stay in memory until the context closes.
|
38
|
+
|
39
|
+
## headers
|
40
|
+
|
41
|
+
```
|
42
|
+
def headers
|
43
|
+
```
|
44
|
+
|
45
|
+
An object with all the response HTTP headers associated with this response.
|
46
|
+
|
47
|
+
## headers_array
|
48
|
+
|
49
|
+
```
|
50
|
+
def headers_array
|
51
|
+
```
|
52
|
+
|
53
|
+
An array with all the request HTTP headers associated with this response. Header names are not lower-cased. Headers with
|
54
|
+
multiple entries, such as `Set-Cookie`, appear in the array multiple times.
|
55
|
+
|
56
|
+
## json
|
57
|
+
|
58
|
+
```
|
59
|
+
def json
|
60
|
+
```
|
61
|
+
|
62
|
+
Returns the JSON representation of response body.
|
63
|
+
|
64
|
+
This method will throw if the response body is not parsable via `JSON.parse`.
|
65
|
+
|
66
|
+
## ok
|
67
|
+
|
68
|
+
```
|
69
|
+
def ok
|
70
|
+
```
|
71
|
+
|
72
|
+
Contains a boolean stating whether the response was successful (status in the range 200-299) or not.
|
73
|
+
|
74
|
+
## status
|
75
|
+
|
76
|
+
```
|
77
|
+
def status
|
78
|
+
```
|
79
|
+
|
80
|
+
Contains the status code of the response (e.g., 200 for a success).
|
81
|
+
|
82
|
+
## status_text
|
83
|
+
|
84
|
+
```
|
85
|
+
def status_text
|
86
|
+
```
|
87
|
+
|
88
|
+
Contains the status text of the response (e.g. usually an "OK" for a success).
|
89
|
+
|
90
|
+
## text
|
91
|
+
|
92
|
+
```
|
93
|
+
def text
|
94
|
+
```
|
95
|
+
|
96
|
+
Returns the text representation of response body.
|
97
|
+
|
98
|
+
## url
|
99
|
+
|
100
|
+
```
|
101
|
+
def url
|
102
|
+
```
|
103
|
+
|
104
|
+
Contains the URL of the response.
|
@@ -436,4 +436,8 @@ def expect_page(predicate: nil, timeout: nil)
|
|
436
436
|
Performs action and waits for a new [Page](./page) to be created in the context. If predicate is provided, it passes [Page](./page) value into the `predicate` and waits for `predicate.call(page)` to return a truthy value. Will throw an error if
|
437
437
|
the context closes before new [Page](./page) is created.
|
438
438
|
|
439
|
+
## request
|
440
|
+
|
441
|
+
API testing helper associated with this context. Requests made with this API will use context cookies.
|
442
|
+
|
439
443
|
## tracing
|
@@ -19,9 +19,7 @@ end
|
|
19
19
|
path = download.path
|
20
20
|
```
|
21
21
|
|
22
|
-
|
23
|
-
downloaded content. If `acceptDownloads` is not set, download events are emitted, but the actual download is not
|
24
|
-
performed and user has no access to the downloaded files.
|
22
|
+
|
25
23
|
|
26
24
|
## cancel
|
27
25
|
|
@@ -26,6 +26,15 @@ page.frame_locator('.result-frame').locator('button').click
|
|
26
26
|
page.frame_locator('.result-frame').first.locator('button').click
|
27
27
|
```
|
28
28
|
|
29
|
+
**Converting Locator to FrameLocator**
|
30
|
+
|
31
|
+
If you have a [Locator](./locator) object pointing to an `iframe` it can be converted to [FrameLocator](./frame_locator) using
|
32
|
+
[`:scope`](https://developer.mozilla.org/en-US/docs/Web/CSS/:scope) CSS selector:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
frame_locator = locator.frame_locator(':scope')
|
36
|
+
```
|
37
|
+
|
29
38
|
|
30
39
|
|
31
40
|
## first
|
@@ -56,7 +65,7 @@ Returns locator to the last matching frame.
|
|
56
65
|
## locator
|
57
66
|
|
58
67
|
```
|
59
|
-
def locator(selector)
|
68
|
+
def locator(selector, hasText: nil)
|
60
69
|
```
|
61
70
|
|
62
71
|
The method finds an element matching the specified selector in the FrameLocator's subtree.
|
@@ -4,53 +4,10 @@ sidebar_position: 10
|
|
4
4
|
|
5
5
|
# Locator
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
```ruby
|
11
|
-
locator = page.locator("text=Submit")
|
12
|
-
locator.click
|
13
|
-
```
|
14
|
-
|
15
|
-
The difference between the Locator and [ElementHandle](./element_handle) is that the latter points to a particular element, while Locator
|
16
|
-
captures the logic of how to retrieve that element.
|
17
|
-
|
18
|
-
In the example below, handle points to a particular DOM element on page. If that element changes text or is used by
|
19
|
-
React to render an entirely different component, handle is still pointing to that very DOM element. This can lead to
|
20
|
-
unexpected behaviors.
|
21
|
-
|
22
|
-
```ruby
|
23
|
-
handle = page.query_selector("text=Submit")
|
24
|
-
handle.hover
|
25
|
-
handle.click
|
26
|
-
```
|
27
|
-
|
28
|
-
With the locator, every time the `element` is used, up-to-date DOM element is located in the page using the selector. So
|
29
|
-
in the snippet below, underlying DOM element is going to be located twice.
|
30
|
-
|
31
|
-
```ruby
|
32
|
-
locator = page.locator("text=Submit")
|
33
|
-
locator.hover
|
34
|
-
locator.click
|
35
|
-
```
|
36
|
-
|
37
|
-
**Strictness**
|
38
|
-
|
39
|
-
Locators are strict. This means that all operations on locators that imply some target DOM element will throw if more
|
40
|
-
than one element matches given selector.
|
41
|
-
|
42
|
-
```ruby
|
43
|
-
# Throws if there are several buttons in DOM:
|
44
|
-
page.locator('button').click
|
45
|
-
|
46
|
-
# Works because we explicitly tell locator to pick the first element:
|
47
|
-
page.locator('button').first.click
|
48
|
-
|
49
|
-
# Works because count knows what to do with multiple matches:
|
50
|
-
page.locator('button').count
|
51
|
-
```
|
52
|
-
|
7
|
+
Locators are the central piece of Playwright's auto-waiting and retry-ability. In a nutshell, locators represent a way
|
8
|
+
to find element(s) on the page at any moment. Locator can be created with the [Page#locator](./page#locator) method.
|
53
9
|
|
10
|
+
[Learn more about locators](https://playwright.dev/python/docs/locators).
|
54
11
|
|
55
12
|
## all_inner_texts
|
56
13
|
|
@@ -220,6 +177,21 @@ element.dispatch_event("dragstart", eventInit: { dataTransfer: data_transfer })
|
|
220
177
|
|
221
178
|
|
222
179
|
|
180
|
+
## drag_to
|
181
|
+
|
182
|
+
```
|
183
|
+
def drag_to(
|
184
|
+
target,
|
185
|
+
force: nil,
|
186
|
+
noWaitAfter: nil,
|
187
|
+
sourcePosition: nil,
|
188
|
+
targetPosition: nil,
|
189
|
+
timeout: nil,
|
190
|
+
trial: nil)
|
191
|
+
```
|
192
|
+
|
193
|
+
|
194
|
+
|
223
195
|
## element_handle
|
224
196
|
|
225
197
|
```
|
@@ -458,7 +430,7 @@ Returns locator to the last matching element.
|
|
458
430
|
## locator
|
459
431
|
|
460
432
|
```
|
461
|
-
def locator(selector)
|
433
|
+
def locator(selector, hasText: nil)
|
462
434
|
```
|
463
435
|
|
464
436
|
The method finds an element matching the specified selector in the [Locator](./locator)'s subtree.
|
@@ -774,7 +774,7 @@ considered not visible.
|
|
774
774
|
## locator
|
775
775
|
|
776
776
|
```
|
777
|
-
def locator(selector)
|
777
|
+
def locator(selector, hasText: nil)
|
778
778
|
```
|
779
779
|
|
780
780
|
The method returns an element locator that can be used to perform actions on the page. Locator is resolved to the
|
@@ -1597,4 +1597,8 @@ associated with the page.
|
|
1597
1597
|
|
1598
1598
|
## mouse
|
1599
1599
|
|
1600
|
+
## request
|
1601
|
+
|
1602
|
+
API testing helper associated with this page. Requests made with this API will use page cookies.
|
1603
|
+
|
1600
1604
|
## touchscreen
|
@@ -1,17 +1,5 @@
|
|
1
1
|
# API coverages
|
2
2
|
|
3
|
-
## APIRequestContext
|
4
|
-
|
5
|
-
* ~~delete~~
|
6
|
-
* ~~dispose~~
|
7
|
-
* ~~fetch~~
|
8
|
-
* ~~get~~
|
9
|
-
* ~~head~~
|
10
|
-
* ~~patch~~
|
11
|
-
* ~~post~~
|
12
|
-
* ~~put~~
|
13
|
-
* ~~storage_state~~
|
14
|
-
|
15
3
|
## Request
|
16
4
|
|
17
5
|
* all_headers
|
@@ -331,6 +319,7 @@
|
|
331
319
|
* accessibility
|
332
320
|
* keyboard
|
333
321
|
* mouse
|
322
|
+
* request
|
334
323
|
* touchscreen
|
335
324
|
|
336
325
|
## BrowserContext
|
@@ -361,7 +350,7 @@
|
|
361
350
|
* expect_event
|
362
351
|
* expect_page
|
363
352
|
* ~~wait_for_event~~
|
364
|
-
*
|
353
|
+
* request
|
365
354
|
* tracing
|
366
355
|
|
367
356
|
## CDPSession
|
@@ -417,6 +406,7 @@
|
|
417
406
|
* count
|
418
407
|
* dblclick
|
419
408
|
* dispatch_event
|
409
|
+
* drag_to
|
420
410
|
* element_handle
|
421
411
|
* element_handles
|
422
412
|
* evaluate
|
@@ -461,6 +451,38 @@
|
|
461
451
|
* locator
|
462
452
|
* nth
|
463
453
|
|
454
|
+
## LocalUtils
|
455
|
+
|
456
|
+
|
457
|
+
## APIResponse
|
458
|
+
|
459
|
+
* body
|
460
|
+
* dispose
|
461
|
+
* headers
|
462
|
+
* headers_array
|
463
|
+
* json
|
464
|
+
* ok
|
465
|
+
* status
|
466
|
+
* status_text
|
467
|
+
* text
|
468
|
+
* url
|
469
|
+
|
470
|
+
## APIRequestContext
|
471
|
+
|
472
|
+
* delete
|
473
|
+
* dispose
|
474
|
+
* fetch
|
475
|
+
* get
|
476
|
+
* head
|
477
|
+
* patch
|
478
|
+
* post
|
479
|
+
* put
|
480
|
+
* ~~storage_state~~
|
481
|
+
|
482
|
+
## ~~APIRequest~~
|
483
|
+
|
484
|
+
* ~~new_context~~
|
485
|
+
|
464
486
|
## Android
|
465
487
|
|
466
488
|
* devices
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module Playwright
|
2
|
+
define_api_implementation :APIResponseImpl do
|
3
|
+
include Utils::Errors::SafeCloseError
|
4
|
+
|
5
|
+
# @params context [APIRequestContext]
|
6
|
+
# @params initializer [Hash]
|
7
|
+
def initialize(context, initializer)
|
8
|
+
@request = context
|
9
|
+
@initializer = initializer
|
10
|
+
@headers = RawHeaders.new(initializer['headers'])
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
"#<APIResponse url=#{url} status=#{status} status_text=#{status_text}>"
|
15
|
+
end
|
16
|
+
|
17
|
+
def url
|
18
|
+
@initializer['url']
|
19
|
+
end
|
20
|
+
|
21
|
+
def ok
|
22
|
+
(200...300).include?(status)
|
23
|
+
end
|
24
|
+
alias_method :ok?, :ok
|
25
|
+
|
26
|
+
def status
|
27
|
+
@initializer['status']
|
28
|
+
end
|
29
|
+
|
30
|
+
def status_text
|
31
|
+
@initializer['statusText']
|
32
|
+
end
|
33
|
+
|
34
|
+
def headers
|
35
|
+
@headers.headers
|
36
|
+
end
|
37
|
+
|
38
|
+
def headers_array
|
39
|
+
@headers.headers_array
|
40
|
+
end
|
41
|
+
|
42
|
+
class AlreadyDisposedError < StandardError
|
43
|
+
def initialize
|
44
|
+
super('Response has been disposed')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def body
|
49
|
+
binary = @request.channel.send_message_to_server("fetchResponseBody", fetchUid: fetch_uid)
|
50
|
+
raise AlreadyDisposedError.new unless binary
|
51
|
+
Base64.strict_decode64(binary)
|
52
|
+
rescue => err
|
53
|
+
if safe_close_error?(err)
|
54
|
+
raise AlreadyDisposedError.new
|
55
|
+
else
|
56
|
+
raise
|
57
|
+
end
|
58
|
+
end
|
59
|
+
alias_method :text, :body
|
60
|
+
|
61
|
+
def json
|
62
|
+
JSON.parse(text)
|
63
|
+
end
|
64
|
+
|
65
|
+
def dispose
|
66
|
+
@request.channel.send_message_to_server("disposeAPIResponse", fetchUid: fetch_uid)
|
67
|
+
end
|
68
|
+
|
69
|
+
private def fetch_uid
|
70
|
+
@initializer['fetchUid']
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|