-
Notifications
You must be signed in to change notification settings - Fork 206
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
Bump Retrofit version to 2.0.0 #137
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.artemzin.qualitymatters.network; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import javax.inject.Qualifier; | ||
|
||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
@Documented | ||
@Qualifier | ||
@Retention(RUNTIME) | ||
public @interface ForRestApi { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.artemzin.qualitymatters.network; | ||
|
||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
import java.io.IOException; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import okhttp3.HttpUrl; | ||
import okhttp3.Interceptor; | ||
import okhttp3.Request; | ||
import okhttp3.Response; | ||
|
||
/** | ||
* Such implementation allows us easily change base url in the integration and functional tests! | ||
*/ | ||
public class HostSelectionInterceptor implements Interceptor { | ||
|
||
@Nullable | ||
private volatile String baseUrl; | ||
|
||
@Override @NonNull | ||
public Response intercept(@NonNull Chain chain) throws IOException { | ||
Request request = chain.request(); | ||
final String baseUrl = this.baseUrl; | ||
|
||
if (baseUrl != null) { | ||
request = modifyRequest(request, baseUrl); | ||
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. What do you think about the problem that we redirect all requests (not only api ones) to the mock webserver? I see 2 solutions:
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. Actually, we do not redirect all requests to the mock webserver. 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. We do redirect all requests that goes through that instance of 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. That's right. I mean that dynamic url is used for testing purposes only and now only test code mutates the interceptor. 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. Nothing prevents us from hitting not only API in future and functional tests will cover that and we may have problems, that's why I'm trying to say 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. No. Recreate 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. Wait wait wait then :) Please check square/retrofit#1652 and #111 The idea is that Recreating 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. I prefer to recreate Actually, what I'm doing in my project is: Using some kind of TestModule so that we can inject mock or fake url for testing. 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. I made some investigations and don't see beautiful solution. The problem is object graph is created before MockWebServer starts. If we want to instatiate Retrofit with baseUrl taken from mockWebServer, we should set that url into ApiModule. Using Provider<> in this case looks like a smelling hack for me. 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. Anyway, I think such refactoring is out of this scope. |
||
} | ||
return chain.proceed(request); | ||
} | ||
|
||
public void setBaseUrl(@Nullable String baseUrl) { | ||
this.baseUrl = baseUrl; | ||
} | ||
|
||
@NonNull | ||
Request modifyRequest(@NonNull final Request request, @Nullable String baseUrl) throws MalformedURLException { | ||
final URL url = new URL(baseUrl); | ||
final HttpUrl newUrl = request.url() | ||
.newBuilder() | ||
.scheme(url.getProtocol()) | ||
.host(url.getHost()) | ||
.port(url.getPort()) | ||
.build(); | ||
return request.newBuilder() | ||
.url(newUrl) | ||
.build(); | ||
} | ||
|
||
@Nullable | ||
public String getBaseUrl() { | ||
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. nullability |
||
return baseUrl; | ||
} | ||
} |
This file was deleted.
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.
Nullability annotation pls