mailerlite-ruby 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.envrc +2 -0
  3. data/.github/workflows/main.yml +1 -1
  4. data/.github/workflows/publish_gem.yml +1 -1
  5. data/.gitignore +2 -1
  6. data/CHANGELOG.md +17 -0
  7. data/README.md +574 -0
  8. data/flake.lock +27 -0
  9. data/flake.nix +25 -0
  10. data/lefthook.yml +14 -0
  11. data/lib/mailerlite/api_response.rb +24 -0
  12. data/lib/mailerlite/automations/automation_emails.rb +57 -0
  13. data/lib/mailerlite/automations/automation_reports.rb +114 -0
  14. data/lib/mailerlite/automations/automation_steps.rb +105 -0
  15. data/lib/mailerlite/automations/automation_templates.rb +34 -0
  16. data/lib/mailerlite/automations/automation_triggers.rb +62 -0
  17. data/lib/mailerlite/automations/automations.rb +177 -8
  18. data/lib/mailerlite/brand_styles/brand_styles.rb +24 -0
  19. data/lib/mailerlite/campaigns/campaigns.rb +33 -1
  20. data/lib/mailerlite/ecommerce/ecommerce.rb +316 -0
  21. data/lib/mailerlite/emails/emails.rb +306 -0
  22. data/lib/mailerlite/errors.rb +88 -0
  23. data/lib/mailerlite/files/files.rb +45 -0
  24. data/lib/mailerlite/groups/groups.rb +16 -8
  25. data/lib/mailerlite/params.rb +58 -0
  26. data/lib/mailerlite/query_params.rb +33 -0
  27. data/lib/mailerlite/request.rb +24 -0
  28. data/lib/mailerlite/segments/segments.rb +10 -10
  29. data/lib/mailerlite/subscribers/subscribers.rb +63 -8
  30. data/lib/mailerlite/version.rb +1 -1
  31. data/lib/mailerlite.rb +14 -0
  32. data/spec/api_response_rspec.rb +140 -0
  33. data/spec/automation_emails_rspec.rb +40 -0
  34. data/spec/automation_reports_rspec.rb +92 -0
  35. data/spec/automation_steps_rspec.rb +76 -0
  36. data/spec/automation_templates_rspec.rb +24 -0
  37. data/spec/automation_triggers_rspec.rb +48 -0
  38. data/spec/automations_rspec.rb +143 -0
  39. data/spec/brand_styles_rspec.rb +49 -0
  40. data/spec/campaigns_rspec.rb +42 -0
  41. data/spec/ecommerce_rspec.rb +141 -0
  42. data/spec/emails_rspec.rb +692 -0
  43. data/spec/files_rspec.rb +90 -0
  44. data/spec/fixtures/brand_styles.json +50 -0
  45. data/spec/fixtures/campaign_simple_editor.json +24 -0
  46. data/spec/fixtures/email.json +81 -0
  47. data/spec/fixtures/email_block.json +12 -0
  48. data/spec/fixtures/email_block_created.json +12 -0
  49. data/spec/fixtures/email_block_created_rejected.json +15 -0
  50. data/spec/fixtures/email_block_moved.json +12 -0
  51. data/spec/fixtures/email_block_updated.json +9 -0
  52. data/spec/fixtures/email_block_updated_rejected.json +13 -0
  53. data/spec/fixtures/email_block_validation_invalid.json +5 -0
  54. data/spec/fixtures/email_etag.json +1 -0
  55. data/spec/fixtures/email_html.json +1 -0
  56. data/spec/fixtures/email_settings.json +111 -0
  57. data/spec/fixtures/email_settings_validation.json +9 -0
  58. data/spec/fixtures/email_template.json +1 -0
  59. data/spec/fixtures/email_version.json +1 -0
  60. data/spec/fixtures/email_versions.json +26 -0
  61. data/spec/fixtures/files.json +44 -0
  62. data/spec/groups_rspec.rb +21 -0
  63. data/spec/params_rspec.rb +126 -0
  64. data/spec/request_rspec.rb +139 -0
  65. data/spec/segments_rspec.rb +39 -0
  66. data/spec/spec_helper.rb +1 -0
  67. data/spec/subscribers_rspec.rb +57 -0
  68. data/spec/support/json_fixture.rb +27 -0
  69. data/spec/support/request_stub.rb +25 -0
  70. metadata +54 -7
  71. /data/{renovate.json → .github/renovate.json} +0 -0
data/flake.lock ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "nodes": {
3
+ "nixpkgs": {
4
+ "locked": {
5
+ "lastModified": 1789546076,
6
+ "narHash": "sha256-zVxLZiSnmaaPLwnhj7pwmqe3axBg/C6nG5JZsJMh2g4=",
7
+ "owner": "NixOS",
8
+ "repo": "nixpkgs",
9
+ "rev": "b1b875982b17dabde9b4a37f3e229e74913e6db3",
10
+ "type": "github"
11
+ },
12
+ "original": {
13
+ "owner": "NixOS",
14
+ "ref": "nixos-unstable",
15
+ "repo": "nixpkgs",
16
+ "type": "github"
17
+ }
18
+ },
19
+ "root": {
20
+ "inputs": {
21
+ "nixpkgs": "nixpkgs"
22
+ }
23
+ }
24
+ },
25
+ "root": "root",
26
+ "version": 7
27
+ }
data/flake.nix ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ description = "MailerLite Go SDK environment";
3
+
4
+ inputs = {
5
+ nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6
+ };
7
+
8
+ outputs = { self, nixpkgs }:
9
+ let
10
+ systems = [ "aarch64-darwin" "x86_64-darwin" "aarch64-linux" "x86_64-linux" ];
11
+ forEachSystem = f:
12
+ nixpkgs.lib.genAttrs systems (system: f system nixpkgs.legacyPackages.${system});
13
+ in
14
+ {
15
+ devShells = forEachSystem (system: pkgs: {
16
+ default = pkgs.mkShell {
17
+ packages = with pkgs; [
18
+ lefthook
19
+ gitleaks
20
+ git-secrets
21
+ ];
22
+ };
23
+ });
24
+ };
25
+ }
data/lefthook.yml ADDED
@@ -0,0 +1,14 @@
1
+ ---
2
+ pre-commit:
3
+ commands:
4
+ gitleaks:
5
+ run: gitleaks git --pre-commit --redact --staged --verbose --no-banner
6
+ fail_text: Staged changes contain a secret. Remove it; never commit and revert.
7
+ secrets:
8
+ run: |
9
+ git secrets --list | grep -q 'mssp' || {
10
+ git secrets --register-aws
11
+ git secrets --add 'mlsn\.[A-Za-z0-9._-]+'
12
+ git secrets --add 'mssp\.[A-Za-z0-9._-]+'
13
+ }
14
+ git secrets --scan {staged_files}
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MailerLite
4
+ # Helpers that `Emails`, `BrandStyles` and `Files` add to each `HTTP::Response` that they return.
5
+ #
6
+ # The response is still an `HTTP::Response`. Use `response.code` for the status code,
7
+ # `response.headers` for the headers and `response.parse` for the decoded body.
8
+ module ApiResponse
9
+ # Returns true if the API returned the stored response of an earlier request with the same idempotency key.
10
+ #
11
+ # @return [Boolean] true if the `Idempotent-Replayed` header is "true"
12
+ def idempotent_replay?
13
+ # A proxy can change the case of the value, or send the header two times.
14
+ headers.get('Idempotent-Replayed').any? { |value| value.strip.casecmp?('true') }
15
+ end
16
+
17
+ # Returns the error of the response.
18
+ #
19
+ # @return [MailerLite::ApiError, nil] nil for a 2xx status, otherwise an error that you can raise
20
+ def api_error
21
+ status.success? ? nil : ApiError.from_response(self)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MailerLite
4
+ # This is a class for manipulating the Automation emails from MailerLite API.
5
+ class AutomationEmails
6
+ attr_reader :client
7
+
8
+ # Inits the `AutomationEmails` class with the specified `client`.
9
+ #
10
+ # @param client [MailerLite::Client] the `Client` instance to use
11
+ def initialize(client: MailerLite::Client.new)
12
+ @client = client
13
+ end
14
+
15
+ # Returns the HTML content of the specified email
16
+ #
17
+ # @param automation_id [String] the ID of the Automation
18
+ # @param email_id [String] the ID of the email
19
+ # @return [HTTP::Response] the response from the API
20
+ def content(automation_id:, email_id:)
21
+ client.http.get("#{MAILERLITE_API_URL}/automations/#{automation_id}/emails/#{email_id}/content")
22
+ end
23
+
24
+ # Updates the HTML content of the specified email
25
+ #
26
+ # @param automation_id [String] the ID of the Automation
27
+ # @param email_id [String] the ID of the email
28
+ # @param html [String] the new HTML content
29
+ # @return [HTTP::Response] the response from the API
30
+ def update_content(automation_id:, email_id:, html:)
31
+ client.http.put("#{MAILERLITE_API_URL}/automations/#{automation_id}/emails/#{email_id}/content", json: { 'html' => html })
32
+ end
33
+
34
+ # Returns the report stats of the specified email
35
+ #
36
+ # @param automation_id [String] the ID of the Automation
37
+ # @param email_id [String] the ID of the email
38
+ # @param start_date [String] the first day, together with end_date
39
+ # @param end_date [String] the last day, included
40
+ # @param shop_id [String] report on one shop only, e-commerce figures only
41
+ # @param excel [Boolean] only used by export endpoints
42
+ # @return [HTTP::Response] the response from the API
43
+ def report_stats(automation_id:, email_id:, start_date: nil, end_date: nil, shop_id: nil, excel: nil)
44
+ params = QueryParams.report(start_date: start_date, end_date: end_date, shop_id: shop_id, excel: excel)
45
+ client.http.get(QueryParams.uri("#{MAILERLITE_API_URL}/automations/#{automation_id}/emails/#{email_id}/report-stats", params))
46
+ end
47
+
48
+ # Returns the reasons subscribers gave for unsubscribing from the specified email
49
+ #
50
+ # @param automation_id [String] the ID of the Automation
51
+ # @param email_id [String] the ID of the email
52
+ # @return [HTTP::Response] the response from the API
53
+ def unsubscribe_reasons(automation_id:, email_id:)
54
+ client.http.get("#{MAILERLITE_API_URL}/automations/#{automation_id}/emails/#{email_id}/unsubscribe-reasons")
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,114 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MailerLite
4
+ # This is a class for reading the Automation reports from MailerLite API.
5
+ class AutomationReports
6
+ attr_reader :client
7
+
8
+ # Inits the `AutomationReports` class with the specified `client`.
9
+ #
10
+ # @param client [MailerLite::Client] the `Client` instance to use
11
+ def initialize(client: MailerLite::Client.new)
12
+ @client = client
13
+ end
14
+
15
+ # Returns the run counts of every step of the specified Automation
16
+ #
17
+ # @param automation_id [String] the ID of the Automation
18
+ # @return [HTTP::Response] the response from the API
19
+ def step_run_counts(automation_id)
20
+ client.http.get("#{MAILERLITE_API_URL}/automations/#{automation_id}/steps/run-counts")
21
+ end
22
+
23
+ # Returns the run counts of the specified step
24
+ #
25
+ # @param automation_id [String] the ID of the Automation
26
+ # @param step_id [String] the ID of the step
27
+ # @return [HTTP::Response] the response from the API
28
+ def step_run_count(automation_id:, step_id:)
29
+ client.http.get("#{MAILERLITE_API_URL}/automations/#{automation_id}/steps/run-counts/#{step_id}")
30
+ end
31
+
32
+ # Returns the run counts of every trigger of the specified Automation
33
+ #
34
+ # @param automation_id [String] the ID of the Automation
35
+ # @return [HTTP::Response] the response from the API
36
+ def trigger_run_counts(automation_id)
37
+ client.http.get("#{MAILERLITE_API_URL}/automations/#{automation_id}/triggers/run-counts")
38
+ end
39
+
40
+ # Returns the run counts of the specified trigger
41
+ #
42
+ # @param automation_id [String] the ID of the Automation
43
+ # @param trigger_id [String] the ID of the trigger
44
+ # @return [HTTP::Response] the response from the API
45
+ def trigger_run_count(automation_id:, trigger_id:)
46
+ client.http.get("#{MAILERLITE_API_URL}/automations/#{automation_id}/triggers/run-counts/#{trigger_id}")
47
+ end
48
+
49
+ # Returns the stats of every A/B test step of the specified Automation
50
+ #
51
+ # @param automation_id [String] the ID of the Automation
52
+ # @return [HTTP::Response] the response from the API
53
+ def ab_steps_stats(automation_id)
54
+ client.http.get("#{MAILERLITE_API_URL}/automations/#{automation_id}/ab-steps-stats")
55
+ end
56
+
57
+ # Returns the stats of the specified A/B test step
58
+ #
59
+ # @param automation_id [String] the ID of the Automation
60
+ # @param step_id [String] the ID of the A/B test step
61
+ # @return [HTTP::Response] the response from the API
62
+ def ab_step_stats(automation_id:, step_id:)
63
+ client.http.get("#{MAILERLITE_API_URL}/automations/#{automation_id}/ab-steps-stats/#{step_id}")
64
+ end
65
+
66
+ # Returns the subscribers who reached the specified step
67
+ #
68
+ # @param automation_id [String] the ID of the Automation
69
+ # @param step_id [String] the ID of the step
70
+ # @param status [String] queued or completed
71
+ # @param filter[:date_from,:date_to,:search,:id] [Hash] filters for the subscribers
72
+ # @param limit [Integer] the maximum number of subscribers to return
73
+ # @param page [Integer] the page number of the results to return
74
+ # @param sort [String] the field to sort by, prefix with - for descending order
75
+ # @return [HTTP::Response] the response from the API
76
+ def step_subscribers(automation_id:, step_id:, status:, filter: {}, limit: nil, page: nil, sort: nil)
77
+ activity_subscribers("#{automation_id}/activity/steps/#{step_id}/subscribers", status: status, filter: filter, limit: limit, page: page, sort: sort)
78
+ end
79
+
80
+ # Returns the subscribers who passed the specified trigger
81
+ #
82
+ # @param automation_id [String] the ID of the Automation
83
+ # @param trigger_id [String] the ID of the trigger
84
+ # @param status [String] queued or completed
85
+ # @param filter[:date_from,:date_to,:search,:id] [Hash] filters for the subscribers
86
+ # @param limit [Integer] the maximum number of subscribers to return
87
+ # @param page [Integer] the page number of the results to return
88
+ # @param sort [String] the field to sort by, prefix with - for descending order
89
+ # @return [HTTP::Response] the response from the API
90
+ def trigger_subscribers(automation_id:, trigger_id:, status:, filter: {}, limit: nil, page: nil, sort: nil)
91
+ activity_subscribers("#{automation_id}/activity/triggers/#{trigger_id}/subscribers", status: status, filter: filter, limit: limit, page: page, sort: sort)
92
+ end
93
+
94
+ # Returns the email totals of the specified Automation per month
95
+ #
96
+ # @param automation_id [String] the ID of the Automation
97
+ # @param start_date [String] the first day, together with end_date
98
+ # @param end_date [String] the last day, included
99
+ # @param shop_id [String] report on one shop only, e-commerce figures only
100
+ # @param excel [Boolean] only used by export endpoints
101
+ # @return [HTTP::Response] the response from the API
102
+ def email_monthly_totals(automation_id:, start_date: nil, end_date: nil, shop_id: nil, excel: nil)
103
+ params = QueryParams.report(start_date: start_date, end_date: end_date, shop_id: shop_id, excel: excel)
104
+ client.http.get(QueryParams.uri("#{MAILERLITE_API_URL}/automations/#{automation_id}/monthly-totals/email", params))
105
+ end
106
+
107
+ private
108
+
109
+ def activity_subscribers(path, status:, filter:, **query)
110
+ params = { 'status' => status, **query.transform_keys(&:to_s) }.merge(QueryParams.filter(filter, %i[date_from date_to search id]))
111
+ client.http.get(QueryParams.uri("#{MAILERLITE_API_URL}/automations/#{path}", params))
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,105 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MailerLite
4
+ # This is a class for manipulating the Automation steps from MailerLite API.
5
+ class AutomationSteps
6
+ attr_reader :client
7
+
8
+ # Inits the `AutomationSteps` class with the specified `client`.
9
+ #
10
+ # @param client [MailerLite::Client] the `Client` instance to use
11
+ def initialize(client: MailerLite::Client.new)
12
+ @client = client
13
+ end
14
+
15
+ # Returns the steps of the specified Automation
16
+ #
17
+ # @param automation_id [String] the ID of the Automation
18
+ # @return [HTTP::Response] the response from the API
19
+ def list(automation_id)
20
+ client.http.get("#{MAILERLITE_API_URL}/automations/#{automation_id}/steps/index")
21
+ end
22
+
23
+ # Adds a step to the specified Automation
24
+ #
25
+ # @param automation_id [String] the ID of the Automation
26
+ # @param type [String] email, condition, delay, action, abtest or webhook
27
+ # @param parent_id [Integer] the ID of the step to add the new step after
28
+ # @param branch [String] the branch of the parent step: yes, no, a_path, b_path or c_path
29
+ # @param move_to_branch [String] the branch of the new step to move the following steps to: yes or no
30
+ # @param data [Hash] the settings of the step
31
+ # @return [HTTP::Response] the response from the API
32
+ def create(automation_id:, type:, parent_id: nil, branch: nil, move_to_branch: nil, data: nil)
33
+ params = { 'type' => type, 'parent_id' => parent_id, 'branch' => branch, 'move_to_branch' => move_to_branch, 'data' => data }
34
+ client.http.post("#{MAILERLITE_API_URL}/automations/#{automation_id}/steps", json: params.compact)
35
+ end
36
+
37
+ # Returns the specified step
38
+ #
39
+ # @param automation_id [String] the ID of the Automation
40
+ # @param step_id [String] the ID of the step
41
+ # @return [HTTP::Response] the response from the API
42
+ def fetch(automation_id:, step_id:)
43
+ client.http.get("#{MAILERLITE_API_URL}/automations/#{automation_id}/steps/#{step_id}")
44
+ end
45
+
46
+ # Updates the specified step
47
+ #
48
+ # @param automation_id [String] the ID of the Automation
49
+ # @param step_id [String] the ID of the step
50
+ # @param parent_id [Integer] the ID of the parent step
51
+ # @param data [Hash] the settings of the step
52
+ # @param reschedule_waiting_subscribers [Boolean] reschedule the subscribers waiting on a delay step
53
+ # @return [HTTP::Response] the response from the API
54
+ def update(automation_id:, step_id:, parent_id: nil, data: nil, reschedule_waiting_subscribers: nil)
55
+ params = { 'parent_id' => parent_id, 'data' => data, 'reschedule_waiting_subscribers' => reschedule_waiting_subscribers }
56
+ client.http.put("#{MAILERLITE_API_URL}/automations/#{automation_id}/steps/#{step_id}", json: params.compact)
57
+ end
58
+
59
+ # Deletes the specified step
60
+ #
61
+ # @param automation_id [String] the ID of the Automation
62
+ # @param step_id [String] the ID of the step
63
+ # @param branch_to_delete [String] all, yes or no for a condition step; all, a_path, b_path or c_path for an A/B test step
64
+ # @return [HTTP::Response] the response from the API
65
+ def delete(automation_id:, step_id:, branch_to_delete: nil)
66
+ client.http.delete(QueryParams.uri("#{MAILERLITE_API_URL}/automations/#{automation_id}/steps/#{step_id}", { 'branch_to_delete' => branch_to_delete }))
67
+ end
68
+
69
+ # Copies the specified step
70
+ #
71
+ # @param automation_id [String] the ID of the Automation
72
+ # @param step_id [String] the ID of the step to copy
73
+ # @param parent_id [Integer] the ID of the step to add the copy after
74
+ # @param branch [String] the branch of the parent step: yes, no, a_path, b_path or c_path
75
+ # @param move_to_branch [String] the branch of the copy to move the following steps to: yes or no
76
+ # @return [HTTP::Response] the response from the API
77
+ def copy(automation_id:, step_id:, parent_id: nil, branch: nil, move_to_branch: nil)
78
+ params = { 'parent_id' => parent_id, 'branch' => branch, 'move_to_branch' => move_to_branch }
79
+ client.http.post("#{MAILERLITE_API_URL}/automations/#{automation_id}/steps/#{step_id}/copy", json: params.compact)
80
+ end
81
+
82
+ # Moves a step to another place in the specified Automation
83
+ #
84
+ # @param automation_id [String] the ID of the Automation
85
+ # @param dragged_step_id [Integer] the ID of the step to move
86
+ # @param new_parent_step_id [Integer] the ID of the step to move it after
87
+ # @param branch [String] the branch of the new parent step: yes, no, a_path, b_path or c_path
88
+ # @param branch_for_child [String] the branch of the moved step to attach the following steps to: yes or no
89
+ # @return [HTTP::Response] the response from the API
90
+ def reorder(automation_id:, dragged_step_id:, new_parent_step_id: nil, branch: nil, branch_for_child: nil)
91
+ params = { 'dragged_step_id' => dragged_step_id, 'new_parent_step_id' => new_parent_step_id, 'branch' => branch, 'branch_for_child' => branch_for_child }
92
+ client.http.post("#{MAILERLITE_API_URL}/automations/#{automation_id}/steps/reorder", json: params.compact)
93
+ end
94
+
95
+ # Selects the winning path of the specified A/B test step
96
+ #
97
+ # @param automation_id [String] the ID of the Automation
98
+ # @param step_id [String] the ID of the A/B test step
99
+ # @param ab_test_winner [String] a_path, b_path or c_path
100
+ # @return [HTTP::Response] the response from the API
101
+ def select_ab_test_winner(automation_id:, step_id:, ab_test_winner:)
102
+ client.http.put("#{MAILERLITE_API_URL}/automations/#{automation_id}/steps/#{step_id}/select-ab-test-winner", json: { 'ab_test_winner' => ab_test_winner })
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MailerLite
4
+ # This is a class for manipulating the Automation templates from MailerLite API.
5
+ class AutomationTemplates
6
+ attr_reader :client
7
+
8
+ # Inits the `AutomationTemplates` class with the specified `client`.
9
+ #
10
+ # @param client [MailerLite::Client] the `Client` instance to use
11
+ def initialize(client: MailerLite::Client.new)
12
+ @client = client
13
+ end
14
+
15
+ # Returns a list of Automation templates that match the specified filter criteria.
16
+ #
17
+ # @param filter[:type,:category] [Hash] filters for the templates
18
+ # @param limit [Integer] the maximum number of templates to return
19
+ # @param page [Integer] the page number of the results to return
20
+ # @return [HTTP::Response] the response from the API
21
+ def list(filter: {}, limit: nil, page: nil)
22
+ params = QueryParams.filter(filter, %i[type category]).merge('limit' => limit, 'page' => page)
23
+ client.http.get(QueryParams.uri("#{MAILERLITE_API_URL}/automation-templates", params))
24
+ end
25
+
26
+ # Creates an Automation from the specified template
27
+ #
28
+ # @param template_id [String] the ID of the Automation template
29
+ # @return [HTTP::Response] the response from the API
30
+ def select_template(template_id)
31
+ client.http.post("#{MAILERLITE_API_URL}/automations/select-template/#{template_id}")
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MailerLite
4
+ # This is a class for manipulating the Automation triggers from MailerLite API.
5
+ class AutomationTriggers
6
+ attr_reader :client
7
+
8
+ # Inits the `AutomationTriggers` class with the specified `client`.
9
+ #
10
+ # @param client [MailerLite::Client] the `Client` instance to use
11
+ def initialize(client: MailerLite::Client.new)
12
+ @client = client
13
+ end
14
+
15
+ # Returns the triggers of the specified Automation
16
+ #
17
+ # @param automation_id [String] the ID of the Automation
18
+ # @return [HTTP::Response] the response from the API
19
+ def list(automation_id)
20
+ client.http.get("#{MAILERLITE_API_URL}/automations/#{automation_id}/triggers")
21
+ end
22
+
23
+ # Adds a trigger to the specified Automation
24
+ #
25
+ # @param automation_id [String] the ID of the Automation
26
+ # @param type [String] the trigger type, for example subscriber_joins_group
27
+ # @param data [Hash] the settings of the trigger
28
+ # @return [HTTP::Response] the response from the API
29
+ def create(automation_id:, type:, data: nil)
30
+ params = { 'type' => type, 'data' => data }
31
+ client.http.post("#{MAILERLITE_API_URL}/automations/#{automation_id}/triggers", json: params.compact)
32
+ end
33
+
34
+ # Returns the specified trigger
35
+ #
36
+ # @param automation_id [String] the ID of the Automation
37
+ # @param trigger_id [String] the ID of the trigger
38
+ # @return [HTTP::Response] the response from the API
39
+ def fetch(automation_id:, trigger_id:)
40
+ client.http.get("#{MAILERLITE_API_URL}/automations/#{automation_id}/triggers/#{trigger_id}")
41
+ end
42
+
43
+ # Updates the specified trigger
44
+ #
45
+ # @param automation_id [String] the ID of the Automation
46
+ # @param trigger_id [String] the ID of the trigger
47
+ # @param data [Hash] the settings of the trigger
48
+ # @return [HTTP::Response] the response from the API
49
+ def update(automation_id:, trigger_id:, data:)
50
+ client.http.put("#{MAILERLITE_API_URL}/automations/#{automation_id}/triggers/#{trigger_id}", json: { 'data' => data })
51
+ end
52
+
53
+ # Deletes the specified trigger
54
+ #
55
+ # @param automation_id [String] the ID of the Automation
56
+ # @param trigger_id [String] the ID of the trigger
57
+ # @return [HTTP::Response] the response from the API
58
+ def delete(automation_id:, trigger_id:)
59
+ client.http.delete("#{MAILERLITE_API_URL}/automations/#{automation_id}/triggers/#{trigger_id}")
60
+ end
61
+ end
62
+ end