Class: SendgridNotification::SendgridClient
- Inherits:
-
Object
- Object
- SendgridNotification::SendgridClient
- Defined in:
- app/models/sendgrid_notification/sendgrid_client.rb
Defined Under Namespace
Constant Summary collapse
- SUPPRESSION_TYPES =
%w(invalid_emails bounces blocks).freeze
Instance Attribute Summary collapse
-
#api ⇒ Object
readonly
Returns the value of attribute api.
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#last_response ⇒ Object
readonly
Returns the value of attribute last_response.
Instance Method Summary collapse
-
#initialize ⇒ SendgridClient
constructor
A new instance of SendgridClient.
-
#mail_send(from:, from_name:, to:, subject:, body:) ⇒ Object
TODO: status_code が 500 系およびタイムアウトのときにリトライできるようにする POST /mail/send.
-
#suppression_get(suppression_type, start_time:, end_time:, limit: 100, offset: 0) ⇒ Object
GET /suppression/#type/.
Constructor Details
#initialize ⇒ SendgridClient
Returns a new instance of SendgridClient.
41 42 43 44 45 46 47 48 49 |
# File 'app/models/sendgrid_notification/sendgrid_client.rb', line 41 def initialize @api_key = Rails.application.config.sendgrid_notification.api_key if api_key.blank? raise Error, "no sendgrid api_key. set config.sendgrid_notification.api_key or " \ "SENDGRID_API_KEY environment variable." end @api = SendGrid::API.new(api_key: api_key) @last_response = nil end |
Instance Attribute Details
#api ⇒ Object (readonly)
Returns the value of attribute api.
37 38 39 |
# File 'app/models/sendgrid_notification/sendgrid_client.rb', line 37 def api @api end |
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
37 38 39 |
# File 'app/models/sendgrid_notification/sendgrid_client.rb', line 37 def api_key @api_key end |
#last_response ⇒ Object (readonly)
Returns the value of attribute last_response.
37 38 39 |
# File 'app/models/sendgrid_notification/sendgrid_client.rb', line 37 def last_response @last_response end |
Instance Method Details
#mail_send(from:, from_name:, to:, subject:, body:) ⇒ Object
TODO: status_code が 500 系およびタイムアウトのときにリトライできるようにするPOST /mail/send
53 54 55 56 57 |
# File 'app/models/sendgrid_notification/sendgrid_client.rb', line 53 def mail_send(from:, from_name:, to:, subject:, body:) mail = build_mail(from, from_name, to, subject, body) res = client.mail._('send').post(request_body: mail.to_json) @last_response = Response.new(res) end |
#suppression_get(suppression_type, start_time:, end_time:, limit: 100, offset: 0) ⇒ Object
GET /suppression/#type/
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/models/sendgrid_notification/sendgrid_client.rb', line 62 def suppression_get(suppression_type, start_time:, end_time:, limit: 100, offset: 0) unless SUPPRESSION_TYPES.include?(suppression_type.to_s) # 警告のみ Rails.logger.error("Unknown suppresssion type '#{suppression_type}'") end params = { start_time: start_time.to_i, end_time: end_time.to_i, limit: limit, offset: offset, } res = client.suppression._(suppression_type).get(query_params: params) @last_response = Response.new(res) end |