Module: TempmailSdk::Providers::TempMailIo
- Defined in:
- lib/tempmail_sdk/providers/temp_mail_io.rb
Overview
temp-mail.io 渠道实现 API: https://api.internal.temp-mail.io/api/v3
Constant Summary collapse
- CHANNEL =
"temp-mail-io"- BASE_URL =
"https://api.internal.temp-mail.io/api/v3"- PAGE_URL =
"https://temp-mail.io/en"- UA =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36"
Class Method Summary collapse
- .fetch_cors_header ⇒ Object
- .generate_email ⇒ EmailInfo
- .get_emails(email) ⇒ Array<Email>
- .headers ⇒ Object
Class Method Details
.fetch_cors_header ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/tempmail_sdk/providers/temp_mail_io.rb', line 17 def fetch_cors_header return @cors_header if @cors_header begin resp = Http.get(PAGE_URL, headers: { "User-Agent" => UA }, timeout: 15) m = resp.body.match(/mobileTestingHeader\s*:\s*"([^"]+)"/) @cors_header = m ? m[1] : "1" rescue StandardError @cors_header = "1" end @cors_header end |
.generate_email ⇒ EmailInfo
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/tempmail_sdk/providers/temp_mail_io.rb', line 43 def generate_email resp = Http.post("#{BASE_URL}/email/new", headers: headers, json: { "min_name_length" => 10, "max_name_length" => 10 }, timeout: 15) resp.raise_for_status data = resp.json email = data.is_a?(Hash) ? data["email"] : nil token = data.is_a?(Hash) ? data["token"] : nil raise "temp-mail-io: invalid generate response" if email.to_s.empty? || token.to_s.empty? EmailInfo.new(channel: CHANNEL, email: email, token: token) end |
.get_emails(email) ⇒ Array<Email>
57 58 59 60 61 62 63 64 |
# File 'lib/tempmail_sdk/providers/temp_mail_io.rb', line 57 def get_emails(email) resp = Http.get("#{BASE_URL}/email/#{email}/messages", headers: headers, timeout: 15) resp.raise_for_status rows = resp.json return [] unless rows.is_a?(Array) rows.select { |r| r.is_a?(Hash) }.map { |raw| Normalize.normalize_email(raw, email) } end |
.headers ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/tempmail_sdk/providers/temp_mail_io.rb', line 30 def headers { "Content-Type" => "application/json", "Application-Name" => "web", "Application-Version" => "4.0.0", "X-CORS-Header" => fetch_cors_header, "User-Agent" => UA, "Origin" => "https://temp-mail.io", "Referer" => "https://temp-mail.io/" } end |