-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor gradle props * Fix NPE when reverse geocode returns empty body * Set sample app API key via gradle props * Update deploy scripts to inject API key via build props * Centralize API key management in new MapzenManager class * Checkstyle * Tangram 0.4.9 release * Update javadoc
- Loading branch information
Showing
29 changed files
with
294 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,6 @@ | ||
version=0.0.1-SNAPSHOT | ||
|
||
POM_ARTIFACT_ID=mapzen-core | ||
POM_NAME=Mapzen Android Core | ||
POM_PACKAGING=aar | ||
|
||
GROUP=com.mapzen | ||
VERSION_NAME=0.0.1-SNAPSHOT | ||
|
||
POM_DESCRIPTION=Core classes used by the Mapzen Android SDK and Mapzen Places API. | ||
|
||
POM_URL=https://github.com/mapzen/android | ||
POM_SCM_URL=http://github.com/mapzen/android | ||
POM_SCM_CONNECTION=scm:git:git://github.com/mapzen/android.git | ||
POM_SCM_DEV_CONNECTION=scm:git:[email protected]:mapzen/android.git | ||
|
||
POM_LICENCE_NAME=The Apache Software License, Version 2.0 | ||
POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt | ||
POM_LICENCE_DIST=repo | ||
|
||
POM_DEVELOPER_ID=Mapzen | ||
POM_DEVELOPER_NAME=Mapzen |
10 changes: 0 additions & 10 deletions
10
core/src/main/java/com/mapzen/android/core/ApiKeyConstants.java
This file was deleted.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
core/src/main/java/com/mapzen/android/core/MapzenManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.mapzen.android.core; | ||
|
||
import android.content.Context; | ||
import android.content.res.Resources; | ||
|
||
/** | ||
* {@code MapzenManager} assists with Mapzen API key management. When created it reads the API key | ||
* set in string resources if one has been declared by the application. | ||
* | ||
* <pre> | ||
* <resources> | ||
* <string name="mapzen_api_key">[YOUR_MAPZEN_API_KEY]</string> | ||
* </resources> | ||
* </pre> | ||
* | ||
* If an API key is set in code via {@link #setApiKey(String)} it will override the declared as a | ||
* string resource. | ||
* | ||
* Finally, if an API key is explicitly passed into a specific component when created it will | ||
* supersede any key stored by this class. | ||
* | ||
* <pre> | ||
* MapzenSearch mapzenSearch = new MapzenSearch(context, "mapzen-XXXXXXX") | ||
* </pre> | ||
*/ | ||
public class MapzenManager { | ||
public static final String API_KEY_RES_NAME = "mapzen_api_key"; | ||
public static final String API_KEY_RES_TYPE = "string"; | ||
public static final String API_KEY_PARAM_NAME = "api_key"; | ||
|
||
static MapzenManager instance; | ||
|
||
/** | ||
* Get singleton instance. | ||
*/ | ||
public static MapzenManager instance(Context context) { | ||
if (instance == null) { | ||
instance = new MapzenManager(context); | ||
} | ||
|
||
return instance; | ||
} | ||
|
||
private String apiKey; | ||
|
||
/** | ||
* Creates a new instance of the manager. | ||
*/ | ||
private MapzenManager(Context context) { | ||
final Resources resources = context.getResources(); | ||
int id = resources.getIdentifier(API_KEY_RES_NAME, API_KEY_RES_TYPE, context.getPackageName()); | ||
if (id > 0) { | ||
apiKey = resources.getString(id); | ||
} | ||
} | ||
|
||
/** | ||
* Returns the currently active API key stored by this class. | ||
*/ | ||
public String getApiKey() { | ||
return apiKey; | ||
} | ||
|
||
/** | ||
* Sets a new API key value. This will override any previous key including those declared in xml. | ||
*/ | ||
public void setApiKey(String apiKey) { | ||
this.apiKey = apiKey; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
core/src/test/java/com/mapzen/android/core/MapzenManagerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package com.mapzen.android.core; | ||
|
||
import com.mapzen.BuildConfig; | ||
import com.mapzen.android.core.test.R; | ||
|
||
import org.junit.After; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.powermock.core.classloader.annotations.PrepareForTest; | ||
import org.powermock.modules.junit4.PowerMockRunner; | ||
|
||
import android.content.Context; | ||
import android.content.res.Resources; | ||
import android.support.annotation.NonNull; | ||
|
||
import static com.mapzen.android.core.MapzenManager.API_KEY_RES_NAME; | ||
import static com.mapzen.android.core.MapzenManager.API_KEY_RES_TYPE; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
@RunWith(PowerMockRunner.class) | ||
@PrepareForTest(BuildConfig.class) | ||
public class MapzenManagerTest { | ||
@After public void tearDown() throws Exception { | ||
MapzenManager.instance = null; | ||
} | ||
|
||
@Test public void shouldNotBeNull() throws Exception { | ||
Context context = mock(Context.class); | ||
Resources resources = new TestResources(); | ||
when(context.getResources()).thenReturn(resources); | ||
MapzenManager mapzenManager = MapzenManager.instance(context); | ||
assertThat(mapzenManager).isNotNull(); | ||
} | ||
|
||
@Test public void getApiKey_shouldReturnNullIfNotSet() throws Exception { | ||
Context context = mock(Context.class); | ||
Resources resources = new TestResources(); | ||
when(context.getResources()).thenReturn(resources); | ||
MapzenManager mapzenManager = MapzenManager.instance(context); | ||
assertThat(mapzenManager.getApiKey()).isNull(); | ||
} | ||
|
||
@Test public void getApiKey_shouldReturnNullIfResourceNotFound() throws Exception { | ||
Context context = mock(Context.class); | ||
Resources resources = new TestResourcesNotFound(); | ||
when(context.getResources()).thenReturn(resources); | ||
MapzenManager mapzenManager = MapzenManager.instance(context); | ||
assertThat(mapzenManager.getApiKey()).isNull(); | ||
} | ||
|
||
@Test public void getApiKey_shouldReturnStringResourceValue() throws Exception { | ||
Context context = mock(Context.class); | ||
TestResources resources = new TestResources(); | ||
resources.testApiKey = "mapzen-fake-api-key"; | ||
when(context.getResources()).thenReturn(resources); | ||
MapzenManager mapzenManager = MapzenManager.instance(context); | ||
assertThat(mapzenManager.getApiKey()).isEqualTo("mapzen-fake-api-key"); | ||
} | ||
|
||
@Test public void setApiKey_shouldOverrideStringResourcesValue() throws Exception { | ||
Context context = mock(Context.class); | ||
TestResources resources = new TestResources(); | ||
resources.testApiKey = "mapzen-fake-api-key"; | ||
when(context.getResources()).thenReturn(resources); | ||
MapzenManager mapzenManager = MapzenManager.instance(context); | ||
mapzenManager.setApiKey("mapzen-fake-api-key-2"); | ||
assertThat(mapzenManager.getApiKey()).isEqualTo("mapzen-fake-api-key-2"); | ||
} | ||
|
||
private class TestResources extends Resources { | ||
private String testApiKey; | ||
|
||
TestResources() { | ||
super(null, null, null); | ||
} | ||
|
||
@Override public int getIdentifier(String name, String defType, String defPackage) { | ||
if (API_KEY_RES_NAME.equals(name) && API_KEY_RES_TYPE.equals(defType)) { | ||
return R.id.mapzen_api_key; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
@NonNull @Override public String getString(int id) throws NotFoundException { | ||
if (id == R.id.mapzen_api_key) { | ||
return testApiKey; | ||
} | ||
|
||
throw new NotFoundException(); | ||
} | ||
} | ||
|
||
private class TestResourcesNotFound extends Resources { | ||
TestResourcesNotFound() { | ||
super(null, null, null); | ||
} | ||
|
||
@Override public int getIdentifier(String name, String defType, String defPackage) { | ||
return 0; | ||
} | ||
|
||
@NonNull @Override public String getString(int id) throws NotFoundException { | ||
throw new NotFoundException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.mapzen.android.core.test; | ||
|
||
public final class R { | ||
public static final class id { | ||
public static final int mapzen_api_key = 0x00000001; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
version=1.3.0-SNAPSHOT | ||
|
||
VERSION_NAME=1.3.0-SNAPSHOT | ||
|
||
POM_URL=https://github.com/mapzen/android | ||
POM_SCM_URL=http://github.com/mapzen/android | ||
POM_SCM_CONNECTION=scm:git:git://github.com/mapzen/android.git | ||
POM_SCM_DEV_CONNECTION=scm:git:[email protected]:mapzen/android.git | ||
|
||
POM_LICENCE_NAME=The Apache Software License, Version 2.0 | ||
POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt | ||
POM_LICENCE_DIST=repo | ||
|
||
POM_DEVELOPER_ID=Mapzen | ||
POM_DEVELOPER_NAME=Mapzen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,6 @@ | ||
version=1.3.0-SNAPSHOT | ||
|
||
POM_ARTIFACT_ID=mapzen-android-sdk | ||
POM_NAME=Mapzen Android SDK | ||
POM_PACKAGING=aar | ||
|
||
GROUP=com.mapzen | ||
VERSION_NAME=1.3.0-SNAPSHOT | ||
|
||
POM_DESCRIPTION=Unified SDK for Mapzen tools and services on Android. | ||
|
||
POM_URL=https://github.com/mapzen/android | ||
POM_SCM_URL=http://github.com/mapzen/android | ||
POM_SCM_CONNECTION=scm:git:git://github.com/mapzen/android.git | ||
POM_SCM_DEV_CONNECTION=scm:git:[email protected]:mapzen/android.git | ||
|
||
POM_LICENCE_NAME=The Apache Software License, Version 2.0 | ||
POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt | ||
POM_LICENCE_DIST=repo | ||
|
||
POM_DEVELOPER_ID=Mapzen | ||
POM_DEVELOPER_NAME=Mapzen |
Oops, something went wrong.