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

API key secured. #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ build/
.DS_Store
app/.DS_Store
.idea

apiKey.properties
1 change: 1 addition & 0 deletions apiKey.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
API_KEY = "079dac74a5f94ebdb990ecf61c8854b7"
6 changes: 6 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
apply plugin: 'com.android.application'

def apiKeyPropertiesFile = rootProject.file("apiKey.properties")
def apiKeyProperties = new Properties()
apiKeyProperties.load(new FileInputStream(apiKeyPropertiesFile))

android {
compileSdkVersion 27
defaultConfig {
Expand All @@ -9,6 +13,8 @@ android {
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

buildConfigField("String", "API_KEY", apiKeyProperties['API_KEY'])
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
public interface BaseConstants {

String QUERY = "movies";
String API_KEY = "079dac74a5f94ebdb990ecf61c8854b7";
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import com.an.paginglibrary.sample.AppController;
import com.an.paginglibrary.sample.BaseConstants;
import com.an.paginglibrary.sample.BuildConfig;
import com.an.paginglibrary.sample.model.Article;
import com.an.paginglibrary.sample.model.Feed;
import com.an.paginglibrary.sample.utils.NetworkState;
Expand Down Expand Up @@ -49,7 +50,7 @@ public void loadInitial(@NonNull LoadInitialParams<Long> params,
initialLoading.postValue(NetworkState.LOADING);
networkState.postValue(NetworkState.LOADING);

appController.getRestApi().fetchFeed(QUERY, API_KEY, 1, params.requestedLoadSize)
appController.getRestApi().fetchFeed(QUERY, BuildConfig.API_KEY, 1, params.requestedLoadSize)
.enqueue(new Callback<Feed>() {
@Override
public void onResponse(Call<Feed> call, Response<Feed> response) {
Expand Down Expand Up @@ -86,7 +87,7 @@ public void loadAfter(@NonNull LoadParams<Long> params,

networkState.postValue(NetworkState.LOADING);

appController.getRestApi().fetchFeed(QUERY, API_KEY, params.key, params.requestedLoadSize).enqueue(new Callback<Feed>() {
appController.getRestApi().fetchFeed(QUERY, BuildConfig.API_KEY, params.key, params.requestedLoadSize).enqueue(new Callback<Feed>() {
@Override
public void onResponse(Call<Feed> call, Response<Feed> response) {
if(response.isSuccessful()) {
Expand Down