Module: TempmailSdk::Providers::Mail10s
- Defined in:
- lib/tempmail_sdk/providers/mail10s.rb
Overview
mail10s.com 渠道实现
Constant Summary collapse
- CHANNEL =
"mail10s"- BASE_URL =
"https://mail10s.com"- DOMAIN =
"mail10s.com"- HEADERS =
{ "Accept" => "application/json", "User-Agent" => "Mozilla/5.0" }.freeze
Class Method Summary collapse
- .flatten(raw, recipient) ⇒ Object
- .generate_email ⇒ EmailInfo
- .get_emails(email) ⇒ Array<Email>
- .random_local ⇒ Object
Class Method Details
.flatten(raw, recipient) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/tempmail_sdk/providers/mail10s.rb', line 19 def flatten(raw, recipient) { "id" => raw["id"].to_s, "from" => (raw["sender"] || "").to_s, "to" => recipient, "subject" => (raw["subject"] || "").to_s, "text" => (raw["body_text"] || "").to_s, "html" => (raw["body_html"] || "").to_s, "date" => (raw["received_at"] || "").to_s, "attachments" => raw["attachments"].is_a?(Array) ? raw["attachments"] : [] } end |
.generate_email ⇒ EmailInfo
33 34 35 36 |
# File 'lib/tempmail_sdk/providers/mail10s.rb', line 33 def generate_email email = "#{random_local}@#{DOMAIN}" EmailInfo.new(channel: CHANNEL, email: email, token: email) end |
.get_emails(email) ⇒ Array<Email>
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/tempmail_sdk/providers/mail10s.rb', line 40 def get_emails(email) address = email.to_s.strip raise "mail10s: empty email" if address.empty? resp = Http.get( "#{BASE_URL}/api/emails/#{URI.encode_www_form_component(address)}/inbox", headers: HEADERS, timeout: 15 ) resp.raise_for_status data = resp.json = if data.is_a?(Hash) && data["data"].is_a?(Hash) data["data"]["messages"] end return [] unless .is_a?(Array) .select { |r| r.is_a?(Hash) }.map { |row| Normalize.normalize_email(flatten(row, address), address) } end |
.random_local ⇒ Object
14 15 16 17 |
# File 'lib/tempmail_sdk/providers/mail10s.rb', line 14 def random_local chars = ("a".."z").to_a + ("0".."9").to_a "sdk" + Array.new(16) { chars.sample }.join end |