Skip to content
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

Refactor RouteOptions.toUrl #1314

Merged
merged 1 commit into from
Nov 2, 2021
Merged

Conversation

korshaknn
Copy link
Contributor

closes #1313

can't usejava.net.URL case it doesn't have handy methods to build URL, so use okhttp HttpUrl

also some symbols were encoded:
; -> %3B
, -> %2C
it shouldn't be an issue, right?

@korshaknn korshaknn self-assigned this Oct 29, 2021
Copy link
Contributor

@Guardiola31337 Guardiola31337 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change bringing the possibility to pass either https://mapbox.com/ or https://mapbox.com as baseUrl and should work fine? I'm asking because

public static final String BASE_API_URL = "https://api.mapbox.com";
doesn't include it.

BTW code wise LGTM 👍

@korshaknn
Copy link
Contributor Author

@Guardiola31337 baseUrlWithLastSlash tests it

.baseUrl("https://mapbox.com/")

@@ -2,6 +2,7 @@ apply plugin: 'java-library'

dependencies {
api project(":services-geojson")
api dependenciesList.okhttp3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Guardiola31337 do you think it's fine to bring okHttp dependency to the models model?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great question. Yeah, ideally services-directions-models doesn't have dependencies. We're including OkHttp in services-core

api dependenciesList.retrofit
api dependenciesList.okhttp3Logging

Can we workaround it somehow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as I said we can't use java.net.URL because it doesn't have handy methods to build URL, we will struggle with / symbols anyway, I haven't found any workaround so use okhttp HttpUrl

Copy link
Contributor

@RingerJK RingerJK Oct 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's migrate toUrl method to the service module, smth like

class ServiceUtils {
  public static String toUrl(RouteOption routeOptions) { 
    ...
  }
}

and deprecate current fun. This way we don't need okhttp dependency in the current module

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kotlin extensions would look better 💯

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I vote to move toUrl to the service module. Models has to be as dumb as possible and assembling URLs based on fields is not what models should make

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LukasPaczos @Guardiola31337 vote please and I will continue with the approach

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to maintain the current version of RouteOptions::toUrl anyway, we don't want to release a new breaking mapbox-java release, so I would vote for this option. The method does not need to do any encoding, just a simple unencoded URL that HTTP clients can then interpret. We can migrate to string builders if that's easier and cover edge cases with tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, 2-1 wins stringBuilder + tests

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Late to the party but I'd vote StringBuilder + tests too 😅

@korshaknn korshaknn force-pushed the knn-options-to-url-refactoring branch from 044ccb1 to 5f1c388 Compare November 2, 2021 13:04
@korshaknn
Copy link
Contributor Author

I've fixed // issue and added a test.
cc @LukasPaczos @RingerJK

Copy link
Contributor

@RingerJK RingerJK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@korshaknn korshaknn merged commit de6e87b into main Nov 2, 2021
@korshaknn korshaknn deleted the knn-options-to-url-refactoring branch November 2, 2021 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RouteOptions.toUrl migrate to url library
4 participants