@@ -14,6 +14,10 @@ class PhysicalMail < ApplicationRecord
14
14
first_time_7_streak : 1
15
15
}
16
16
17
+ def self . instant_mission_types
18
+ %w[ first_time_7_streak ]
19
+ end
20
+
17
21
scope :pending_delivery , -> {
18
22
where ( status : :pending )
19
23
. joins ( :user )
@@ -36,14 +40,19 @@ def deliver!
36
40
return if status == :sent || theseus_id . present?
37
41
38
42
slug = "hackatime-#{ mission_type . to_s . gsub ( "_" , "-" ) } "
43
+ endpoint = if self . class . instant_mission_types . include? ( mission_type )
44
+ "https://mail.hackclub.com/api/v1/letter_queues/instant/#{ slug } -instant"
45
+ else
46
+ "https://mail.hackclub.com/api/v1/letter_queues/#{ slug } "
47
+ end
39
48
40
49
flavors = FlavorText . compliment
41
50
flavors . concat ( FlavorText . rare_compliment ) if rand ( 10 ) == 0
42
51
43
52
return nil unless user . mailing_address . present?
44
53
45
54
# authorization: Bearer <token>
46
- response = HTTP . auth ( "Bearer #{ ENV [ "MAIL_HACKCLUB_TOKEN" ] } " ) . post ( "https://mail.hackclub.com/api/v1/letter_queues/ #{ slug } " , json : {
55
+ response = HTTP . auth ( "Bearer #{ ENV [ "MAIL_HACKCLUB_TOKEN" ] } " ) . post ( endpoint , json : {
47
56
recipient_email : user . email_addresses . first . email ,
48
57
address : {
49
58
first_name : user . mailing_address . first_name ,
@@ -70,6 +79,9 @@ def deliver!
70
79
update ( status : :failed )
71
80
raise "Failed to deliver physical mail: #{ response . body } "
72
81
end
82
+ rescue OpenSSL ::SSL ::SSLError => e
83
+ Rails . logger . warn "SSL error during mail delivery (request likely succeeded): #{ e . message } "
84
+ update ( status : :sent )
73
85
rescue => e
74
86
update ( status : :failed )
75
87
raise e
0 commit comments