wreq-rb 0.3.3 → 0.4.0
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/Cargo.lock +1 -1
- data/README.md +6 -0
- data/ext/wreq_rb/Cargo.toml +2 -2
- data/ext/wreq_rb/src/client.rs +33 -6
- data/lib/wreq-rb/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 71608761c20fbf78bba7dee0c06b2518f6ed6ff843f755ea5df5e0a7bdc0c9a4
|
|
4
|
+
data.tar.gz: 84e1796d7cfc7bdb65dfb593a59b19c7cc482bc068fabfe108bf86e4df661acc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 66afa069e1fe4ba4ea575507148a008021f59fbbefe53eb9433d123fd7caa36e956e340495914d159c7da69b9ce03773a1976af1c75c598ec763131cabc08e73
|
|
7
|
+
data.tar.gz: 87598598868608d50e6169d903c29cfc443f1e3439e4b20d8f81f974c95de6a247d11b272912ac880e4bae4377f72d1c9721e52bf7e774b9f0b74e6ec5f3e05c
|
data/Cargo.lock
CHANGED
data/README.md
CHANGED
|
@@ -76,6 +76,7 @@ client = Wreq::Client.new(
|
|
|
76
76
|
deflate: true, # enable deflate decompression
|
|
77
77
|
zstd: true, # enable zstd decompression
|
|
78
78
|
emulation: "chrome_143", # browser emulation (enabled by default)
|
|
79
|
+
emulation_os: "windows", # OS emulation: windows, macos (default), linux, android, ios
|
|
79
80
|
headers: { # default headers for all requests
|
|
80
81
|
"Accept" => "application/json"
|
|
81
82
|
}
|
|
@@ -116,6 +117,7 @@ Pass an options hash as the second argument to any HTTP method:
|
|
|
116
117
|
| `basic` | Array | `[username, password]` for Basic auth |
|
|
117
118
|
| `proxy` | String | Per-request proxy URL |
|
|
118
119
|
| `emulation` | String/Boolean | Per-request emulation override |
|
|
120
|
+
| `emulation_os` | String | OS emulation: `windows`, `macos`, `linux`, `android`, `ios` |
|
|
119
121
|
|
|
120
122
|
## Browser Emulation
|
|
121
123
|
|
|
@@ -132,6 +134,10 @@ client = Wreq::Client.new(emulation: "edge_142")
|
|
|
132
134
|
# Disable emulation entirely
|
|
133
135
|
client = Wreq::Client.new(emulation: false)
|
|
134
136
|
|
|
137
|
+
# Emulate a specific OS (default is macOS)
|
|
138
|
+
client = Wreq::Client.new(emulation: "chrome_145", emulation_os: "windows")
|
|
139
|
+
client = Wreq::Client.new(emulation: "chrome_145", emulation_os: "linux")
|
|
140
|
+
|
|
135
141
|
# Emulation + custom user-agent (user_agent overrides emulation's UA)
|
|
136
142
|
client = Wreq::Client.new(emulation: "chrome_143", user_agent: "MyBot/1.0")
|
|
137
143
|
|
data/ext/wreq_rb/Cargo.toml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "wreq_rb"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.4.0"
|
|
4
4
|
edition = "2021"
|
|
5
5
|
publish = false
|
|
6
6
|
|
|
@@ -24,7 +24,7 @@ wreq = { path = "../../vendor/wreq", features = [
|
|
|
24
24
|
"query",
|
|
25
25
|
"form",
|
|
26
26
|
] }
|
|
27
|
-
wreq-util = { version = "=3.0.0-rc.10", features = ["emulation", "emulation-serde"] }
|
|
27
|
+
wreq-util = { version = "=3.0.0-rc.10", features = ["emulation", "emulation-serde", "emulation-compression"] }
|
|
28
28
|
tokio = { version = "1", features = ["full"] }
|
|
29
29
|
tokio-util = "0.7"
|
|
30
30
|
serde_json = "1.0"
|
data/ext/wreq_rb/src/client.rs
CHANGED
|
@@ -11,7 +11,7 @@ use magnus::{
|
|
|
11
11
|
use tokio::runtime::Runtime;
|
|
12
12
|
use tokio_util::sync::CancellationToken;
|
|
13
13
|
use wreq::header::{HeaderMap, HeaderName, HeaderValue};
|
|
14
|
-
use wreq_util::Emulation as BrowserEmulation;
|
|
14
|
+
use wreq_util::{Emulation as BrowserEmulation, EmulationOS, EmulationOption};
|
|
15
15
|
|
|
16
16
|
use crate::error::{generic_error, to_magnus_error};
|
|
17
17
|
use crate::response::Response;
|
|
@@ -149,6 +149,28 @@ fn parse_emulation(name: &str) -> Result<BrowserEmulation, magnus::Error> {
|
|
|
149
149
|
.map_err(|_| generic_error(format!("unknown emulation: '{}'. Use names like 'chrome_145', 'firefox_147', 'safari_18.5', etc.", name)))
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
+
/// Parse a Ruby string like "windows" into an EmulationOS variant.
|
|
153
|
+
fn parse_emulation_os(name: &str) -> Result<EmulationOS, magnus::Error> {
|
|
154
|
+
let json_val = serde_json::Value::String(name.to_string());
|
|
155
|
+
serde_json::from_value::<EmulationOS>(json_val)
|
|
156
|
+
.map_err(|_| generic_error("unknown emulation_os. Use: 'windows', 'macos', 'linux', 'android', 'ios'"))
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/// Build an EmulationOption from an Emulation and an optional OS from the opts hash.
|
|
160
|
+
fn build_emulation_option(
|
|
161
|
+
emu: BrowserEmulation,
|
|
162
|
+
opts: &RHash,
|
|
163
|
+
) -> Result<EmulationOption, magnus::Error> {
|
|
164
|
+
let os = match hash_get_string(opts, "emulation_os")? {
|
|
165
|
+
Some(os_name) => parse_emulation_os(&os_name)?,
|
|
166
|
+
None => EmulationOS::default(),
|
|
167
|
+
};
|
|
168
|
+
Ok(EmulationOption::builder()
|
|
169
|
+
.emulation(emu)
|
|
170
|
+
.emulation_os(os)
|
|
171
|
+
.build())
|
|
172
|
+
}
|
|
173
|
+
|
|
152
174
|
// --------------------------------------------------------------------------
|
|
153
175
|
// Ruby Client
|
|
154
176
|
// --------------------------------------------------------------------------
|
|
@@ -175,14 +197,17 @@ impl Client {
|
|
|
175
197
|
if val.is_kind_of(ruby.class_false_class()) {
|
|
176
198
|
// emulation: false — skip emulation entirely
|
|
177
199
|
} else if val.is_kind_of(ruby.class_true_class()) {
|
|
178
|
-
|
|
200
|
+
let opt = build_emulation_option(DEFAULT_EMULATION, &opts)?;
|
|
201
|
+
builder = builder.emulation(opt);
|
|
179
202
|
} else {
|
|
180
203
|
let name: String = TryConvert::try_convert(val)?;
|
|
181
204
|
let emu = parse_emulation(&name)?;
|
|
182
|
-
|
|
205
|
+
let opt = build_emulation_option(emu, &opts)?;
|
|
206
|
+
builder = builder.emulation(opt);
|
|
183
207
|
}
|
|
184
208
|
} else {
|
|
185
|
-
|
|
209
|
+
let opt = build_emulation_option(DEFAULT_EMULATION, &opts)?;
|
|
210
|
+
builder = builder.emulation(opt);
|
|
186
211
|
}
|
|
187
212
|
|
|
188
213
|
if let Some(ua) = hash_get_string(&opts, "user_agent")? {
|
|
@@ -416,11 +441,13 @@ fn apply_request_options(
|
|
|
416
441
|
if val.is_kind_of(ruby.class_false_class()) {
|
|
417
442
|
// emulation: false — no per-request emulation override
|
|
418
443
|
} else if val.is_kind_of(ruby.class_true_class()) {
|
|
419
|
-
|
|
444
|
+
let opt = build_emulation_option(DEFAULT_EMULATION, opts)?;
|
|
445
|
+
req = req.emulation(opt);
|
|
420
446
|
} else {
|
|
421
447
|
let name: String = TryConvert::try_convert(val)?;
|
|
422
448
|
let emu = parse_emulation(&name)?;
|
|
423
|
-
|
|
449
|
+
let opt = build_emulation_option(emu, opts)?;
|
|
450
|
+
req = req.emulation(opt);
|
|
424
451
|
}
|
|
425
452
|
}
|
|
426
453
|
|
data/lib/wreq-rb/version.rb
CHANGED