Class: MailerLite::Automations
- Inherits:
-
Object
- Object
- MailerLite::Automations
- Defined in:
- lib/mailerlite/automations/automations.rb
Overview
This is a class for manipulating the Automation from MailerLite API.
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#fetch(automation_id) ⇒ HTTP::Response
fetch the specified Automation.
-
#get(limit: nil, page: nil, filter: {}) ⇒ HTTP::Response
Returns a list of Automations that match the specified filter criteria.
-
#get_subscriber_activity(automation_id:, filter: {}, page: nil, limit: nil) ⇒ HTTP::Response
get_subscriber_activity the subscriber activity for specified Automation.
-
#initialize(client: MailerLite::Client.new) ⇒ Automations
constructor
Inits the ‘Automations` class with the specified `client`.
Constructor Details
#initialize(client: MailerLite::Client.new) ⇒ Automations
Inits the ‘Automations` class with the specified `client`.
11 12 13 |
# File 'lib/mailerlite/automations/automations.rb', line 11 def initialize(client: MailerLite::Client.new) @client = client end |
Instance Attribute Details
#client ⇒ Object (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
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.
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
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 |