Module: SendGrid4r::REST::SpamReports

Includes:
Request
Included in:
API
Defined in:
lib/sendgrid4r/rest/spam_reports.rb

Overview

SendGrid Web API v3 SpamReports

Defined Under Namespace

Classes: SpamReport

Constant Summary

Constants included from Request

Request::BASE_URL

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Request

#create_args, #delete, #execute, #finish, #get, #patch, #post, #process_array_params, #process_url_params, #put

Class Method Details

.create_spam_report(resp) ⇒ Object



23
24
25
26
27
# File 'lib/sendgrid4r/rest/spam_reports.rb', line 23

def self.create_spam_report(resp)
  return resp if resp.nil?
  created = Time.at(resp['created']) unless resp['created'].nil?
  SpamReport.new(created, resp['email'], resp['ip'])
end

.create_spam_reports(resp) ⇒ Object



18
19
20
21
# File 'lib/sendgrid4r/rest/spam_reports.rb', line 18

def self.create_spam_reports(resp)
  return resp if resp.nil?
  resp.map { |spam_report| SpamReports.create_spam_report(spam_report) }
end

.url(email = nil) ⇒ Object



12
13
14
15
16
# File 'lib/sendgrid4r/rest/spam_reports.rb', line 12

def self.url(email = nil)
  url = "#{BASE_URL}/suppression/spam_reports"
  url = "#{url}/#{email}" unless email.nil?
  url
end

Instance Method Details

#delete_spam_report(email:, &block) ⇒ Object



55
56
57
# File 'lib/sendgrid4r/rest/spam_reports.rb', line 55

def delete_spam_report(email:, &block)
  delete(@auth, SpamReports.url(email), &block)
end

#delete_spam_reports(delete_all: nil, emails: nil, &block) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/sendgrid4r/rest/spam_reports.rb', line 41

def delete_spam_reports(delete_all: nil, emails: nil, &block)
  if delete_all == true
    payload = { delete_all: delete_all }
  else
    payload = { emails: emails }
  end
  delete(@auth, SpamReports.url, nil, payload, &block)
end

#get_spam_report(email:, &block) ⇒ Object



50
51
52
53
# File 'lib/sendgrid4r/rest/spam_reports.rb', line 50

def get_spam_report(email:, &block)
  resp = get(@auth, SpamReports.url(email), &block)
  finish(resp, @raw_resp) { |r| SpamReports.create_spam_reports(r) }
end

#get_spam_reports(start_time: nil, end_time: nil, limit: nil, offset: nil, &block) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/sendgrid4r/rest/spam_reports.rb', line 29

def get_spam_reports(
  start_time: nil, end_time: nil, limit: nil, offset: nil, &block
)
  params = {}
  params[:start_time] = start_time.to_i unless start_time.nil?
  params[:end_time] = end_time.to_i unless end_time.nil?
  params[:limit] = limit.to_i unless limit.nil?
  params[:offset] = offset.to_i unless offset.nil?
  resp = get(@auth, SpamReports.url, params, &block)
  finish(resp, @raw_resp) { |r| SpamReports.create_spam_reports(r) }
end