-
Notifications
You must be signed in to change notification settings - Fork 21
feat(java): add algolia user agent APIC-338 #347
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 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fef3519
feat(java): add algolia user agent
millotp fae1136
optional with requester
millotp 9619762
review
millotp 5a04b08
Merge branch 'main' into feat/ua-java
millotp 5700f88
Merge branch 'main' into feat/ua-java
millotp a703a16
Merge branch 'main' into feat/ua-java
millotp 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
55 changes: 55 additions & 0 deletions
55
clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/utils/UserAgent.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,55 @@ | ||
package com.algolia.utils; | ||
|
||
import java.util.LinkedHashSet; | ||
import java.util.Set; | ||
|
||
public class UserAgent { | ||
|
||
private final Set<String> segments; | ||
|
||
private String finalValue; | ||
|
||
public UserAgent(String clientVersion) { | ||
this.finalValue = String.format("Algolia for Java (%s)", clientVersion); | ||
this.segments = new LinkedHashSet<String>(); | ||
this.addSegment(new Segment("JVM", System.getProperty("java.version"))); | ||
} | ||
|
||
public String addSegment(Segment seg) { | ||
String segment = seg.toString(); | ||
if (segments.contains(segment)) return finalValue; | ||
segments.add(segment); | ||
finalValue += segment; | ||
return finalValue; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return finalValue; | ||
} | ||
|
||
public static class Segment { | ||
|
||
private final String value; | ||
private final String version; | ||
|
||
public Segment(String value) { | ||
this(value, null); | ||
} | ||
|
||
public Segment(String value, String version) { | ||
this.value = value; | ||
this.version = version; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append("; ").append(value); | ||
if (version != null) { | ||
sb.append(" (").append(version).append(")"); | ||
} | ||
return sb.toString(); | ||
} | ||
} | ||
} |
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
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
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
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
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 |
---|---|---|
|
@@ -68,6 +68,17 @@ Some Algolia clients (search and recommend) targets the default appId host (`${a | |
|
||
As the generator does not support reading `servers` in a spec file, hosts methods and variables are extracted with a custom script and create variables for you to use in the mustache templates, [read more here](/docs/addNewClient#generators). | ||
|
||
### User Agent | ||
|
||
The header 'User-Agent' must respect a strict pattern of a base, plus additional user defined segments: | ||
base: `Algolia for <language> (<apiVersion>)` | ||
client: `; <clientName> (<clientVersion>)` | ||
segment: `; <Description> ([version])` | ||
|
||
The version is optional for segments. | ||
|
||
The resulting User Agent is the concatenation of `base`, `client`, and all the `segments`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe an example of output could help There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and the link to this PR |
||
|
||
### Requesters | ||
|
||
> TODO: informations | ||
|
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.
non blocking: I did not saw other one liners in this codebase, we might want to stick to curly brackets for consistency