-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/add rules #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,17 @@ | ||
| source 'https://rubygems.org' | ||
|
|
||
| group :development do | ||
| gem 'bundler', '>= 2.2' | ||
| gem'dotenv', '~> 2.7.0' | ||
| gem'pry', '~> 0.14.0' | ||
| gem'rails' | ||
| gem'rake', '~> 13.0.0' | ||
| gem'rspec', '~> 3.10.0' | ||
| gem'rubocop', '~> 1.11.0' | ||
| gem'rubocop-rspec', '~> 2.2.0' | ||
| gem'simplecov', '~> 0.21.0' | ||
| gem'vcr', '~> 6.0.0' | ||
| gem'webmock', '~> 3.12.0' | ||
| gem 'bundler', '>= 2.5' | ||
| gem 'dotenv', '~> 3.1' | ||
| gem 'pry', '~> 0.14.2' | ||
| gem 'rails' | ||
| gem 'rake', '~> 13.2' | ||
| gem 'rspec', '~> 3.13' | ||
| gem 'rubocop', '~> 1.69' | ||
| gem 'rubocop-rspec', '~> 3.2' | ||
| gem 'simplecov', '~> 0.22' | ||
| gem 'vcr', '~> 6.3' | ||
| gem 'webmock', '~> 3.24' | ||
| end | ||
|
|
||
| gemspec |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| module Improvmx | ||
| # All rule related endpoints | ||
| module Rules | ||
| # List all rules for a domain | ||
| # @param domain [String] The domain name | ||
| # @param params [Hash] Optional parameters (search, page) | ||
| # @return [Hash] Response containing rules array | ||
| def list_rules(domain, params = {}) | ||
| get("/domains/#{domain}/rules/", params).to_h | ||
| end | ||
|
|
||
| # Get a specific rule | ||
| # @param rule_id [String] The rule ID (UUID) | ||
| # @param domain [String] The domain name | ||
| # @return [Hash, nil] The rule object or nil if not found | ||
| def get_rule(rule_id, domain) | ||
| get("/domains/#{domain}/rules/#{rule_id}").to_h | ||
| rescue NotFoundError | ||
| nil | ||
| end | ||
|
|
||
| # Create an alias rule | ||
| # @param domain [String] The domain name | ||
| # @param alias_name [String] The alias (e.g., "richard") | ||
| # @param forward_to [String, Array] Destination email(s) | ||
| # @param rank [Float, nil] Optional rank for evaluation priority | ||
| # @param active [Boolean] Whether the rule is active (default: true) | ||
| # @param id [String, nil] Optional custom rule ID | ||
| # @return [Hash] The created rule | ||
| def create_alias_rule(domain, alias_name, forward_to, rank: nil, active: true, id: nil) | ||
| data = { | ||
| type: 'alias', | ||
| config: { | ||
| alias: alias_name, | ||
| forward: forward(forward_to) | ||
| }, | ||
| active: active | ||
| } | ||
| data[:rank] = rank if rank | ||
| data[:id] = id if id | ||
|
|
||
| response = post("/domains/#{domain}/rules/", data) | ||
| response.to_h['rule'] | ||
| end | ||
|
|
||
| # Create a regex rule | ||
| # @param domain [String] The domain name | ||
| # @param regex [String] The regular expression pattern | ||
| # @param scopes [Array<String>] Scopes to match (sender, recipient, subject, body) | ||
| # @param forward_to [String, Array] Destination email(s) | ||
| # @param rank [Float, nil] Optional rank for evaluation priority | ||
| # @param active [Boolean] Whether the rule is active (default: true) | ||
| # @param id [String, nil] Optional custom rule ID | ||
| # @return [Hash] The created rule | ||
| def create_regex_rule(domain, regex, scopes, forward_to, rank: nil, active: true, id: nil) | ||
| data = { | ||
| type: 'regex', | ||
| config: { | ||
| regex: regex, | ||
| scopes: scopes, | ||
| forward: forward(forward_to) | ||
| }, | ||
| active: active | ||
| } | ||
| data[:rank] = rank if rank | ||
| data[:id] = id if id | ||
|
|
||
| response = post("/domains/#{domain}/rules/", data) | ||
| response.to_h['rule'] | ||
| end | ||
|
Comment on lines
+55
to
+70
|
||
|
|
||
| # Create a CEL rule | ||
| # @param domain [String] The domain name | ||
| # @param expression [String] The CEL expression | ||
| # @param forward_to [String, Array] Destination email(s) | ||
| # @param rank [Float, nil] Optional rank for evaluation priority | ||
| # @param active [Boolean] Whether the rule is active (default: true) | ||
| # @param id [String, nil] Optional custom rule ID | ||
| # @return [Hash] The created rule | ||
| def create_cel_rule(domain, expression, forward_to, rank: nil, active: true, id: nil) | ||
| data = { | ||
| type: 'cel', | ||
| config: { | ||
| expression: expression, | ||
| forward: forward(forward_to) | ||
| }, | ||
| active: active | ||
| } | ||
| data[:rank] = rank if rank | ||
| data[:id] = id if id | ||
|
|
||
| response = post("/domains/#{domain}/rules/", data) | ||
| response.to_h['rule'] | ||
| end | ||
|
Comment on lines
+80
to
+94
|
||
|
|
||
| # Update a rule | ||
| # @param rule_id [String] The rule ID | ||
| # @param domain [String] The domain name | ||
| # @param config [Hash] The config object for the rule | ||
| # @param rank [Float, nil] Optional new rank | ||
| # @param active [Boolean, nil] Optional active state | ||
| # @return [Hash, false] The updated rule or false if not found | ||
| def update_rule(rule_id, domain, config: nil, rank: nil, active: nil) | ||
| data = {} | ||
| data[:config] = config if config | ||
| data[:rank] = rank if rank | ||
| data[:active] = active unless active.nil? | ||
|
|
||
| response = put("/domains/#{domain}/rules/#{rule_id}", data) | ||
| response.to_h['rule'] | ||
| rescue NotFoundError | ||
| false | ||
| end | ||
|
Comment on lines
+103
to
+113
|
||
|
|
||
| # Delete a rule | ||
| # @param rule_id [String] The rule ID | ||
| # @param domain [String] The domain name | ||
| # @return [Boolean] true if deleted or not found | ||
| def delete_rule(rule_id, domain) | ||
| response = delete("/domains/#{domain}/rules/#{rule_id}") | ||
| response.ok? | ||
| rescue NotFoundError | ||
| true | ||
| end | ||
|
|
||
| # Delete all rules for a domain | ||
| # @param domain [String] The domain name | ||
| # @return [Boolean] true if successful | ||
| def delete_all_rules(domain) | ||
| response = delete("/domains/#{domain}/rules-all") | ||
| response.ok? | ||
| end | ||
|
|
||
| # Bulk modify rules | ||
| # @param domain [String] The domain name | ||
| # @param rules [Array<Hash>] Array of rule objects | ||
| # @param behavior [String] 'add', 'update', or 'delete' (default: 'add') | ||
| # @return [Hash] Results of bulk operation | ||
| def bulk_modify_rules(domain, rules, behavior: 'add') | ||
| data = { | ||
| rules: rules, | ||
| behavior: behavior | ||
| } | ||
|
Comment on lines
+139
to
+143
|
||
|
|
||
| response = post("/domains/#{domain}/rules/bulk", data) | ||
| response.to_h | ||
| end | ||
|
Comment on lines
+139
to
+147
|
||
| end | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parameter order is inconsistent with the existing codebase patterns. Looking at the aliases module, the pattern used is create_alias(alias_name, forward_to, domain) where the resource identifier comes first, then the data, then the domain. However, this method has create_alias_rule(domain, alias_name, forward_to, ...) with domain first. For consistency, consider reordering parameters to match the existing pattern: create_alias_rule(alias_name, forward_to, domain, rank: nil, active: true, id: nil).