Module: TempmailSdk::Providers::OneSecMail
- Defined in:
- lib/tempmail_sdk/providers/one_sec_mail.rb
Overview
1SecMail 渠道 — https://tmaily.com
Constant Summary collapse
- CHANNEL =
"1sec-mail"- BASE_URL =
"https://tmaily.com/"- HEADERS =
{ "Accept" => "application/json", "User-Agent" => "Mozilla/5.0" }.freeze
Class Method Summary collapse
-
.generate_email ⇒ EmailInfo
生成临时邮箱,从 Set-Cookie 提取会话 Cookie.
- .get_emails(email, token) ⇒ Array<Email>
Class Method Details
.generate_email ⇒ EmailInfo
生成临时邮箱,从 Set-Cookie 提取会话 Cookie
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/tempmail_sdk/providers/one_sec_mail.rb', line 15 def generate_email resp = Http.get("#{BASE_URL}generate", headers: HEADERS, timeout: 15) resp.raise_for_status = resp.("TMaily_sid") raise "1sec-mail: 未获取到会话 Cookie" if .nil? || .empty? = "TMaily_sid=#{}" data = resp.json email = data.is_a?(Hash) ? data["address"].to_s.strip : "" raise "1sec-mail: 无效的邮箱响应" unless email.include?("@") EmailInfo.new(channel: CHANNEL, email: email, token: ) end |
.get_emails(email, token) ⇒ Array<Email>
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/tempmail_sdk/providers/one_sec_mail.rb', line 32 def get_emails(email, token) address = email.to_s.strip raise "1sec-mail: 邮箱地址为空" if address.empty? resp = Http.get("#{BASE_URL}emails?address=#{address}", headers: HEADERS.merge("Cookie" => token.to_s), timeout: 15) resp.raise_for_status rows = resp.json raise "1sec-mail: 无效的邮件列表响应" unless rows.is_a?(Array) rows.select { |r| r.is_a?(Hash) }.map { |item| Normalize.normalize_email(item, address) } end |