Commit 3c9262b2 authored by Mohsen Taleb's avatar Mohsen Taleb

Added support for custom API urls and updated to mapbox-0.7.3

parent 2d853272
apply plugin: 'com.android.library' apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven' apply plugin: 'com.github.dcendents.android-maven'
version = "0.7.1" version = "0.7.3"
def siteUrl = 'http://cedarmaps.com' def siteUrl = 'http://cedarmaps.com'
def gitUrl = 'http://cedarmaps.com/git' def gitUrl = 'http://cedarmaps.com/git'
group = "com.cedarmaps" group = "com.cedarmaps"
android { android {
compileSdkVersion 21 compileSdkVersion 22
buildToolsVersion "21.1.2" buildToolsVersion "21.1.2"
defaultConfig { defaultConfig {
minSdkVersion 9 minSdkVersion 9
targetSdkVersion 21 targetSdkVersion 22
versionCode 2 versionCode 3
versionName "0.7.1" versionName "0.7.3"
} }
buildTypes { buildTypes {
} }
...@@ -22,7 +22,7 @@ android { ...@@ -22,7 +22,7 @@ android {
dependencies { dependencies {
compile fileTree(dir: 'libs', include: ['*.jar']) compile fileTree(dir: 'libs', include: ['*.jar'])
compile('com.mapbox.mapboxsdk:mapbox-android-sdk:0.7.1@aar') { compile('com.mapbox.mapboxsdk:mapbox-android-sdk:0.7.3@aar') {
transitive = true transitive = true
} }
} }
......
...@@ -3,9 +3,6 @@ package com.cedarstudios.cedarmapssdk; ...@@ -3,9 +3,6 @@ package com.cedarstudios.cedarmapssdk;
import com.squareup.okhttp.Response; import com.squareup.okhttp.Response;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException; import java.io.IOException;
public class CedarMapsException extends Exception { public class CedarMapsException extends Exception {
......
...@@ -62,7 +62,7 @@ class CedarMapsImpl extends CedarMapsBaseImpl implements CedarMaps { ...@@ -62,7 +62,7 @@ class CedarMapsImpl extends CedarMapsBaseImpl implements CedarMaps {
throw new CedarMapsException(e); throw new CedarMapsException(e);
} }
String url = String String url = String
.format(Locale.ENGLISH, conf.getRestBaseURL() + "geocode/%s/%s.json", .format(Locale.ENGLISH, conf.getAPIBaseURL() + "geocode/%s/%s.json",
conf.getMapId(), term); conf.getMapId(), term);
url += String.format(Locale.ENGLISH, "?limit=%s", limit); url += String.format(Locale.ENGLISH, "?limit=%s", limit);
...@@ -88,7 +88,7 @@ class CedarMapsImpl extends CedarMapsBaseImpl implements CedarMaps { ...@@ -88,7 +88,7 @@ class CedarMapsImpl extends CedarMapsBaseImpl implements CedarMaps {
@Override @Override
public JSONObject geocode(double lat, double lng) throws CedarMapsException { public JSONObject geocode(double lat, double lng) throws CedarMapsException {
String url = String.format(Locale.ENGLISH, String url = String.format(Locale.ENGLISH,
conf.getRestBaseURL() + "geocode/%1$s/%2$s,%3$s.json", conf.getMapId(), lat, lng); conf.getAPIBaseURL() + "geocode/%1$s/%2$s,%3$s.json", conf.getMapId(), lat, lng);
if (TextUtils.isEmpty(conf.getMapId())) { if (TextUtils.isEmpty(conf.getMapId())) {
throw new CedarMapsException(new NullPointerException( throw new CedarMapsException(new NullPointerException(
......
package com.cedarstudios.cedarmapssdk.config;
class CedarMapsConstants {
public final static String CEDARMAPS_BASE_URL_V1 = "http://api.cedarmaps.com/v1/";
}
...@@ -12,7 +12,7 @@ public interface Configuration extends AuthorizationConfiguration, Serializable ...@@ -12,7 +12,7 @@ public interface Configuration extends AuthorizationConfiguration, Serializable
String getOAuth2AccessToken(); String getOAuth2AccessToken();
String getRestBaseURL(); String getAPIBaseURL();
String getOAuth2Scope(); String getOAuth2Scope();
......
package com.cedarstudios.cedarmapssdk.config; package com.cedarstudios.cedarmapssdk.config;
import com.cedarstudios.cedarmapssdk.CedarMapsConstants;
import java.io.ObjectStreamException; import java.io.ObjectStreamException;
import java.io.Serializable; import java.io.Serializable;
...@@ -22,10 +21,10 @@ class ConfigurationBase implements Configuration, Serializable { ...@@ -22,10 +21,10 @@ class ConfigurationBase implements Configuration, Serializable {
private String mapId; private String mapId;
private String oAuth2TokenURL = CedarMapsConstants.CEDARMAPS_BASE_URL_V1 + "token";
private String restBaseURL = CedarMapsConstants.CEDARMAPS_BASE_URL_V1; private String restBaseURL = CedarMapsConstants.CEDARMAPS_BASE_URL_V1;
private String oAuth2TokenURL = restBaseURL + "token";
public void setOAuthClientId(String oAuthClientId) { public void setOAuthClientId(String oAuthClientId) {
this.oAuthClientId = oAuthClientId; this.oAuthClientId = oAuthClientId;
...@@ -39,8 +38,13 @@ class ConfigurationBase implements Configuration, Serializable { ...@@ -39,8 +38,13 @@ class ConfigurationBase implements Configuration, Serializable {
this.mapId = mapId; this.mapId = mapId;
} }
public void setAPIBaseUrl(String baseUrl) {
restBaseURL = baseUrl;
setOAuth2TokenURL(restBaseURL + "token");
}
@Override @Override
public String getRestBaseURL() { public String getAPIBaseURL() {
return restBaseURL; return restBaseURL;
} }
......
...@@ -4,6 +4,12 @@ public final class ConfigurationBuilder { ...@@ -4,6 +4,12 @@ public final class ConfigurationBuilder {
private ConfigurationBase configurationBase = new ConfigurationBase(); private ConfigurationBase configurationBase = new ConfigurationBase();
public ConfigurationBuilder setAPIBaseURL(String baseURL) {
checkNotBuilt();
configurationBase.setAPIBaseUrl(baseURL);
return this;
}
public ConfigurationBuilder setClientId(String clientId) { public ConfigurationBuilder setClientId(String clientId) {
checkNotBuilt(); checkNotBuilt();
......
package com.cedarstudios.cedarmapssdk.tileprovider; package com.cedarstudios.cedarmapssdk.tileprovider;
import com.cedarstudios.cedarmapssdk.CedarMaps; import com.cedarstudios.cedarmapssdk.CedarMaps;
import com.cedarstudios.cedarmapssdk.CedarMapsConstants;
import com.cedarstudios.cedarmapssdk.CedarMapsException; import com.cedarstudios.cedarmapssdk.CedarMapsException;
import com.cedarstudios.cedarmapssdk.CedarMapsFactory; import com.cedarstudios.cedarmapssdk.CedarMapsFactory;
import com.cedarstudios.cedarmapssdk.CedarMapsTileLayerListener; import com.cedarstudios.cedarmapssdk.CedarMapsTileLayerListener;
...@@ -202,7 +201,7 @@ public class CedarMapsTileLayer extends WebSourceTileLayer { ...@@ -202,7 +201,7 @@ public class CedarMapsTileLayer extends WebSourceTileLayer {
private String getBrandedJSONURL() { private String getBrandedJSONURL() {
String url = String String url = String
.format(Locale.ENGLISH, CedarMapsConstants.CEDARMAPS_BASE_URL_V1 .format(Locale.ENGLISH, mConfiguration.getAPIBaseURL()
+ "tiles/%s.json?access_token=%s&secure=1", mId, + "tiles/%s.json?access_token=%s&secure=1", mId,
CedarMapsUtils.getAccessToken()); CedarMapsUtils.getAccessToken());
if (!mEnableSSL) { if (!mEnableSSL) {
...@@ -263,7 +262,7 @@ public class CedarMapsTileLayer extends WebSourceTileLayer { ...@@ -263,7 +262,7 @@ public class CedarMapsTileLayer extends WebSourceTileLayer {
if (!TextUtils.isEmpty(aUrl) && !aUrl.toLowerCase(Locale.US).contains("http://") && !aUrl if (!TextUtils.isEmpty(aUrl) && !aUrl.toLowerCase(Locale.US).contains("http://") && !aUrl
.toLowerCase(Locale.US).contains("https://")) { .toLowerCase(Locale.US).contains("https://")) {
super.setURL( super.setURL(
CedarMapsConstants.CEDARMAPS_BASE_URL_V1 + "tiles/" + aUrl mConfiguration.getAPIBaseURL() + "tiles/" + aUrl
+ "/{z}/{x}/{y}.png?access_token=" + "/{z}/{x}/{y}.png?access_token="
+ CedarMapsUtils.getAccessToken()); + CedarMapsUtils.getAccessToken());
} else { } else {
......
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
android { android {
compileSdkVersion 21 compileSdkVersion 22
buildToolsVersion "21.1.2" buildToolsVersion "21.1.2"
defaultConfig { defaultConfig {
applicationId "com.cedarstudios.cedarmaps.sample" applicationId "com.cedarstudios.cedarmaps.sample"
minSdkVersion 9 minSdkVersion 9
targetSdkVersion 21 targetSdkVersion 22
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
} }
...@@ -21,6 +21,6 @@ android { ...@@ -21,6 +21,6 @@ android {
dependencies { dependencies {
compile fileTree(dir: 'libs', include: ['*.jar']) compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3' compile 'com.android.support:appcompat-v7:22.1.1'
compile(project(':CedarMapsSDK')) compile(project(':CedarMapsSDK'))
} }
...@@ -16,7 +16,7 @@ repositories { ...@@ -16,7 +16,7 @@ repositories {
} }
dependencies { dependencies {
compile('com.cedarmaps:CedarMapsSDK:0.7.1@aar') { compile('com.cedarmaps:CedarMapsSDK:0.7.3@aar') {
transitive = true transitive = true
} }
} }
...@@ -112,6 +112,19 @@ Configuration configuration = new ConfigurationBuilder() ...@@ -112,6 +112,19 @@ Configuration configuration = new ConfigurationBuilder()
Currently you can use `cedarmaps.streets` as default mapId Currently you can use `cedarmaps.streets` as default mapId
#### Changing API Base Url
You can change API Base Url by setting it on configuration object:
```java
MapView mapView = new MapView(context);
Configuration configuration = new ConfigurationBuilder()
.setAPIBaseURL(CUSTOM_API_URL)
.setClientId(Constants.CLIENT_ID)
.setClientSecret(Constants.CLIENT_SECRET)
.setMapId(Constants.MAPID_CEDARMAPS_STREETS)
.build();
```
### Attention ### Attention
......
...@@ -5,7 +5,7 @@ buildscript { ...@@ -5,7 +5,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:1.0.1' classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'com.github.dcendents:android-maven-plugin:1.2' classpath 'com.github.dcendents:android-maven-plugin:1.2'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment