-
Notifications
You must be signed in to change notification settings - Fork 439
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
feat: modify user agent string #683
Conversation
…nd made it extensible
…ture/DII-365-Modify-user-string
…ture/Modify-UserAgent-string
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.
Coverage is a bit low. Should see where more tests would be useful.
Could you link the issue that this PR solves, in the description ? |
new BasicHeader(HttpHeaders.ACCEPT, "application/json"), | ||
new BasicHeader(HttpHeaders.ACCEPT_ENCODING, "utf-8") | ||
); | ||
isCustomClient = true; |
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.
What's the purpose of this flag? Would it ever equal to false?
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.
it is to know if client(developer) has created custom httpclient. I am using this flag to add " custom" String in UserAgentString.
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.
I guess I am missing something here. Won't it be always true
?
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.
By default it will be false, It will be true when NetworkHttpClient instance is created by using constructor:
"NetworkHttpClient(HttpClientBuilder clientBuilder)" (Means by passing custom HttpClientBuilder)
Example:
Check class ProxiedTwilioClientCreator in below mentioned link:
https://www.twilio.com/docs/libraries/java/custom-http-clients-java#
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.
Got it. Thanks.
Added |
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.
High-level feedback on the new tests: they do execute the new/changed lines and have assertions, but the assertions are overly loose. They should assert on the expected impact of the new behavior rather than the new behavior not having a negative impact.
Let me know if you'd like to sync for more discussion/clarification.
private TwilioRestClient twilioRestClient; | ||
|
||
@Injectable |
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.
Don't think this annotation is needed since setUp
sets the value.
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.
Not able make method call without making variable as @Injectable
This was strange to me.
---> |
…tString in Twilio
Twilio.setPassword("Password"); | ||
Twilio.setUserAgentExtensions(Arrays.asList("ce-appointment-reminders/1.0.0", "code-exchange")); | ||
Twilio.getRestClient(); | ||
assertEquals(Twilio.getUserAgentExtensions(), Arrays.asList("ce-appointment-reminders/1.0.0", "code-exchange")); |
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.
nit: Should flip the arg order so it's expected, actual
private List<String> userAgentExtensionsEmpty = new ArrayList<>();; | ||
private List<String> userAgentExtensions = Arrays.asList("ce-appointment-reminders/1.0.0", "code-exchange");; |
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.
nit: Double ;
at EOL.
|
||
@Test | ||
public void testRequestWithExtention() { | ||
Request request = new Request( | ||
HttpMethod.GET, | ||
Domains.API.toString(), | ||
"/2010-04-01/Accounts/" + "AC123" + "/Messages/" + "MM123" + ".json" | ||
); | ||
twilioRestClientExtension = new TwilioRestClient.Builder("AC123", "AUTH TOKEN") | ||
.userAgentExtensions(userAgentStringExtensions) | ||
.build(); | ||
twilioRestClientExtension.request(request); | ||
assertEquals(request.getUserAgentExtensions(), userAgentStringExtensions); | ||
} | ||
|
||
@Test | ||
public void testRequestWithExtentionEmpty() { | ||
Request request = new Request( | ||
HttpMethod.GET, | ||
Domains.API.toString(), | ||
"/2010-04-01/Accounts/" + "AC123" + "/Messages/" + "MM123" + ".json" | ||
); | ||
twilioRestClientExtension = new TwilioRestClient.Builder("AC123", "AUTH TOKEN") | ||
.userAgentExtensions(Arrays.asList()) | ||
.build(); | ||
twilioRestClientExtension.request(request); | ||
assertEquals(request.getUserAgentExtensions(), null); | ||
} | ||
|
||
@Test | ||
public void testRequestWithExtentionNull() { | ||
Request request = new Request( | ||
HttpMethod.GET, | ||
Domains.API.toString(), | ||
"/2010-04-01/Accounts/" + "AC123" + "/Messages/" + "MM123" + ".json" | ||
); | ||
twilioRestClientExtension = new TwilioRestClient.Builder("AC123", "AUTH TOKEN") | ||
.userAgentExtensions(null) | ||
.build(); | ||
twilioRestClientExtension.request(request); | ||
assertEquals(request.getUserAgentExtensions(), null); | ||
} |
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.
s/Extention/Extension/
Request request = new Request( | ||
HttpMethod.GET, | ||
Domains.API.toString(), | ||
"/2010-04-01/Accounts/" + "AC123" + "/Messages/" + "MM123" + ".json" |
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.
nit: No need for string concatenation.
.userAgentExtensions(null) | ||
.build(); | ||
twilioRestClientExtension.request(request); | ||
assertEquals(request.getUserAgentExtensions(), null); |
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.
nit: assertNull
Recommend installing the SonarQube IDE plugin which alerts about things like this.
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.
🚀
Kudos, SonarCloud Quality Gate passed! |
Fixes
Standardisation of UserAgent String as per below mentioned doc
https://docs.google.com/document/d/1dDAvu9N4wkTnZKmWx5iiMfU42b7qYLAegA_QbZoBkU0/edit#
Checklist
If you have questions, please file a support ticket, or create a GitHub Issue in this repository.