unione 1.1.3

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.
Files changed (146) hide show
  1. checksums.yaml +7 -0
  2. data/AGENTS.md +99 -0
  3. data/LICENSE +21 -0
  4. data/README.md +270 -0
  5. data/docs/ConfirmedEmail.md +109 -0
  6. data/docs/Domain.md +257 -0
  7. data/docs/Email.md +126 -0
  8. data/docs/EmailValidation.md +54 -0
  9. data/docs/EventDump.md +157 -0
  10. data/docs/Obsolete.md +119 -0
  11. data/docs/Project.md +174 -0
  12. data/docs/Suppression.md +163 -0
  13. data/docs/System.md +73 -0
  14. data/docs/Tag.md +73 -0
  15. data/docs/Template.md +164 -0
  16. data/docs/Webhook.md +182 -0
  17. data/lib/unione/api/confirmed_email/confirmed_email_api.rb +47 -0
  18. data/lib/unione/api/confirmed_email/model/confirmed_email.rb +49 -0
  19. data/lib/unione/api/confirmed_email/model/confirmed_email_create_response.rb +50 -0
  20. data/lib/unione/api/confirmed_email/model/confirmed_email_delete_response.rb +50 -0
  21. data/lib/unione/api/confirmed_email/model/confirmed_email_list_response.rb +50 -0
  22. data/lib/unione/api/confirmed_email/model/confirmed_email_request.rb +42 -0
  23. data/lib/unione/api/domain/domain_api.rb +129 -0
  24. data/lib/unione/api/domain/model/dkim_status.rb +18 -0
  25. data/lib/unione/api/domain/model/domain_delete_request.rb +42 -0
  26. data/lib/unione/api/domain/model/domain_delete_response.rb +51 -0
  27. data/lib/unione/api/domain/model/domain_get_dns_records_request.rb +42 -0
  28. data/lib/unione/api/domain/model/domain_get_dns_records_response.rb +76 -0
  29. data/lib/unione/api/domain/model/domain_get_sandbox_domain_response.rb +51 -0
  30. data/lib/unione/api/domain/model/domain_list_request.rb +60 -0
  31. data/lib/unione/api/domain/model/domain_list_response.rb +51 -0
  32. data/lib/unione/api/domain/model/domain_list_response_domains_item.rb +58 -0
  33. data/lib/unione/api/domain/model/domain_list_response_domains_item_dkim.rb +52 -0
  34. data/lib/unione/api/domain/model/domain_list_response_domains_item_verification_record.rb +50 -0
  35. data/lib/unione/api/domain/model/domain_validate_dkim_request.rb +42 -0
  36. data/lib/unione/api/domain/model/domain_validate_dkim_response.rb +51 -0
  37. data/lib/unione/api/domain/model/domain_validate_verification_record_request.rb +42 -0
  38. data/lib/unione/api/domain/model/domain_validate_verification_record_response.rb +51 -0
  39. data/lib/unione/api/email/email_api.rb +56 -0
  40. data/lib/unione/api/email/model/email_send_request.rb +42 -0
  41. data/lib/unione/api/email/model/email_send_response.rb +83 -0
  42. data/lib/unione/api/email/model/email_subscribe_request.rb +58 -0
  43. data/lib/unione/api/email/model/message_object.rb +291 -0
  44. data/lib/unione/api/email/model/message_object_options.rb +70 -0
  45. data/lib/unione/api/email/model/message_object_recipients_item.rb +77 -0
  46. data/lib/unione/api/email_validation/email_validation_api.rb +34 -0
  47. data/lib/unione/api/email_validation/model/email_validation_single_request.rb +42 -0
  48. data/lib/unione/api/email_validation/model/email_validation_single_response.rb +140 -0
  49. data/lib/unione/api/event_dump/event_dump_api.rb +67 -0
  50. data/lib/unione/api/event_dump/model/event_dump_create_request.rb +119 -0
  51. data/lib/unione/api/event_dump/model/event_dump_create_response.rb +52 -0
  52. data/lib/unione/api/event_dump/model/event_dump_delete_request.rb +43 -0
  53. data/lib/unione/api/event_dump/model/event_dump_files_object.rb +51 -0
  54. data/lib/unione/api/event_dump/model/event_dump_get_request.rb +43 -0
  55. data/lib/unione/api/event_dump/model/event_dump_get_response.rb +51 -0
  56. data/lib/unione/api/event_dump/model/event_dump_list_response.rb +52 -0
  57. data/lib/unione/api/event_dump/model/event_dump_object.rb +66 -0
  58. data/lib/unione/api/event_dump/model/filter_object.rb +139 -0
  59. data/lib/unione/api/obsolete/model/obsolete_unsubscribed_check_request.rb +42 -0
  60. data/lib/unione/api/obsolete/model/obsolete_unsubscribed_check_response.rb +59 -0
  61. data/lib/unione/api/obsolete/model/obsolete_unsubscribed_list_request.rb +43 -0
  62. data/lib/unione/api/obsolete/model/obsolete_unsubscribed_list_response.rb +51 -0
  63. data/lib/unione/api/obsolete/model/obsolete_unsubscribed_list_response_unsubscribed_item.rb +50 -0
  64. data/lib/unione/api/obsolete/model/obsolete_unsubscribed_set_message.rb +25 -0
  65. data/lib/unione/api/obsolete/model/obsolete_unsubscribed_set_request.rb +42 -0
  66. data/lib/unione/api/obsolete/model/obsolete_unsubscribed_set_response.rb +64 -0
  67. data/lib/unione/api/obsolete/obsolete_api.rb +57 -0
  68. data/lib/unione/api/project/model/project_create_request.rb +42 -0
  69. data/lib/unione/api/project/model/project_create_response.rb +60 -0
  70. data/lib/unione/api/project/model/project_delete_request.rb +52 -0
  71. data/lib/unione/api/project/model/project_list_object.rb +146 -0
  72. data/lib/unione/api/project/model/project_list_request.rb +50 -0
  73. data/lib/unione/api/project/model/project_list_response.rb +51 -0
  74. data/lib/unione/api/project/model/project_object.rb +94 -0
  75. data/lib/unione/api/project/model/project_update_object.rb +130 -0
  76. data/lib/unione/api/project/model/project_update_request.rb +60 -0
  77. data/lib/unione/api/project/model/project_update_response.rb +52 -0
  78. data/lib/unione/api/project/project_api.rb +71 -0
  79. data/lib/unione/api/suppression/model/suppression_delete_request.rb +42 -0
  80. data/lib/unione/api/suppression/model/suppression_get_object.rb +91 -0
  81. data/lib/unione/api/suppression/model/suppression_get_request.rb +52 -0
  82. data/lib/unione/api/suppression/model/suppression_get_response.rb +59 -0
  83. data/lib/unione/api/suppression/model/suppression_list_object.rb +91 -0
  84. data/lib/unione/api/suppression/model/suppression_list_request.rb +94 -0
  85. data/lib/unione/api/suppression/model/suppression_list_response.rb +61 -0
  86. data/lib/unione/api/suppression/model/suppression_set_request.rb +69 -0
  87. data/lib/unione/api/suppression/suppression_api.rb +63 -0
  88. data/lib/unione/api/system/model/project_accounting_object.rb +62 -0
  89. data/lib/unione/api/system/model/system_info_response.rb +95 -0
  90. data/lib/unione/api/system/model/system_info_response_accounting.rb +68 -0
  91. data/lib/unione/api/system/model/system_ping_response.rb +51 -0
  92. data/lib/unione/api/system/system_api.rb +35 -0
  93. data/lib/unione/api/tag/model/tag_delete_request.rb +42 -0
  94. data/lib/unione/api/tag/model/tag_list_response.rb +51 -0
  95. data/lib/unione/api/tag/model/tags_response_object.rb +50 -0
  96. data/lib/unione/api/tag/tag_api.rb +40 -0
  97. data/lib/unione/api/template/model/editor_type.rb +19 -0
  98. data/lib/unione/api/template/model/template_delete_request.rb +42 -0
  99. data/lib/unione/api/template/model/template_get_request.rb +42 -0
  100. data/lib/unione/api/template/model/template_get_response.rb +51 -0
  101. data/lib/unione/api/template/model/template_list_object.rb +232 -0
  102. data/lib/unione/api/template/model/template_list_request.rb +52 -0
  103. data/lib/unione/api/template/model/template_list_response.rb +51 -0
  104. data/lib/unione/api/template/model/template_object.rb +201 -0
  105. data/lib/unione/api/template/model/template_set_request.rb +42 -0
  106. data/lib/unione/api/template/model/template_set_response.rb +51 -0
  107. data/lib/unione/api/template/template_api.rb +66 -0
  108. data/lib/unione/api/webhook/model/block_type.rb +20 -0
  109. data/lib/unione/api/webhook/model/device_type.rb +22 -0
  110. data/lib/unione/api/webhook/model/domain_status.rb +19 -0
  111. data/lib/unione/api/webhook/model/event_name.rb +19 -0
  112. data/lib/unione/api/webhook/model/traffic_type.rb +24 -0
  113. data/lib/unione/api/webhook/model/webhook_callback.rb +52 -0
  114. data/lib/unione/api/webhook/model/webhook_callback_events_by_user_item.rb +66 -0
  115. data/lib/unione/api/webhook/model/webhook_callback_events_by_user_item_events_item.rb +52 -0
  116. data/lib/unione/api/webhook/model/webhook_callback_events_by_user_item_events_item_event_data.rb +167 -0
  117. data/lib/unione/api/webhook/model/webhook_callback_events_by_user_item_events_item_event_data_delivery_info.rb +192 -0
  118. data/lib/unione/api/webhook/model/webhook_delete_request.rb +42 -0
  119. data/lib/unione/api/webhook/model/webhook_event_format.rb +18 -0
  120. data/lib/unione/api/webhook/model/webhook_events_object.rb +52 -0
  121. data/lib/unione/api/webhook/model/webhook_get_request.rb +42 -0
  122. data/lib/unione/api/webhook/model/webhook_get_response.rb +51 -0
  123. data/lib/unione/api/webhook/model/webhook_list_request.rb +51 -0
  124. data/lib/unione/api/webhook/model/webhook_list_response.rb +51 -0
  125. data/lib/unione/api/webhook/model/webhook_object.rb +123 -0
  126. data/lib/unione/api/webhook/model/webhook_set_request.rb +109 -0
  127. data/lib/unione/api/webhook/model/webhook_set_response.rb +51 -0
  128. data/lib/unione/api/webhook/model/webhook_status.rb +21 -0
  129. data/lib/unione/api/webhook/webhook_api.rb +89 -0
  130. data/lib/unione/client/api_client.rb +93 -0
  131. data/lib/unione/client/api_error.rb +22 -0
  132. data/lib/unione/client/configuration.rb +49 -0
  133. data/lib/unione/client/decode.rb +33 -0
  134. data/lib/unione/common/model/attachments_array_item.rb +59 -0
  135. data/lib/unione/common/model/body_object.rb +57 -0
  136. data/lib/unione/common/model/email_counter_mode.rb +21 -0
  137. data/lib/unione/common/model/email_status.rb +23 -0
  138. data/lib/unione/common/model/headers_object.rb +72 -0
  139. data/lib/unione/common/model/inline_attachments_array_item.rb +59 -0
  140. data/lib/unione/common/model/success_response.rb +41 -0
  141. data/lib/unione/common/model/template_engine.rb +19 -0
  142. data/lib/unione/common/model/verification_record_status.rb +16 -0
  143. data/lib/unione/uni_one_client.rb +127 -0
  144. data/lib/unione/version.rb +5 -0
  145. data/lib/unione.rb +130 -0
  146. metadata +187 -0
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UniOne
4
+ module Api
5
+ module Domain
6
+ module Model
7
+ # DomainValidateDkimRequest
8
+ class DomainValidateDkimRequest
9
+ # Domain to validate DKIM record for.
10
+ # @return [String, nil]
11
+ attr_accessor :domain
12
+
13
+ def initialize(
14
+ domain:
15
+ )
16
+ @domain = domain
17
+ end
18
+
19
+ # Builds the object from decoded JSON. Lenient: a missing field, nil or a value of another type
20
+ # gives nil (data that is not a Hash gives an empty object).
21
+ def self.from_h(data)
22
+ data = {} unless data.is_a?(Hash)
23
+ new(
24
+ domain: data['domain']
25
+ )
26
+ end
27
+
28
+ # JSON-ready hash, nil fields are omitted.
29
+ def to_h
30
+ {
31
+ 'domain' => @domain,
32
+ }.compact
33
+ end
34
+
35
+ def to_json(*args)
36
+ to_h.to_json(*args)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UniOne
4
+ module Api
5
+ module Domain
6
+ module Model
7
+ # DomainValidateDkimResponse
8
+ class DomainValidateDkimResponse
9
+ # "success" string
10
+ # Allowed values: `success`.
11
+ # @return [String, nil]
12
+ attr_accessor :status
13
+
14
+ # Debug message.
15
+ # @return [String, nil]
16
+ attr_accessor :message
17
+
18
+ def initialize(
19
+ status: nil,
20
+ message: nil
21
+ )
22
+ @status = status
23
+ @message = message
24
+ end
25
+
26
+ # Builds the object from decoded JSON. Lenient: a missing field, nil or a value of another type
27
+ # gives nil (data that is not a Hash gives an empty object).
28
+ def self.from_h(data)
29
+ data = {} unless data.is_a?(Hash)
30
+ new(
31
+ status: data['status'],
32
+ message: data['message']
33
+ )
34
+ end
35
+
36
+ # JSON-ready hash, nil fields are omitted.
37
+ def to_h
38
+ {
39
+ 'status' => @status,
40
+ 'message' => @message,
41
+ }.compact
42
+ end
43
+
44
+ def to_json(*args)
45
+ to_h.to_json(*args)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UniOne
4
+ module Api
5
+ module Domain
6
+ module Model
7
+ # DomainValidateVerificationRecordRequest
8
+ class DomainValidateVerificationRecordRequest
9
+ # Domain to validate verification record for.
10
+ # @return [String, nil]
11
+ attr_accessor :domain
12
+
13
+ def initialize(
14
+ domain:
15
+ )
16
+ @domain = domain
17
+ end
18
+
19
+ # Builds the object from decoded JSON. Lenient: a missing field, nil or a value of another type
20
+ # gives nil (data that is not a Hash gives an empty object).
21
+ def self.from_h(data)
22
+ data = {} unless data.is_a?(Hash)
23
+ new(
24
+ domain: data['domain']
25
+ )
26
+ end
27
+
28
+ # JSON-ready hash, nil fields are omitted.
29
+ def to_h
30
+ {
31
+ 'domain' => @domain,
32
+ }.compact
33
+ end
34
+
35
+ def to_json(*args)
36
+ to_h.to_json(*args)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UniOne
4
+ module Api
5
+ module Domain
6
+ module Model
7
+ # DomainValidateVerificationRecordResponse
8
+ class DomainValidateVerificationRecordResponse
9
+ # "success" string
10
+ # Allowed values: `success`.
11
+ # @return [String, nil]
12
+ attr_accessor :status
13
+
14
+ # Debug message.
15
+ # @return [String, nil]
16
+ attr_accessor :message
17
+
18
+ def initialize(
19
+ status: nil,
20
+ message: nil
21
+ )
22
+ @status = status
23
+ @message = message
24
+ end
25
+
26
+ # Builds the object from decoded JSON. Lenient: a missing field, nil or a value of another type
27
+ # gives nil (data that is not a Hash gives an empty object).
28
+ def self.from_h(data)
29
+ data = {} unless data.is_a?(Hash)
30
+ new(
31
+ status: data['status'],
32
+ message: data['message']
33
+ )
34
+ end
35
+
36
+ # JSON-ready hash, nil fields are omitted.
37
+ def to_h
38
+ {
39
+ 'status' => @status,
40
+ 'message' => @message,
41
+ }.compact
42
+ end
43
+
44
+ def to_json(*args)
45
+ to_h.to_json(*args)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ module UniOne
6
+ module Api
7
+ module Email
8
+ # This group of methods is related with email sending.
9
+ class EmailApi
10
+ # @param client [::UniOne::Client::ApiClient]
11
+ def initialize(client)
12
+ @client = client
13
+ end
14
+
15
+ # Sends an email or a bunch of emails
16
+ #
17
+ # While sending you can provide substitutions (merge tags), use a template, turn on read or click
18
+ # tracking, etc.
19
+ #
20
+ # Restrictions:
21
+ # * maximum request size is 10 MB
22
+ # * maximum number of recipients is 500
23
+ # * The symbol '/' is not allowed in attachment names
24
+ #
25
+ # If the list of recipients contains invalid, non-existent, duplicate, or unsubscribed emails, those
26
+ # emails will be returned in the output parameter failed_emails, and the email will be sent to all
27
+ # other valid emails addresses. If all the emails addresses fall into failed_emails, sending will not
28
+ # be carried out and API error 204 will be returned.
29
+ #
30
+ # Documentation: https://docs.unione.io/en/web-api-ref#email-send
31
+ # @param request [::UniOne::Api::Email::Model::EmailSendRequest, Hash]
32
+ # @return [::UniOne::Api::Email::Model::EmailSendResponse]
33
+ # @raise [::UniOne::Client::ApiError]
34
+ def send_email(request)
35
+ ::UniOne::Api::Email::Model::EmailSendResponse.from_h(@client.call('/email/send.json', request.is_a?(Hash) ? request : request.to_h))
36
+ end
37
+
38
+ # Sends an email with (re)subscribe link.
39
+ #
40
+ # This method allows subscription renewal by a former subscriber who has previously unsubscribed, or
41
+ # who is blocked because of complaints. This method sends an email with a new subscription link to a
42
+ # former subscriber. Once the recipient clicks the link, their subscription status is restored.
43
+ # There is a default restriction that limits this method to being used once a day. If you need to
44
+ # resubscribe more often, please ask support about it.
45
+ #
46
+ # Documentation: https://docs.unione.io/en/web-api-ref#email-subscribe
47
+ # @param request [::UniOne::Api::Email::Model::EmailSubscribeRequest, Hash]
48
+ # @return [::UniOne::Common::Model::SuccessResponse]
49
+ # @raise [::UniOne::Client::ApiError]
50
+ def subscribe(request)
51
+ ::UniOne::Common::Model::SuccessResponse.from_h(@client.call('/email/subscribe.json', request.is_a?(Hash) ? request : request.to_h))
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UniOne
4
+ module Api
5
+ module Email
6
+ module Model
7
+ # EmailSendRequest
8
+ class EmailSendRequest
9
+ # Object containing all message properties.
10
+ # @return [MessageObject, nil]
11
+ attr_accessor :message
12
+
13
+ def initialize(
14
+ message:
15
+ )
16
+ @message = message
17
+ end
18
+
19
+ # Builds the object from decoded JSON. Lenient: a missing field, nil or a value of another type
20
+ # gives nil (data that is not a Hash gives an empty object).
21
+ def self.from_h(data)
22
+ data = {} unless data.is_a?(Hash)
23
+ new(
24
+ message: ::UniOne::Client::Decode.model(::UniOne::Api::Email::Model::MessageObject, data['message'])
25
+ )
26
+ end
27
+
28
+ # JSON-ready hash, nil fields are omitted.
29
+ def to_h
30
+ {
31
+ 'message' => @message.nil? ? nil : @message.to_h,
32
+ }.compact
33
+ end
34
+
35
+ def to_json(*args)
36
+ to_h.to_json(*args)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UniOne
4
+ module Api
5
+ module Email
6
+ module Model
7
+ # EmailSendResponse
8
+ class EmailSendResponse
9
+ # "success" string
10
+ # Allowed values: `success`.
11
+ # @return [String, nil]
12
+ attr_accessor :status
13
+
14
+ # Job identifier, might be useful for investigating errors.
15
+ # @return [String, nil]
16
+ attr_accessor :job_id
17
+
18
+ # Array of recipients emails successfully accepted for sending.
19
+ # @return [Array<String>, nil]
20
+ attr_accessor :emails
21
+
22
+ # Object with emails rejected for sending as property names and their statuses as property values,
23
+ # e.g.: {"email1@gmail.com": "temporary_unavailable"}. Possible statuses:
24
+ #
25
+ # - __unsubscribed__ - specified email is unsubscribed;
26
+ # - __invalid__ - the email does not exist or has been entered incorrectly;
27
+ # - __duplicate__ - the email already exists in the request, email duplicating is prevented;
28
+ # - __temporary_unavailable__ - the email address is unavailable. This means that over the next three days sending to this address will return an error. Email may be temporarily unavailable due to several reasons, e.g.:
29
+ #
30
+ # - a previous email has been rejected by the recipient's server for spam;
31
+ # - the recipient's mailbox is full or is not used;
32
+ # - recipient's domain does not accept mail;
33
+ # - sending server was rejected due to blacklisting;
34
+ #
35
+ # - __permanent_unavailable__ - the email address is permanently unavailable or unsubscribed globally.
36
+ # - __complained__ - the recipient reported spam in the previous emails;
37
+ # - __blocked__ - sending to the email is prohibited by administration of UniOne.
38
+ # We may added new statuses in the future.
39
+ # @return [Hash{String => String}, nil]
40
+ attr_accessor :failed_emails
41
+
42
+ def initialize(
43
+ status: nil,
44
+ job_id: nil,
45
+ emails: nil,
46
+ failed_emails: nil
47
+ )
48
+ @status = status
49
+ @job_id = job_id
50
+ @emails = emails
51
+ @failed_emails = failed_emails
52
+ end
53
+
54
+ # Builds the object from decoded JSON. Lenient: a missing field, nil or a value of another type
55
+ # gives nil (data that is not a Hash gives an empty object).
56
+ def self.from_h(data)
57
+ data = {} unless data.is_a?(Hash)
58
+ new(
59
+ status: data['status'],
60
+ job_id: data['job_id'],
61
+ emails: ::UniOne::Client::Decode.list(data['emails']),
62
+ failed_emails: ::UniOne::Client::Decode.map(data['failed_emails'])
63
+ )
64
+ end
65
+
66
+ # JSON-ready hash, nil fields are omitted.
67
+ def to_h
68
+ {
69
+ 'status' => @status,
70
+ 'job_id' => @job_id,
71
+ 'emails' => @emails,
72
+ 'failed_emails' => @failed_emails,
73
+ }.compact
74
+ end
75
+
76
+ def to_json(*args)
77
+ to_h.to_json(*args)
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UniOne
4
+ module Api
5
+ module Email
6
+ module Model
7
+ # EmailSubscribeRequest
8
+ class EmailSubscribeRequest
9
+ # Sender’s email on a confirmed domain. (Field alias "email_address_from" is supported, too).
10
+ # @return [String, nil]
11
+ attr_accessor :from_email
12
+
13
+ # Sender’s name. (Field alias "name_from" is supported, too).
14
+ # @return [String, nil]
15
+ attr_accessor :from_name
16
+
17
+ # Recipient’s email. (Field alias "email_address_to" is supported, too).
18
+ # @return [String, nil]
19
+ attr_accessor :to_email
20
+
21
+ def initialize(
22
+ from_email:,
23
+ from_name:,
24
+ to_email:
25
+ )
26
+ @from_email = from_email
27
+ @from_name = from_name
28
+ @to_email = to_email
29
+ end
30
+
31
+ # Builds the object from decoded JSON. Lenient: a missing field, nil or a value of another type
32
+ # gives nil (data that is not a Hash gives an empty object).
33
+ def self.from_h(data)
34
+ data = {} unless data.is_a?(Hash)
35
+ new(
36
+ from_email: data['from_email'],
37
+ from_name: data['from_name'],
38
+ to_email: data['to_email']
39
+ )
40
+ end
41
+
42
+ # JSON-ready hash, nil fields are omitted.
43
+ def to_h
44
+ {
45
+ 'from_email' => @from_email,
46
+ 'from_name' => @from_name,
47
+ 'to_email' => @to_email,
48
+ }.compact
49
+ end
50
+
51
+ def to_json(*args)
52
+ to_h.to_json(*args)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end