-
Notifications
You must be signed in to change notification settings - Fork 39
feat: Configurable import strict mode and max import message count #56
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
src/main/java/com/mixpanel/mixpanelapi/DeliveryOptions.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| package com.mixpanel.mixpanelapi; | ||
|
|
||
| /** | ||
| * Options for configuring how messages are delivered to Mixpanel. | ||
| * Use the {@link Builder} to create instances. | ||
| * | ||
| * <p>Different options apply to different message types: | ||
| * <ul> | ||
| * <li>{@code importStrictMode} - Only applies to import messages</li> | ||
| * <li>{@code useIpAddress} - Only applies to events, people, and groups messages (NOT imports)</li> | ||
| * </ul> | ||
| * | ||
| * <p>Example usage: | ||
| * <pre>{@code | ||
| * DeliveryOptions options = new DeliveryOptions.Builder() | ||
| * .importStrictMode(false) // Disable strict validation for imports | ||
| * .useIpAddress(true) // Use IP address for geolocation (events/people/groups only) | ||
| * .build(); | ||
| * | ||
| * mixpanelApi.deliver(delivery, options); | ||
| * }</pre> | ||
| */ | ||
| public class DeliveryOptions { | ||
|
|
||
| private final boolean mImportStrictMode; | ||
| private final boolean mUseIpAddress; | ||
|
|
||
| private DeliveryOptions(Builder builder) { | ||
| mImportStrictMode = builder.importStrictMode; | ||
| mUseIpAddress = builder.useIpAddress; | ||
| } | ||
|
|
||
| /** | ||
| * Returns whether strict mode is enabled for import messages. | ||
| * | ||
| * <p><strong>Note:</strong> This option only applies to import messages (historical events). | ||
| * It has no effect on regular events, people, or groups messages. | ||
| * | ||
| * <p>When strict mode is enabled (default), the /import endpoint validates each event | ||
| * and returns a 400 error if any event has issues. Correctly formed events are still | ||
| * ingested, and problematic events are returned in the response with error messages. | ||
| * | ||
| * <p>When strict mode is disabled, validation is bypassed and all events are imported | ||
| * regardless of their validity. | ||
| * | ||
| * @return true if strict mode is enabled for imports, false otherwise | ||
| */ | ||
| public boolean isImportStrictMode() { | ||
| return mImportStrictMode; | ||
| } | ||
|
|
||
| /** | ||
| * Returns whether the IP address should be used for geolocation. | ||
| * | ||
| * <p><strong>Note:</strong> This option only applies to events, people, and groups messages. | ||
| * It does NOT apply to import messages, which use Basic Auth and don't support the ip parameter. | ||
| * | ||
| * @return true if IP address should be used for geolocation, false otherwise | ||
| */ | ||
| public boolean useIpAddress() { | ||
| return mUseIpAddress; | ||
| } | ||
|
|
||
| /** | ||
| * Builder for creating {@link DeliveryOptions} instances. | ||
| */ | ||
| public static class Builder { | ||
| private boolean importStrictMode = true; | ||
| private boolean useIpAddress = false; | ||
|
|
||
| /** | ||
| * Sets whether to use strict mode for import messages. | ||
| * | ||
| * will validate the supplied events and return a 400 status code if any of the events fail validation with details of the error | ||
| * | ||
| * <p>Setting this value to true (default) will validate the supplied events and return | ||
| * a 400 status code if any of the events fail validation with details of the error. | ||
| * Setting this value to false disables validation. | ||
| * | ||
| * @param importStrictMode true to enable strict validation (default), false to disable | ||
| * @return this Builder instance for method chaining | ||
| */ | ||
| public Builder importStrictMode(boolean importStrictMode) { | ||
| this.importStrictMode = importStrictMode; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Sets whether to use the IP address for geolocation. | ||
| * | ||
| * <p><strong>Note:</strong> This option only applies to events, people, and groups messages. | ||
| * It does NOT apply to import messages. | ||
| * | ||
| * <p>When enabled, Mixpanel will use the IP address of the request to set | ||
| * geolocation properties on events and profiles. | ||
| * | ||
| * @param useIpAddress true to use IP address for geolocation, false otherwise (default) | ||
| * @return this Builder instance for method chaining | ||
| */ | ||
| public Builder useIpAddress(boolean useIpAddress) { | ||
| this.useIpAddress = useIpAddress; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Builds and returns a new {@link DeliveryOptions} instance. | ||
| * | ||
| * @return a new DeliveryOptions with the configured settings | ||
| */ | ||
| public DeliveryOptions build() { | ||
| return new DeliveryOptions(this); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This line appears to be a leftover fragment from editing. It's not formatted as a proper JavaDoc comment (missing
<p>tag or proper punctuation) and duplicates the content of the following line. Remove this line as the complete description starts on line 76.