wreq 1.1.0 → 1.2.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.
data/src/emulate.rs CHANGED
@@ -4,11 +4,11 @@ use magnus::{
4
4
  };
5
5
 
6
6
  define_ruby_enum!(
7
- /// An emulation.
7
+ /// An emulation profile.
8
8
  const,
9
- EmulationDevice,
10
- "Wreq::EmulationDevice",
11
- wreq_util::Emulation,
9
+ Profile,
10
+ "Wreq::Profile",
11
+ wreq_util::Profile,
12
12
  Chrome100,
13
13
  Chrome101,
14
14
  Chrome104,
@@ -48,6 +48,7 @@ define_ruby_enum!(
48
48
  Chrome145,
49
49
  Chrome146,
50
50
  Chrome147,
51
+ Chrome148,
51
52
 
52
53
  Edge101,
53
54
  Edge122,
@@ -67,6 +68,7 @@ define_ruby_enum!(
67
68
  Edge145,
68
69
  Edge146,
69
70
  Edge147,
71
+ Edge148,
70
72
 
71
73
  Firefox109,
72
74
  Firefox117,
@@ -86,6 +88,8 @@ define_ruby_enum!(
86
88
  Firefox147,
87
89
  Firefox148,
88
90
  Firefox149,
91
+ Firefox150,
92
+ Firefox151,
89
93
 
90
94
  SafariIos17_2,
91
95
  SafariIos17_4_1,
@@ -110,6 +114,8 @@ define_ruby_enum!(
110
114
  Safari26,
111
115
  Safari26_1,
112
116
  Safari26_2,
117
+ Safari26_3,
118
+ Safari26_4,
113
119
  SafariIos26,
114
120
  SafariIos26_2,
115
121
  SafariIPad26,
@@ -139,14 +145,15 @@ define_ruby_enum!(
139
145
  Opera128,
140
146
  Opera129,
141
147
  Opera130,
148
+ Opera131,
142
149
  );
143
150
 
144
151
  define_ruby_enum!(
145
- /// An emulation operating system.
152
+ /// An emulation profile for OS.
146
153
  const,
147
- EmulationOS,
148
- "Wreq::EmulationOS",
149
- wreq_util::EmulationOS,
154
+ Platform,
155
+ "Wreq::Platform",
156
+ wreq_util::Platform,
150
157
  Windows,
151
158
  MacOS,
152
159
  Linux,
@@ -157,19 +164,19 @@ define_ruby_enum!(
157
164
  /// A struct to represent the `EmulationOption` class.
158
165
  #[derive(Clone)]
159
166
  #[magnus::wrap(class = "Wreq::Emulation", free_immediately, size)]
160
- pub struct Emulation(pub wreq_util::EmulationOption);
167
+ pub struct Emulation(pub wreq_util::Emulation);
161
168
 
162
- // ===== impl EmulationDevice =====
169
+ // ===== impl Profile =====
163
170
 
164
- impl EmulationDevice {
171
+ impl Profile {
165
172
  pub fn to_s(&self) -> String {
166
173
  self.into_ffi().inspect()
167
174
  }
168
175
  }
169
176
 
170
- // ===== impl EmulationOS =====
177
+ // ===== impl Platform =====
171
178
 
172
- impl EmulationOS {
179
+ impl Platform {
173
180
  pub fn to_s(&self) -> String {
174
181
  self.into_ffi().inspect()
175
182
  }
@@ -179,31 +186,31 @@ impl EmulationOS {
179
186
 
180
187
  impl Emulation {
181
188
  fn new(ruby: &Ruby, args: &[Value]) -> Result<Self, Error> {
182
- let mut device = None;
183
- let mut os = None;
184
- let mut skip_http2 = None;
185
- let mut skip_headers = None;
189
+ let mut profile = None;
190
+ let mut platform = None;
191
+ let mut http2 = None;
192
+ let mut headers = None;
186
193
 
187
194
  if let Some(hash) = args.first().and_then(|v| RHash::from_value(*v)) {
188
- if let Some(v) = hash.get(ruby.to_symbol("device")) {
189
- device = Some(Obj::<EmulationDevice>::try_convert(v)?);
195
+ if let Some(v) = hash.get(ruby.to_symbol(stringify!(profile))) {
196
+ profile = Some(Obj::<Profile>::try_convert(v)?);
190
197
  }
191
- if let Some(v) = hash.get(ruby.to_symbol("os")) {
192
- os = Some(Obj::<EmulationOS>::try_convert(v)?);
198
+ if let Some(v) = hash.get(ruby.to_symbol(stringify!(platform))) {
199
+ platform = Some(Obj::<Platform>::try_convert(v)?);
193
200
  }
194
- if let Some(v) = hash.get(ruby.to_symbol("skip_http2")) {
195
- skip_http2 = Some(bool::try_convert(v)?);
201
+ if let Some(v) = hash.get(ruby.to_symbol(stringify!(http2))) {
202
+ http2 = Some(bool::try_convert(v)?);
196
203
  }
197
- if let Some(v) = hash.get(ruby.to_symbol("skip_headers")) {
198
- skip_headers = Some(bool::try_convert(v)?);
204
+ if let Some(v) = hash.get(ruby.to_symbol(stringify!(headers))) {
205
+ headers = Some(bool::try_convert(v)?);
199
206
  }
200
207
  }
201
208
 
202
- let emulation = wreq_util::EmulationOption::builder()
203
- .emulation(device.map(|obj| obj.into_ffi()).unwrap_or_default())
204
- .emulation_os(os.map(|os| os.into_ffi()).unwrap_or_default())
205
- .skip_http2(skip_http2.unwrap_or(false))
206
- .skip_headers(skip_headers.unwrap_or(false))
209
+ let emulation = wreq_util::Emulation::builder()
210
+ .profile(profile.map(|obj| obj.into_ffi()).unwrap_or_default())
211
+ .platform(platform.map(|os| os.into_ffi()).unwrap_or_default())
212
+ .http2(http2.unwrap_or(true))
213
+ .headers(headers.unwrap_or(true))
207
214
  .build();
208
215
 
209
216
  Ok(Self(emulation))
@@ -211,150 +218,158 @@ impl Emulation {
211
218
  }
212
219
 
213
220
  pub fn include(ruby: &Ruby, gem_module: &RModule) -> Result<(), Error> {
214
- // EmulationDevice enum binding
215
- let emulation_class = gem_module.define_class("EmulationDevice", ruby.class_object())?;
216
- emulation_class.define_method("to_s", method!(EmulationDevice::to_s, 0))?;
217
- emulation_class.const_set("Chrome100", EmulationDevice::Chrome100)?;
218
- emulation_class.const_set("Chrome101", EmulationDevice::Chrome101)?;
219
- emulation_class.const_set("Chrome104", EmulationDevice::Chrome104)?;
220
- emulation_class.const_set("Chrome105", EmulationDevice::Chrome105)?;
221
- emulation_class.const_set("Chrome106", EmulationDevice::Chrome106)?;
222
- emulation_class.const_set("Chrome107", EmulationDevice::Chrome107)?;
223
- emulation_class.const_set("Chrome108", EmulationDevice::Chrome108)?;
224
- emulation_class.const_set("Chrome109", EmulationDevice::Chrome109)?;
225
- emulation_class.const_set("Chrome110", EmulationDevice::Chrome110)?;
226
- emulation_class.const_set("Chrome114", EmulationDevice::Chrome114)?;
227
- emulation_class.const_set("Chrome116", EmulationDevice::Chrome116)?;
228
- emulation_class.const_set("Chrome117", EmulationDevice::Chrome117)?;
229
- emulation_class.const_set("Chrome118", EmulationDevice::Chrome118)?;
230
- emulation_class.const_set("Chrome119", EmulationDevice::Chrome119)?;
231
- emulation_class.const_set("Chrome120", EmulationDevice::Chrome120)?;
232
- emulation_class.const_set("Chrome123", EmulationDevice::Chrome123)?;
233
- emulation_class.const_set("Chrome124", EmulationDevice::Chrome124)?;
234
- emulation_class.const_set("Chrome126", EmulationDevice::Chrome126)?;
235
- emulation_class.const_set("Chrome127", EmulationDevice::Chrome127)?;
236
- emulation_class.const_set("Chrome128", EmulationDevice::Chrome128)?;
237
- emulation_class.const_set("Chrome129", EmulationDevice::Chrome129)?;
238
- emulation_class.const_set("Chrome130", EmulationDevice::Chrome130)?;
239
- emulation_class.const_set("Chrome131", EmulationDevice::Chrome131)?;
240
- emulation_class.const_set("Chrome132", EmulationDevice::Chrome132)?;
241
- emulation_class.const_set("Chrome133", EmulationDevice::Chrome133)?;
242
- emulation_class.const_set("Chrome134", EmulationDevice::Chrome134)?;
243
- emulation_class.const_set("Chrome135", EmulationDevice::Chrome135)?;
244
- emulation_class.const_set("Chrome136", EmulationDevice::Chrome136)?;
245
- emulation_class.const_set("Chrome137", EmulationDevice::Chrome137)?;
246
- emulation_class.const_set("Chrome138", EmulationDevice::Chrome138)?;
247
- emulation_class.const_set("Chrome139", EmulationDevice::Chrome139)?;
248
- emulation_class.const_set("Chrome140", EmulationDevice::Chrome140)?;
249
- emulation_class.const_set("Chrome141", EmulationDevice::Chrome141)?;
250
- emulation_class.const_set("Chrome142", EmulationDevice::Chrome142)?;
251
- emulation_class.const_set("Chrome143", EmulationDevice::Chrome143)?;
252
- emulation_class.const_set("Chrome144", EmulationDevice::Chrome144)?;
253
- emulation_class.const_set("Chrome145", EmulationDevice::Chrome145)?;
254
- emulation_class.const_set("Chrome146", EmulationDevice::Chrome146)?;
255
- emulation_class.const_set("Chrome147", EmulationDevice::Chrome147)?;
256
- emulation_class.const_set("Edge101", EmulationDevice::Edge101)?;
257
- emulation_class.const_set("Edge122", EmulationDevice::Edge122)?;
258
- emulation_class.const_set("Edge127", EmulationDevice::Edge127)?;
259
- emulation_class.const_set("Edge131", EmulationDevice::Edge131)?;
260
- emulation_class.const_set("Edge134", EmulationDevice::Edge134)?;
261
- emulation_class.const_set("Edge135", EmulationDevice::Edge135)?;
262
- emulation_class.const_set("Edge136", EmulationDevice::Edge136)?;
263
- emulation_class.const_set("Edge137", EmulationDevice::Edge137)?;
264
- emulation_class.const_set("Edge138", EmulationDevice::Edge138)?;
265
- emulation_class.const_set("Edge139", EmulationDevice::Edge139)?;
266
- emulation_class.const_set("Edge140", EmulationDevice::Edge140)?;
267
- emulation_class.const_set("Edge141", EmulationDevice::Edge141)?;
268
- emulation_class.const_set("Edge142", EmulationDevice::Edge142)?;
269
- emulation_class.const_set("Edge143", EmulationDevice::Edge143)?;
270
- emulation_class.const_set("Edge144", EmulationDevice::Edge144)?;
271
- emulation_class.const_set("Edge145", EmulationDevice::Edge145)?;
272
- emulation_class.const_set("Edge146", EmulationDevice::Edge146)?;
273
- emulation_class.const_set("Edge147", EmulationDevice::Edge147)?;
221
+ // Profile enum binding
222
+ let profile = gem_module.define_class("Profile", ruby.class_object())?;
223
+ profile.define_method("to_s", method!(Profile::to_s, 0))?;
224
+ profile.const_set("Chrome100", Profile::Chrome100)?;
225
+ profile.const_set("Chrome101", Profile::Chrome101)?;
226
+ profile.const_set("Chrome104", Profile::Chrome104)?;
227
+ profile.const_set("Chrome105", Profile::Chrome105)?;
228
+ profile.const_set("Chrome106", Profile::Chrome106)?;
229
+ profile.const_set("Chrome107", Profile::Chrome107)?;
230
+ profile.const_set("Chrome108", Profile::Chrome108)?;
231
+ profile.const_set("Chrome109", Profile::Chrome109)?;
232
+ profile.const_set("Chrome110", Profile::Chrome110)?;
233
+ profile.const_set("Chrome114", Profile::Chrome114)?;
234
+ profile.const_set("Chrome116", Profile::Chrome116)?;
235
+ profile.const_set("Chrome117", Profile::Chrome117)?;
236
+ profile.const_set("Chrome118", Profile::Chrome118)?;
237
+ profile.const_set("Chrome119", Profile::Chrome119)?;
238
+ profile.const_set("Chrome120", Profile::Chrome120)?;
239
+ profile.const_set("Chrome123", Profile::Chrome123)?;
240
+ profile.const_set("Chrome124", Profile::Chrome124)?;
241
+ profile.const_set("Chrome126", Profile::Chrome126)?;
242
+ profile.const_set("Chrome127", Profile::Chrome127)?;
243
+ profile.const_set("Chrome128", Profile::Chrome128)?;
244
+ profile.const_set("Chrome129", Profile::Chrome129)?;
245
+ profile.const_set("Chrome130", Profile::Chrome130)?;
246
+ profile.const_set("Chrome131", Profile::Chrome131)?;
247
+ profile.const_set("Chrome132", Profile::Chrome132)?;
248
+ profile.const_set("Chrome133", Profile::Chrome133)?;
249
+ profile.const_set("Chrome134", Profile::Chrome134)?;
250
+ profile.const_set("Chrome135", Profile::Chrome135)?;
251
+ profile.const_set("Chrome136", Profile::Chrome136)?;
252
+ profile.const_set("Chrome137", Profile::Chrome137)?;
253
+ profile.const_set("Chrome138", Profile::Chrome138)?;
254
+ profile.const_set("Chrome139", Profile::Chrome139)?;
255
+ profile.const_set("Chrome140", Profile::Chrome140)?;
256
+ profile.const_set("Chrome141", Profile::Chrome141)?;
257
+ profile.const_set("Chrome142", Profile::Chrome142)?;
258
+ profile.const_set("Chrome143", Profile::Chrome143)?;
259
+ profile.const_set("Chrome144", Profile::Chrome144)?;
260
+ profile.const_set("Chrome145", Profile::Chrome145)?;
261
+ profile.const_set("Chrome146", Profile::Chrome146)?;
262
+ profile.const_set("Chrome147", Profile::Chrome147)?;
263
+ profile.const_set("Chrome148", Profile::Chrome148)?;
274
264
 
275
- emulation_class.const_set("Firefox109", EmulationDevice::Firefox109)?;
276
- emulation_class.const_set("Firefox117", EmulationDevice::Firefox117)?;
277
- emulation_class.const_set("Firefox128", EmulationDevice::Firefox128)?;
278
- emulation_class.const_set("Firefox133", EmulationDevice::Firefox133)?;
279
- emulation_class.const_set("Firefox135", EmulationDevice::Firefox135)?;
280
- emulation_class.const_set("FirefoxPrivate135", EmulationDevice::FirefoxPrivate135)?;
281
- emulation_class.const_set("FirefoxAndroid135", EmulationDevice::FirefoxAndroid135)?;
282
- emulation_class.const_set("Firefox136", EmulationDevice::Firefox136)?;
283
- emulation_class.const_set("FirefoxPrivate136", EmulationDevice::FirefoxPrivate136)?;
284
- emulation_class.const_set("Firefox139", EmulationDevice::Firefox139)?;
285
- emulation_class.const_set("Firefox142", EmulationDevice::Firefox142)?;
286
- emulation_class.const_set("Firefox143", EmulationDevice::Firefox143)?;
287
- emulation_class.const_set("Firefox144", EmulationDevice::Firefox144)?;
288
- emulation_class.const_set("Firefox145", EmulationDevice::Firefox145)?;
289
- emulation_class.const_set("Firefox146", EmulationDevice::Firefox146)?;
290
- emulation_class.const_set("Firefox147", EmulationDevice::Firefox147)?;
291
- emulation_class.const_set("Firefox148", EmulationDevice::Firefox148)?;
292
- emulation_class.const_set("Firefox149", EmulationDevice::Firefox149)?;
265
+ profile.const_set("Edge101", Profile::Edge101)?;
266
+ profile.const_set("Edge122", Profile::Edge122)?;
267
+ profile.const_set("Edge127", Profile::Edge127)?;
268
+ profile.const_set("Edge131", Profile::Edge131)?;
269
+ profile.const_set("Edge134", Profile::Edge134)?;
270
+ profile.const_set("Edge135", Profile::Edge135)?;
271
+ profile.const_set("Edge136", Profile::Edge136)?;
272
+ profile.const_set("Edge137", Profile::Edge137)?;
273
+ profile.const_set("Edge138", Profile::Edge138)?;
274
+ profile.const_set("Edge139", Profile::Edge139)?;
275
+ profile.const_set("Edge140", Profile::Edge140)?;
276
+ profile.const_set("Edge141", Profile::Edge141)?;
277
+ profile.const_set("Edge142", Profile::Edge142)?;
278
+ profile.const_set("Edge143", Profile::Edge143)?;
279
+ profile.const_set("Edge144", Profile::Edge144)?;
280
+ profile.const_set("Edge145", Profile::Edge145)?;
281
+ profile.const_set("Edge146", Profile::Edge146)?;
282
+ profile.const_set("Edge147", Profile::Edge147)?;
283
+ profile.const_set("Edge148", Profile::Edge148)?;
293
284
 
294
- emulation_class.const_set("SafariIos17_2", EmulationDevice::SafariIos17_2)?;
295
- emulation_class.const_set("SafariIos17_4_1", EmulationDevice::SafariIos17_4_1)?;
296
- emulation_class.const_set("SafariIos16_5", EmulationDevice::SafariIos16_5)?;
297
- emulation_class.const_set("Safari15_3", EmulationDevice::Safari15_3)?;
298
- emulation_class.const_set("Safari15_5", EmulationDevice::Safari15_5)?;
299
- emulation_class.const_set("Safari15_6_1", EmulationDevice::Safari15_6_1)?;
300
- emulation_class.const_set("Safari16", EmulationDevice::Safari16)?;
301
- emulation_class.const_set("Safari16_5", EmulationDevice::Safari16_5)?;
302
- emulation_class.const_set("Safari17_0", EmulationDevice::Safari17_0)?;
303
- emulation_class.const_set("Safari17_2_1", EmulationDevice::Safari17_2_1)?;
304
- emulation_class.const_set("Safari17_4_1", EmulationDevice::Safari17_4_1)?;
305
- emulation_class.const_set("Safari17_5", EmulationDevice::Safari17_5)?;
306
- emulation_class.const_set("Safari17_6", EmulationDevice::Safari17_6)?;
307
- emulation_class.const_set("Safari18", EmulationDevice::Safari18)?;
308
- emulation_class.const_set("SafariIPad18", EmulationDevice::SafariIPad18)?;
309
- emulation_class.const_set("Safari18_2", EmulationDevice::Safari18_2)?;
310
- emulation_class.const_set("Safari18_3", EmulationDevice::Safari18_3)?;
311
- emulation_class.const_set("Safari18_3_1", EmulationDevice::Safari18_3_1)?;
312
- emulation_class.const_set("SafariIos18_1_1", EmulationDevice::SafariIos18_1_1)?;
313
- emulation_class.const_set("Safari18_5", EmulationDevice::Safari18_5)?;
314
- emulation_class.const_set("Safari26", EmulationDevice::Safari26)?;
315
- emulation_class.const_set("Safari26_1", EmulationDevice::Safari26_1)?;
316
- emulation_class.const_set("Safari26_2", EmulationDevice::Safari26_2)?;
317
- emulation_class.const_set("SafariIos26", EmulationDevice::SafariIos26)?;
318
- emulation_class.const_set("SafariIos26_2", EmulationDevice::SafariIos26_2)?;
319
- emulation_class.const_set("SafariIPad26", EmulationDevice::SafariIPad26)?;
320
- emulation_class.const_set("SafariIpad26_2", EmulationDevice::SafariIpad26_2)?;
285
+ profile.const_set("Firefox109", Profile::Firefox109)?;
286
+ profile.const_set("Firefox117", Profile::Firefox117)?;
287
+ profile.const_set("Firefox128", Profile::Firefox128)?;
288
+ profile.const_set("Firefox133", Profile::Firefox133)?;
289
+ profile.const_set("Firefox135", Profile::Firefox135)?;
290
+ profile.const_set("FirefoxPrivate135", Profile::FirefoxPrivate135)?;
291
+ profile.const_set("FirefoxAndroid135", Profile::FirefoxAndroid135)?;
292
+ profile.const_set("Firefox136", Profile::Firefox136)?;
293
+ profile.const_set("FirefoxPrivate136", Profile::FirefoxPrivate136)?;
294
+ profile.const_set("Firefox139", Profile::Firefox139)?;
295
+ profile.const_set("Firefox142", Profile::Firefox142)?;
296
+ profile.const_set("Firefox143", Profile::Firefox143)?;
297
+ profile.const_set("Firefox144", Profile::Firefox144)?;
298
+ profile.const_set("Firefox145", Profile::Firefox145)?;
299
+ profile.const_set("Firefox146", Profile::Firefox146)?;
300
+ profile.const_set("Firefox147", Profile::Firefox147)?;
301
+ profile.const_set("Firefox148", Profile::Firefox148)?;
302
+ profile.const_set("Firefox149", Profile::Firefox149)?;
303
+ profile.const_set("Firefox150", Profile::Firefox150)?;
304
+ profile.const_set("Firefox151", Profile::Firefox151)?;
321
305
 
322
- emulation_class.const_set("OkHttp3_9", EmulationDevice::OkHttp3_9)?;
323
- emulation_class.const_set("OkHttp3_11", EmulationDevice::OkHttp3_11)?;
324
- emulation_class.const_set("OkHttp3_13", EmulationDevice::OkHttp3_13)?;
325
- emulation_class.const_set("OkHttp3_14", EmulationDevice::OkHttp3_14)?;
326
- emulation_class.const_set("OkHttp4_9", EmulationDevice::OkHttp4_9)?;
327
- emulation_class.const_set("OkHttp4_10", EmulationDevice::OkHttp4_10)?;
328
- emulation_class.const_set("OkHttp4_12", EmulationDevice::OkHttp4_12)?;
329
- emulation_class.const_set("OkHttp5", EmulationDevice::OkHttp5)?;
306
+ profile.const_set("SafariIos17_2", Profile::SafariIos17_2)?;
307
+ profile.const_set("SafariIos17_4_1", Profile::SafariIos17_4_1)?;
308
+ profile.const_set("SafariIos16_5", Profile::SafariIos16_5)?;
309
+ profile.const_set("Safari15_3", Profile::Safari15_3)?;
310
+ profile.const_set("Safari15_5", Profile::Safari15_5)?;
311
+ profile.const_set("Safari15_6_1", Profile::Safari15_6_1)?;
312
+ profile.const_set("Safari16", Profile::Safari16)?;
313
+ profile.const_set("Safari16_5", Profile::Safari16_5)?;
314
+ profile.const_set("Safari17_0", Profile::Safari17_0)?;
315
+ profile.const_set("Safari17_2_1", Profile::Safari17_2_1)?;
316
+ profile.const_set("Safari17_4_1", Profile::Safari17_4_1)?;
317
+ profile.const_set("Safari17_5", Profile::Safari17_5)?;
318
+ profile.const_set("Safari17_6", Profile::Safari17_6)?;
319
+ profile.const_set("Safari18", Profile::Safari18)?;
320
+ profile.const_set("SafariIPad18", Profile::SafariIPad18)?;
321
+ profile.const_set("Safari18_2", Profile::Safari18_2)?;
322
+ profile.const_set("Safari18_3", Profile::Safari18_3)?;
323
+ profile.const_set("Safari18_3_1", Profile::Safari18_3_1)?;
324
+ profile.const_set("SafariIos18_1_1", Profile::SafariIos18_1_1)?;
325
+ profile.const_set("Safari18_5", Profile::Safari18_5)?;
326
+ profile.const_set("Safari26", Profile::Safari26)?;
327
+ profile.const_set("Safari26_1", Profile::Safari26_1)?;
328
+ profile.const_set("Safari26_2", Profile::Safari26_2)?;
329
+ profile.const_set("Safari26_3", Profile::Safari26_3)?;
330
+ profile.const_set("Safari26_4", Profile::Safari26_4)?;
331
+ profile.const_set("SafariIos26", Profile::SafariIos26)?;
332
+ profile.const_set("SafariIos26_2", Profile::SafariIos26_2)?;
333
+ profile.const_set("SafariIPad26", Profile::SafariIPad26)?;
334
+ profile.const_set("SafariIpad26_2", Profile::SafariIpad26_2)?;
330
335
 
331
- emulation_class.const_set("Opera116", EmulationDevice::Opera116)?;
332
- emulation_class.const_set("Opera117", EmulationDevice::Opera117)?;
333
- emulation_class.const_set("Opera118", EmulationDevice::Opera118)?;
334
- emulation_class.const_set("Opera119", EmulationDevice::Opera119)?;
335
- emulation_class.const_set("Opera120", EmulationDevice::Opera120)?;
336
- emulation_class.const_set("Opera121", EmulationDevice::Opera121)?;
337
- emulation_class.const_set("Opera122", EmulationDevice::Opera122)?;
338
- emulation_class.const_set("Opera123", EmulationDevice::Opera123)?;
339
- emulation_class.const_set("Opera124", EmulationDevice::Opera124)?;
340
- emulation_class.const_set("Opera125", EmulationDevice::Opera125)?;
341
- emulation_class.const_set("Opera126", EmulationDevice::Opera126)?;
342
- emulation_class.const_set("Opera127", EmulationDevice::Opera127)?;
343
- emulation_class.const_set("Opera128", EmulationDevice::Opera128)?;
344
- emulation_class.const_set("Opera129", EmulationDevice::Opera129)?;
345
- emulation_class.const_set("Opera130", EmulationDevice::Opera130)?;
336
+ profile.const_set("OkHttp3_9", Profile::OkHttp3_9)?;
337
+ profile.const_set("OkHttp3_11", Profile::OkHttp3_11)?;
338
+ profile.const_set("OkHttp3_13", Profile::OkHttp3_13)?;
339
+ profile.const_set("OkHttp3_14", Profile::OkHttp3_14)?;
340
+ profile.const_set("OkHttp4_9", Profile::OkHttp4_9)?;
341
+ profile.const_set("OkHttp4_10", Profile::OkHttp4_10)?;
342
+ profile.const_set("OkHttp4_12", Profile::OkHttp4_12)?;
343
+ profile.const_set("OkHttp5", Profile::OkHttp5)?;
346
344
 
347
- // EmulationOS enum binding
348
- let emulation_os_class = gem_module.define_class("EmulationOS", ruby.class_object())?;
349
- emulation_os_class.define_method("to_s", method!(EmulationOS::to_s, 0))?;
350
- emulation_os_class.const_set("Windows", EmulationOS::Windows)?;
351
- emulation_os_class.const_set("MacOS", EmulationOS::MacOS)?;
352
- emulation_os_class.const_set("Linux", EmulationOS::Linux)?;
353
- emulation_os_class.const_set("Android", EmulationOS::Android)?;
354
- emulation_os_class.const_set("IOS", EmulationOS::IOS)?;
345
+ profile.const_set("Opera116", Profile::Opera116)?;
346
+ profile.const_set("Opera117", Profile::Opera117)?;
347
+ profile.const_set("Opera118", Profile::Opera118)?;
348
+ profile.const_set("Opera119", Profile::Opera119)?;
349
+ profile.const_set("Opera120", Profile::Opera120)?;
350
+ profile.const_set("Opera121", Profile::Opera121)?;
351
+ profile.const_set("Opera122", Profile::Opera122)?;
352
+ profile.const_set("Opera123", Profile::Opera123)?;
353
+ profile.const_set("Opera124", Profile::Opera124)?;
354
+ profile.const_set("Opera125", Profile::Opera125)?;
355
+ profile.const_set("Opera126", Profile::Opera126)?;
356
+ profile.const_set("Opera127", Profile::Opera127)?;
357
+ profile.const_set("Opera128", Profile::Opera128)?;
358
+ profile.const_set("Opera129", Profile::Opera129)?;
359
+ profile.const_set("Opera130", Profile::Opera130)?;
360
+ profile.const_set("Opera131", Profile::Opera131)?;
361
+
362
+ // Platform enum binding
363
+ let platform = gem_module.define_class("Platform", ruby.class_object())?;
364
+ platform.define_method("to_s", method!(Platform::to_s, 0))?;
365
+ platform.const_set("Windows", Platform::Windows)?;
366
+ platform.const_set("MacOS", Platform::MacOS)?;
367
+ platform.const_set("Linux", Platform::Linux)?;
368
+ platform.const_set("Android", Platform::Android)?;
369
+ platform.const_set("IOS", Platform::IOS)?;
355
370
 
356
371
  // Emulation class binding
357
- let emulation_option_class = gem_module.define_class("Emulation", ruby.class_object())?;
358
- emulation_option_class.define_singleton_method("new", function!(Emulation::new, -1))?;
372
+ let emulation = gem_module.define_class("Emulation", ruby.class_object())?;
373
+ emulation.define_singleton_method("new", function!(Emulation::new, -1))?;
359
374
  Ok(())
360
375
  }
data/src/error.rs CHANGED
@@ -85,6 +85,14 @@ pub fn interrupt_error() -> MagnusError {
85
85
  MagnusError::new(ruby!().get_inner(&INTERRUPT_ERROR), "request interrupted")
86
86
  }
87
87
 
88
+ /// LocalJumpError for methods that require a Ruby block.
89
+ pub fn no_block_given_error() -> MagnusError {
90
+ MagnusError::new(
91
+ ruby!().exception_local_jump_error(),
92
+ "no block given (yield)",
93
+ )
94
+ }
95
+
88
96
  /// Map [`tokio::sync::mpsc::error::SendError`] to corresponding [`magnus::Error`]
89
97
  pub fn mpsc_send_error_to_magnus<T>(err: SendError<T>) -> MagnusError {
90
98
  MagnusError::new(
@@ -109,6 +117,14 @@ pub fn header_value_error_to_magnus(err: wreq::header::InvalidHeaderValue) -> Ma
109
117
  )
110
118
  }
111
119
 
120
+ /// Map type/value errors to corresponding [`magnus::Error`]
121
+ pub fn type_value_error_to_magnus(err: &str) -> MagnusError {
122
+ MagnusError::new(
123
+ ruby!().get_inner(&BUILDER_ERROR),
124
+ format!("type error: {err}"),
125
+ )
126
+ }
127
+
112
128
  /// Map [`wreq::Error`] to corresponding [`magnus::Error`]
113
129
  pub fn wreq_error_to_magnus(err: wreq::Error) -> MagnusError {
114
130
  let error_msg = err.to_string();
data/src/extractor.rs CHANGED
@@ -1,7 +1,6 @@
1
- use bytes::Bytes;
2
1
  use magnus::{RArray, RHash, RString, Ruby, TryConvert, r_hash::ForEach};
3
2
  use wreq::{
4
- Proxy, Version,
3
+ Proxy,
5
4
  header::{HeaderMap, HeaderName, HeaderValue, OrigHeaderMap},
6
5
  };
7
6
 
@@ -33,27 +32,6 @@ where
33
32
  }
34
33
  }
35
34
 
36
- // ===== impl Extractor<Version> =====
37
-
38
- impl ExtractorName for Version {
39
- const NAME: &str = "version";
40
- }
41
-
42
- impl TryConvert for Extractor<Version> {
43
- fn try_convert(value: magnus::Value) -> Result<Self, magnus::Error> {
44
- let keyword = RHash::try_convert(value)?;
45
- if let Some(version_val) = keyword.get(Version::NAME) {
46
- return <&crate::http::Version>::try_convert(version_val)
47
- .cloned()
48
- .map(crate::http::Version::into_ffi)
49
- .map(Some)
50
- .map(Extractor);
51
- }
52
-
53
- Ok(Extractor(None))
54
- }
55
- }
56
-
57
35
  // ===== impl Extractor<HeaderValue> =====
58
36
 
59
37
  impl ExtractorName for HeaderValue {
@@ -138,41 +116,6 @@ impl TryConvert for Extractor<OrigHeaderMap> {
138
116
  }
139
117
  }
140
118
 
141
- // ===== impl Extractor<Vec<HeaderValue>> =====
142
-
143
- impl ExtractorName for Vec<HeaderValue> {
144
- const NAME: &str = "cookies";
145
- }
146
-
147
- impl TryConvert for Extractor<Vec<HeaderValue>> {
148
- fn try_convert(value: magnus::Value) -> Result<Self, magnus::Error> {
149
- use percent_encoding::{NON_ALPHANUMERIC, percent_encode};
150
-
151
- let ruby = Ruby::get_with(value);
152
- let keyword = RHash::try_convert(value)?;
153
-
154
- if let Some(hash) = keyword
155
- .get(ruby.to_symbol(Vec::<HeaderValue>::NAME))
156
- .and_then(RHash::from_value)
157
- {
158
- let mut cookies = Vec::new();
159
- hash.foreach(|name: RString, value: RString| {
160
- let value = value.to_bytes();
161
- let encoded_value = percent_encode(&value, NON_ALPHANUMERIC);
162
- let cookie = format!("{name}={encoded_value}");
163
- let header_value = HeaderValue::from_maybe_shared(Bytes::from(cookie))
164
- .map_err(header_value_error_to_magnus)?;
165
- cookies.push(header_value);
166
- Ok(ForEach::Continue)
167
- })?;
168
-
169
- return Ok(Extractor(Some(cookies)));
170
- }
171
-
172
- Ok(Extractor(None))
173
- }
174
- }
175
-
176
119
  // ===== impl Extractor<Proxy> =====
177
120
 
178
121
  impl ExtractorName for Proxy {
@@ -182,9 +125,9 @@ impl ExtractorName for Proxy {
182
125
  impl TryConvert for Extractor<Proxy> {
183
126
  fn try_convert(value: magnus::Value) -> Result<Self, magnus::Error> {
184
127
  let ruby = Ruby::get_with(value);
185
- let keyword = RHash::try_convert(value)?;
128
+ let rhash = RHash::try_convert(value)?;
186
129
 
187
- if let Some(proxy) = keyword
130
+ if let Some(proxy) = rhash
188
131
  .get(ruby.to_symbol(Proxy::NAME))
189
132
  .and_then(RString::from_value)
190
133
  {