Class: Sendgrid::Web::Unsubscribes

Inherits:
Client
  • Object
show all
Defined in:
lib/sendgrid/web/unsubscribes.rb

Instance Method Summary collapse

Methods inherited from Client

base_uri, config, #config, configure

Instance Method Details

#add(email: nil) ⇒ Sendgrid::Web::Response

Note:

email is a required parameter.

Add email addresses to the Unsubscribe list.

Parameters:

  • email (String) (defaults to: nil)

    Email address to add to unsubscribe list.

Returns:



60
61
62
63
64
65
66
67
68
# File 'lib/sendgrid/web/unsubscribes.rb', line 60

def add(email: nil)
  if email.nil?
    raise ArgumentError.new('Missing required `email` option')
  end
  res = connection.post(
    '/api/unsubscribes.add.json',
    default_params(email: email))
  craft_response(res)
end

#delete(start_date: nil, end_date: nil, email: nil) ⇒ Sendgrid::Web::Response

Note:

If no parameters are provided the ENTIRE list will be removed.

Delete an address from the Unsubscribe list.

Parameters:

  • start_date (DateTime) (defaults to: nil)

    Optional date to start retrieving for.

  • end_date (DateTime) (defaults to: nil)

    Optional date to end retrieving for.

  • email (String) (defaults to: nil)

    Unsubscribed email address to remove.

Returns:



44
45
46
47
48
49
50
51
52
53
# File 'lib/sendgrid/web/unsubscribes.rb', line 44

def delete(
  start_date: nil, end_date: nil, email: nil)
  res = connection.post(
    '/api/unsubscribes.delete.json',
    default_params(
      start_date: start_date,
      end_date: end_date,
      email: email))
  craft_response(res)
end

#get(date: nil, days: nil, start_date: nil, end_date: nil, limit: nil, offset: nil) ⇒ Sendgrid::Web::Response

Note:

All parameters are optional.

Retrieve a list of Unsubscribes with addresses and optionally with dates.

Parameters:

  • date (Integer) (defaults to: nil)

    Retrieve the timestamp of the unsubscribe records.

  • days (Integer) (defaults to: nil)

    Number of days in the past for which to retrieve unsubscribe records (includes today).

  • start_date (DateTime) (defaults to: nil)

    The start of the date range for which to retrieve unsubscribe records.

  • end_date (DateTime) (defaults to: nil)

    The end of the date range for which to retrieve unsubscribe records.

  • limit (Integer) (defaults to: nil)

    Optional field to limit the number of results returned.

  • offset (Integer) (defaults to: nil)

    Optional beginning point in the list to retrieve from.

Returns:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/sendgrid/web/unsubscribes.rb', line 20

def get(
  date: nil, days: nil, start_date: nil,
  end_date: nil, limit: nil, offset: nil)
  res = connection.post(
    '/api/unsubscribes.get.json',
    default_params(
      date: date,
      days: days,
      start_date: start_date,
      end_date: end_date,
      limit: limit,
      offset: offset))
  craft_response(res)
end