Class: MailerLite::Automations

Inherits:
Object
  • Object
show all
Defined in:
lib/mailerlite/automations/automations.rb

Overview

This is a class for manipulating the Automation from MailerLite API.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client: MailerLite::Client.new) ⇒ Automations

Inits the ‘Automations` class with the specified `client`.

Parameters:

  • client (MailerLite::Client) (defaults to: MailerLite::Client.new)

    the ‘Client` instance to use



11
12
13
# File 'lib/mailerlite/automations/automations.rb', line 11

def initialize(client: MailerLite::Client.new)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/mailerlite/automations/automations.rb', line 6

def client
  @client
end

Instance Method Details

#fetch(automation_id) ⇒ HTTP::Response

fetch the specified Automation

Parameters:

  • automation_id (String)

    the ID of the Automation to fetch

Returns:

  • (HTTP::Response)

    the response from the API



37
38
39
# File 'lib/mailerlite/automations/automations.rb', line 37

def fetch(automation_id)
  client.http.get("#{MAILERLITE_API_URL}/automations/#{automation_id}")
end

#get(limit: nil, page: nil, filter: {}) ⇒ HTTP::Response

Returns a list of Automations that match the specified filter criteria.

Parameters:

  • filter (:status, :name, :group) (defaults to: {})
    Array

    filters for automation

  • limit (Integer) (defaults to: nil)

    the maximum number of Automations to return

  • page (Integer) (defaults to: nil)

    the page number of the results to return

Returns:

  • (HTTP::Response)

    the response from the API



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mailerlite/automations/automations.rb', line 21

def get(limit: nil, page: nil, filter: {})
  params = {}
  params['filter[status]'] = filter[:status] if filter.key?(:status)
  params['filter[name]'] = filter[:name] if filter.key?(:name)
  params['filter[group]'] = filter[:group] if filter.key?(:group)
  params['limit'] = limit if limit
  params['page'] = page if page
  uri = URI("#{MAILERLITE_API_URL}/automations")
  uri.query = URI.encode_www_form(params.compact)
  client.http.get(uri)
end

#get_subscriber_activity(automation_id:, filter: {}, page: nil, limit: nil) ⇒ HTTP::Response

get_subscriber_activity the subscriber activity for specified Automation

Parameters:

  • automation_id (Integer)

    the ID of the Automation to get_subscriber_activity

  • filter (:status, :date_from, :date_to, :scheduled_from, :scheduled_to, :keyword) (defaults to: {})
    Array

    Must be one of the following: completed, active, canceled, failed

  • limit (Integer) (defaults to: nil)

    the maximum number of Automations to return

  • page (Integer) (defaults to: nil)

    the page number of the results to return

Returns:

  • (HTTP::Response)

    the response from the API



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/mailerlite/automations/automations.rb', line 48

def get_subscriber_activity(automation_id:, filter: {}, page: nil, limit: nil)
  params = { 'filter[status]' => filter[:status] }
  params['filter[date_from]'] = filter[:date_from] if filter.key?(:date_from)
  params['filter[date_to]'] = filter[:date_to] if filter.key?(:date_to)
  params['filter[scheduled_from]'] = filter[:scheduled_from] if filter.key?(:scheduled_from)
  params['filter[scheduled_to]'] = filter[:scheduled_to] if filter.key?(:scheduled_to)
  params['filter[keyword]'] = filter[:keyword] if filter.key?(:keyword)
  params['page'] = page if page
  params['limit'] = limit if limit
  uri = URI("#{MAILERLITE_API_URL}/automations/#{automation_id}/activity")
  uri.query = URI.encode_www_form(params.compact)
  client.http.get(uri)
end