-
Notifications
You must be signed in to change notification settings - Fork 534
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
Fix #5: GAE Abstraction part 1 - Topic Page handler [Blocked: #85] #78
Changes from 1 commit
7269d15
ac16d10
bf96010
ef62740
93d703b
3679c4c
a4e0ad5
d187b56
d27d161
5d5da22
07b51d5
a52bb57
1d6c39b
b476e8e
4aadf7a
d03a527
a380eaa
1da9475
842dc21
ffde992
f5ae749
0049548
cd94945
e392406
5eccceb
1751f36
798cf41
80249a8
bb62037
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
package org.oppia.data | ||
|
||
/** Constant values for data module will be defined here */ | ||
/** An object that contains constants for data module */ | ||
object Constants { | ||
|
||
const val RESPONSE_SUCCESS = 200 | ||
/** Constant which defines successful API call */ | ||
const val HTTP_OK = 200 | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,29 @@ | ||
package org.oppia.data.backends.gae | ||
|
||
/** NetworkSettings contains functions and constants specifically related to network only. */ | ||
/** An object that contains functions and constants specifically related to network only. */ | ||
object NetworkSettings { | ||
|
||
private var isDeveloperMode: Boolean = true | ||
|
||
/** DEVELOPER URL which connects to development server */ | ||
// TODO(#74): Move this to DI graph | ||
const val BASE_URL = "https://oppia.org" | ||
private const val DEVELOPER_URL = "https://oppia.org" | ||
/** PRODUCTION URL which connects to production server */ | ||
private const val PROD_URL = "https://oppia.org" | ||
/** | ||
* Prefix in Json response for extra layer of security in API calls | ||
* | ||
* @see <a href="https://github.com/oppia/oppia/blob/8f9eed9652d7c2d318798792f3c2c38a909abc67/feconf.py#L319">XSSI_PREFIX</a> | ||
* | ||
* Remove this prefix from every Json response which is achieved in [NetworkInterceptor] | ||
*/ | ||
const val XSSI_PREFIX = ")]}\'" | ||
rt4914 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
fun getBaseUrl(): String { | ||
return if (isDeveloperMode) { | ||
DEVELOPER_URL | ||
} else { | ||
PROD_URL | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ import okhttp3.OkHttpClient | |
import retrofit2.Retrofit | ||
import retrofit2.converter.moshi.MoshiConverterFactory | ||
|
||
/** This file manages Retrofit configuration and connection with Oppia backend */ | ||
/** An object that contains the Retrofit configuration with the Oppia backend. */ | ||
object OppiaGaeClient { | ||
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. Let's go ahead and move this to the Dagger graph so that we can inject TopicService directly. We probably don't need OppiaGaeClient at all, and we can also hide the retrofit instance. A pseudocode implementation of this is: @Module
class NetworkModule {
@Qualifier private annotation class OppiaRetrofit
@OppiaRetrofit
@Provides
@Singleton
fun provideRetrofitInstance() {
return retrofit2.Retrofit.Builder().
baseUrl(...)
...
.build()
}
@Provides
@Singleton
fun provideTopicService(@OppiaRetrofit retrofit: Retrofit) {
return retrofit.create(TopicService::class.java)
}
} NB: This module needs to be included in the application component's module list. And with this module, we can now inject |
||
|
||
private var retrofit: Retrofit? = null | ||
|
@@ -16,7 +16,7 @@ object OppiaGaeClient { | |
client.addInterceptor(NetworkInterceptor()) | ||
|
||
retrofit = retrofit2.Retrofit.Builder() | ||
.baseUrl(NetworkSettings.BASE_URL) | ||
.baseUrl(NetworkSettings.getBaseUrl()) | ||
.addConverterFactory(MoshiConverterFactory.create()) | ||
.client(client.build()) | ||
.build() | ||
|
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.
@BenHenning Not sure how to dagger-ify this.