From cac9d829c992f8d7e30ca2ccc3f2847b58fe139a Mon Sep 17 00:00:00 2001 From: Luis Guzman Date: Thu, 24 May 2018 19:28:07 -0500 Subject: [PATCH] library with implement java library --- app/build.gradle | 17 +- .../android/sbxcloudsdk/auth/SbxAuth.java | 496 -------------- .../auth/config/SbxAppKeyField.java | 15 - .../auth/config/SbxDomainField.java | 15 - .../sbxcloudsdk/auth/user/SbxAuthToken.java | 15 - .../sbxcloudsdk/auth/user/SbxEmailField.java | 15 - .../sbxcloudsdk/auth/user/SbxNameField.java | 15 - .../auth/user/SbxPasswordField.java | 15 - .../auth/user/SbxUsernameField.java | 15 - .../cloudscript/SbxCloudScriptHelper.java | 42 -- .../exception/SbxAuthException.java | 20 - .../exception/SbxConfigException.java | 20 - .../exception/SbxModelException.java | 20 - .../sbxcloudsdk/message/SbxChannelHelper.java | 92 --- .../android/sbxcloudsdk/net/ApiManager.java | 6 +- .../sbxcloudsdk/net/auth/SbxAuthAndroid.java | 35 + .../SbxAuthPersistenceAndroidStrategy.java | 57 ++ .../android/sbxcloudsdk/net/auth/SbxUser.java | 35 +- .../net/callback/SbxArrayResponse.java | 13 - .../net/callback/SbxSimpleResponse.java | 15 - .../net/cloudscript/SbxCloudScript.java | 10 +- .../sbxcloudsdk/net/message/SbxChannel.java | 16 +- .../sbxcloudsdk/net/message/SbxMessage.java | 2 +- .../sbxcloudsdk/net/message/SbxPush.java | 8 +- .../sbxcloudsdk/net/model/SbxFile.java | 8 +- .../sbxcloudsdk/net/model/SbxModel.java | 36 +- .../sbxcloudsdk/net/model/SbxQuery.java | 10 +- .../sbxcloudsdk/push/SbxPushHelper.java | 40 -- .../sbxcloudsdk/query/SbxModelHelper.java | 438 ------------ .../sbxcloudsdk/query/SbxQueryBuilder.java | 611 ----------------- .../query/annotation/SbxCreatedAt.java | 15 - .../sbxcloudsdk/query/annotation/SbxKey.java | 15 - .../query/annotation/SbxModelName.java | 16 - .../query/annotation/SbxParamField.java | 19 - .../query/annotation/SbxUpdatedAt.java | 15 - .../sbxcloudsdk/util/SbxDataValidator.java | 104 --- .../sbxcloudsdk/util/SbxFileHelper.java | 28 - .../sbxcloudsdk/util/SbxJsonModeler.java | 15 - .../sbxcloudsdk/util/SbxMagicComposer.java | 631 ------------------ .../sbxcloudsdk/util/SbxUrlComposer.java | 155 ----- .../android/sbxcloudsdk/util/UrlHelper.java | 37 - .../android/sbxcloudsdk/Category.java | 6 +- .../android/sbxcloudsdk/ExampleUnitTest.java | 12 +- .../sbxcloud/android/sbxcloudsdk/Product.java | 6 +- .../sbxcloud/android/sbxcloudsdk/User.java | 12 +- build.gradle | 13 +- gradle/wrapper/gradle-wrapper.properties | 4 +- 47 files changed, 194 insertions(+), 3061 deletions(-) delete mode 100644 app/src/main/java/com/sbxcloud/android/sbxcloudsdk/auth/SbxAuth.java delete mode 100644 app/src/main/java/com/sbxcloud/android/sbxcloudsdk/auth/config/SbxAppKeyField.java delete mode 100644 app/src/main/java/com/sbxcloud/android/sbxcloudsdk/auth/config/SbxDomainField.java delete mode 100644 app/src/main/java/com/sbxcloud/android/sbxcloudsdk/auth/user/SbxAuthToken.java delete mode 100644 app/src/main/java/com/sbxcloud/android/sbxcloudsdk/auth/user/SbxEmailField.java delete mode 100644 app/src/main/java/com/sbxcloud/android/sbxcloudsdk/auth/user/SbxNameField.java delete mode 100644 app/src/main/java/com/sbxcloud/android/sbxcloudsdk/auth/user/SbxPasswordField.java delete mode 100644 app/src/main/java/com/sbxcloud/android/sbxcloudsdk/auth/user/SbxUsernameField.java delete mode 100644 app/src/main/java/com/sbxcloud/android/sbxcloudsdk/cloudscript/SbxCloudScriptHelper.java delete mode 100644 app/src/main/java/com/sbxcloud/android/sbxcloudsdk/exception/SbxAuthException.java delete mode 100644 app/src/main/java/com/sbxcloud/android/sbxcloudsdk/exception/SbxConfigException.java delete mode 100644 app/src/main/java/com/sbxcloud/android/sbxcloudsdk/exception/SbxModelException.java delete mode 100644 app/src/main/java/com/sbxcloud/android/sbxcloudsdk/message/SbxChannelHelper.java create mode 100644 app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/auth/SbxAuthAndroid.java create mode 100644 app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/auth/SbxAuthPersistenceAndroidStrategy.java delete mode 100644 app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/callback/SbxArrayResponse.java delete mode 100644 app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/callback/SbxSimpleResponse.java delete mode 100644 app/src/main/java/com/sbxcloud/android/sbxcloudsdk/push/SbxPushHelper.java delete mode 100644 app/src/main/java/com/sbxcloud/android/sbxcloudsdk/query/SbxModelHelper.java delete mode 100644 app/src/main/java/com/sbxcloud/android/sbxcloudsdk/query/SbxQueryBuilder.java delete mode 100644 app/src/main/java/com/sbxcloud/android/sbxcloudsdk/query/annotation/SbxCreatedAt.java delete mode 100644 app/src/main/java/com/sbxcloud/android/sbxcloudsdk/query/annotation/SbxKey.java delete mode 100644 app/src/main/java/com/sbxcloud/android/sbxcloudsdk/query/annotation/SbxModelName.java delete mode 100644 app/src/main/java/com/sbxcloud/android/sbxcloudsdk/query/annotation/SbxParamField.java delete mode 100644 app/src/main/java/com/sbxcloud/android/sbxcloudsdk/query/annotation/SbxUpdatedAt.java delete mode 100644 app/src/main/java/com/sbxcloud/android/sbxcloudsdk/util/SbxDataValidator.java delete mode 100644 app/src/main/java/com/sbxcloud/android/sbxcloudsdk/util/SbxFileHelper.java delete mode 100644 app/src/main/java/com/sbxcloud/android/sbxcloudsdk/util/SbxJsonModeler.java delete mode 100644 app/src/main/java/com/sbxcloud/android/sbxcloudsdk/util/SbxMagicComposer.java delete mode 100644 app/src/main/java/com/sbxcloud/android/sbxcloudsdk/util/SbxUrlComposer.java delete mode 100644 app/src/main/java/com/sbxcloud/android/sbxcloudsdk/util/UrlHelper.java diff --git a/app/build.gradle b/app/build.gradle index 2a21eb1..7bc37b8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,7 +4,7 @@ apply plugin: 'com.github.dcendents.android-maven' group='com.github.sbxcloud' android { compileSdkVersion 25 - buildToolsVersion "25.0.2" + buildToolsVersion "27.0.3" defaultConfig { minSdkVersion 15 @@ -31,17 +31,18 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + implementation fileTree(dir: 'libs', include: ['*.jar']) + androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) - compile 'com.squareup.okhttp3:logging-interceptor:3.4.1' - compile 'com.squareup.okhttp3:okhttp:3.4.1' - compile 'io.reactivex.rxjava2:rxandroid:2.0.1' + implementation 'com.squareup.okhttp3:logging-interceptor:3.9.1' + implementation 'com.squareup.okhttp3:okhttp:3.9.1' + implementation 'com.github.sbxcloud:sbxcloudjava:v1.0.3-alpha.3' + implementation 'io.reactivex.rxjava2:rxandroid:2.0.1' // Because RxAndroid releases are few and far between, it is recommended you also // explicitly depend on RxJava's latest version for bug fixes and new features. - compile 'io.reactivex.rxjava2:rxjava:2.0.1' - testCompile 'junit:junit:4.12' + implementation 'io.reactivex.rxjava2:rxjava:2.1.6' + testImplementation 'junit:junit:4.12' // testCompile 'org.mockito:mockito-core:1.10.19' // testCompile 'org.json:json:20140107' } diff --git a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/auth/SbxAuth.java b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/auth/SbxAuth.java deleted file mode 100644 index 0443fc3..0000000 --- a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/auth/SbxAuth.java +++ /dev/null @@ -1,496 +0,0 @@ -package com.sbxcloud.android.sbxcloudsdk.auth; - -import android.app.Application; -import android.content.Context; -import android.content.SharedPreferences; - -import com.sbxcloud.android.sbxcloudsdk.auth.config.SbxAppKeyField; -import com.sbxcloud.android.sbxcloudsdk.auth.config.SbxDomainField; -import com.sbxcloud.android.sbxcloudsdk.auth.user.SbxAuthToken; -import com.sbxcloud.android.sbxcloudsdk.auth.user.SbxEmailField; -import com.sbxcloud.android.sbxcloudsdk.auth.user.SbxNameField; -import com.sbxcloud.android.sbxcloudsdk.auth.user.SbxPasswordField; -import com.sbxcloud.android.sbxcloudsdk.auth.user.SbxUsernameField; -import com.sbxcloud.android.sbxcloudsdk.exception.SbxAuthException; -import com.sbxcloud.android.sbxcloudsdk.exception.SbxConfigException; -import com.sbxcloud.android.sbxcloudsdk.util.SbxUrlComposer; -import com.sbxcloud.android.sbxcloudsdk.util.UrlHelper; - -import org.json.JSONObject; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Field; -import java.net.URL; - -import okhttp3.MediaType; -import okhttp3.RequestBody; - -/** - * Created by lgguzman on 18/02/17. - */ -@SuppressWarnings({ "unchecked", "rawtypes" }) -public class SbxAuth { - - - private static SbxAuth defaultSbxAuth; - private int domain; - private String appKey; - private String token; - private boolean HttpLog; - private Context context; - private SharedPreferences sharedPreferences; - private static final String FILE_NAME=SbxAuth.class.getName(); - private static final String FILE_NAME_TOKEN=FILE_NAME+"_Token"; - private static final String FILE_NAME_DOMAIN=FILE_NAME+"_Domain"; - private static final String FILE_NAME_APPKEY=FILE_NAME+"_Appkey"; - - public boolean isHttpLog() { - return HttpLog; - } - - public void setHttpLog(boolean httpLog) { - HttpLog = httpLog; - } - - - public Context getContext() { - return context; - } - - /** - * initialize the data for comunicate on sbxcloud.com - * @param domain the id of the domain on sbxcloud.com - * @param appKey the app key on sbxcloud.com - */ - public static void initializeIfIsNecessary(Context context, int domain, String appKey) { - if(defaultSbxAuth ==null) { - defaultSbxAuth = new SbxAuth(); - defaultSbxAuth.context = context; - defaultSbxAuth.domain = domain; - defaultSbxAuth.appKey = appKey; - defaultSbxAuth.sharedPreferences = context.getSharedPreferences(FILE_NAME,Context.MODE_PRIVATE); - defaultSbxAuth.sharedPreferences.edit().putString(FILE_NAME_APPKEY, defaultSbxAuth.appKey) - .putInt(FILE_NAME_DOMAIN, defaultSbxAuth.domain).apply(); - } - } - - /** - * - * @param app - * @throws SbxConfigException - */ - public static void initialize(Application app)throws SbxConfigException{ - defaultSbxAuth = new SbxAuth(); - defaultSbxAuth.context = app.getApplicationContext(); - defaultSbxAuth.context=app.getApplicationContext(); - defaultSbxAuth.domain=getDomainAnnotation(app); - defaultSbxAuth.appKey=getAppKeyAnnotation(app); - defaultSbxAuth.sharedPreferences = defaultSbxAuth.context.getSharedPreferences(FILE_NAME,Context.MODE_PRIVATE); - defaultSbxAuth.sharedPreferences.edit().putString(FILE_NAME_APPKEY, defaultSbxAuth.appKey) - .putInt(FILE_NAME_DOMAIN, defaultSbxAuth.domain).apply(); - } - - /** - * - * @return - * @throws SbxConfigException - */ - public static SbxAuth getDefaultSbxAuth()throws SbxConfigException { - if(defaultSbxAuth==null) - throw new SbxConfigException("SbxAuth not initialized"); - return defaultSbxAuth; - } - - /** - * - * @return - * @throws SbxConfigException - */ - public int getDomain()throws SbxConfigException { - if(domain==0){ - if(sharedPreferences==null) - throw new SbxConfigException("SbxAuth not initialized"); - else - return domain = sharedPreferences.getInt(FILE_NAME_DOMAIN,0); - } - return domain; - } - - /** - * - * @return - * @throws SbxConfigException - */ - public String getToken()throws SbxConfigException { - if(token==null){ - if (sharedPreferences.getString(FILE_NAME_TOKEN,"").isEmpty()) - throw new SbxConfigException("User is not login yet."); - return token = sharedPreferences.getString(FILE_NAME_TOKEN,""); - } - return token; - } - - /** - * - * @return - * @throws SbxConfigException - */ - public String getAppKey()throws SbxConfigException{ - if(appKey==null){ - if(sharedPreferences==null) - throw new SbxConfigException("SbxAuth not initialized"); - else - return appKey = sharedPreferences.getString(FILE_NAME_APPKEY,""); - } - return appKey; - } - - - public void resetToken(){ - token=null; - if(sharedPreferences!=null) - sharedPreferences.edit().putString(FILE_NAME_TOKEN,"").apply(); - } - - /** - * - * @param obj - * @return - * @throws SbxConfigException - */ - public String refreshToken(final Object obj)throws SbxConfigException, SbxAuthException{ - Class myClass=obj.getClass(); - final Field[] variables = myClass.getDeclaredFields(); - for (final Field variable : variables) { - - final Annotation annotation = variable.getAnnotation(SbxAuthToken.class); - - if (annotation != null && annotation instanceof SbxAuthToken) { - try { - boolean isAccessible=variable.isAccessible(); - variable.setAccessible(true); - token= (String)variable.get(obj); - variable.setAccessible(isAccessible); - sharedPreferences.edit().putString(FILE_NAME_TOKEN,token).apply(); - return token; - } catch (IllegalArgumentException | IllegalAccessException e) { - throw new SbxConfigException(e); - } - - } - } - throw new SbxAuthException(); - } - - /** - * - * @param app - * @return - * @throws SbxConfigException - */ - private static String getAppKeyAnnotation(final Object app)throws SbxConfigException{ - Class myClass=app.getClass(); - final Field[] variables = myClass.getDeclaredFields(); - for (final Field variable : variables) { - - final Annotation annotation = variable.getAnnotation(SbxAppKeyField.class); - - if (annotation != null && annotation instanceof SbxAppKeyField) { - try { - boolean isAccessible=variable.isAccessible(); - variable.setAccessible(true); - String s= (String)variable.get(app); - variable.setAccessible(isAccessible); - return s; - } catch (IllegalArgumentException | IllegalAccessException e) { - throw new SbxConfigException(e); - } - - } - } - throw new SbxConfigException(); - } - - /** - * - * @param app - * @return - * @throws SbxConfigException - */ - private static int getDomainAnnotation(final Object app) throws SbxConfigException{ - Class myClass=app.getClass(); - final Field[] variables = myClass.getDeclaredFields(); - for (final Field variable : variables) { - - final Annotation annotation = variable.getAnnotation(SbxDomainField.class); - - if (annotation != null && annotation instanceof SbxDomainField) { - try { - boolean isAccessible=variable.isAccessible(); - variable.setAccessible(true); - int s= variable.getInt(app); - variable.setAccessible(isAccessible); - return s; - } catch (IllegalArgumentException | IllegalAccessException e) { - throw new SbxConfigException(e); - } - - } - } - throw new SbxConfigException(); - } - - - public SbxUrlComposer getUrllogin(Object o)throws SbxConfigException, SbxAuthException{ - int domain=getDomain(); - String appKey=getAppKey(); - String username=null; - String password=null; - String email=null; - Class myClass=o.getClass(); - final Field[] variables = myClass.getDeclaredFields(); - for (final Field variable : variables) { - - - final Annotation annotation = variable.getAnnotation(SbxUsernameField.class); - - if (annotation != null && annotation instanceof SbxUsernameField) { - try { - boolean isAccessible=variable.isAccessible(); - variable.setAccessible(true); - username= (String)variable.get(o); - variable.setAccessible(isAccessible); - } catch (IllegalArgumentException | IllegalAccessException e) { - throw new SbxAuthException(e); - } - - } - - - final Annotation annotationE = variable.getAnnotation(SbxEmailField.class); - - if (annotationE != null && annotationE instanceof SbxEmailField) { - try { - boolean isAccessible=variable.isAccessible(); - variable.setAccessible(true); - email= (String)variable.get(o); - variable.setAccessible(isAccessible); - } catch (IllegalArgumentException | IllegalAccessException e) { - throw new SbxAuthException(e); - } - - } - - final Annotation annotationP = variable.getAnnotation(SbxPasswordField.class); - - if (annotationP != null && annotationP instanceof SbxPasswordField) { - try { - boolean isAccessible=variable.isAccessible(); - variable.setAccessible(true); - password= (String)variable.get(o); - variable.setAccessible(isAccessible); - } catch (IllegalArgumentException | IllegalAccessException e) { - throw new SbxAuthException(e); - } - - } - } - SbxUrlComposer sbxUrlComposer; - - if(username==null){ - if(email==null){ - throw new SbxAuthException(); - }else{ - if(password==null){ - throw new SbxAuthException(); - }else{ - sbxUrlComposer = new SbxUrlComposer( - UrlHelper.URL_LOGIN - , UrlHelper.GET - ).setUrlParam("email",email) - .setUrlParam("password",password); - } - } - }else{ - if(password==null){ - throw new SbxAuthException(); - }else{ - sbxUrlComposer = new SbxUrlComposer( - UrlHelper.URL_LOGIN - , UrlHelper.GET - ).setUrlParam("login",username) - .setUrlParam("password",password); - } - } - return sbxUrlComposer - .addHeader(UrlHelper.HEADER_KEY_APP_KEY,appKey); - // .addHeader(UrlHelper.HEADER_KEY_ENCODING,UrlHelper.HEADER_GZIP); - } - - public SbxUrlComposer getUrlSigIn(Object o)throws SbxConfigException, SbxAuthException { - int domain = getDomain(); - String appKey = getAppKey(); - String username = null; - String password = null; - String email = null; - String name=null; - Class myClass = o.getClass(); - final Field[] variables = myClass.getDeclaredFields(); - for (final Field variable : variables) { - - final Annotation annotation = variable.getAnnotation(SbxUsernameField.class); - - if (annotation != null && annotation instanceof SbxUsernameField) { - try { - boolean isAccessible=variable.isAccessible(); - variable.setAccessible(true); - username = (String) variable.get(o); - variable.setAccessible(isAccessible); - } catch (IllegalArgumentException | IllegalAccessException e) { - throw new SbxAuthException(e); - } - - } - - - final Annotation annotationE = variable.getAnnotation(SbxEmailField.class); - - if (annotationE != null && annotationE instanceof SbxEmailField) { - try { - boolean isAccessible=variable.isAccessible(); - variable.setAccessible(true); - email = (String) variable.get(o); - variable.setAccessible(isAccessible); - } catch (IllegalArgumentException | IllegalAccessException e) { - throw new SbxAuthException(e); - } - - } - - final Annotation annotationP = variable.getAnnotation(SbxPasswordField.class); - - if (annotationP != null && annotationP instanceof SbxPasswordField) { - try { - boolean isAccessible=variable.isAccessible(); - variable.setAccessible(true); - password = (String) variable.get(o); - variable.setAccessible(isAccessible); - } catch (IllegalArgumentException | IllegalAccessException e) { - throw new SbxAuthException(e); - } - - } - - final Annotation annotationN = variable.getAnnotation(SbxNameField.class); - - if (annotationN != null && annotationN instanceof SbxNameField) { - try { - boolean isAccessible=variable.isAccessible(); - variable.setAccessible(true); - name = (String) variable.get(o); - variable.setAccessible(isAccessible); - } catch (IllegalArgumentException | IllegalAccessException e) { - throw new SbxAuthException(e); - } - - } - } - if(username == null){ - throw new SbxAuthException("Annnotation SbxUsernameField is required"); - } - if(email == null){ - throw new SbxAuthException("Annnotation SbxEmailField is required"); - } - if(password == null){ - throw new SbxAuthException("Annnotation SbxPasswordField is required"); - } - if(name == null){ - throw new SbxAuthException("Annnotation SbxNameField is required"); - } - - return new SbxUrlComposer( - UrlHelper.URL_SIGN_UP - , UrlHelper.GET - ).setUrlParam("email",email) - .setUrlParam("password",password) - .setUrlParam("login",username) - .setUrlParam("name",name) - .setUrlParam("domain",domain+"") - .addHeader(UrlHelper.HEADER_KEY_APP_KEY, appKey); - // .addHeader(UrlHelper.HEADER_KEY_ENCODING, UrlHelper.HEADER_GZIP); - } - - public static SbxUrlComposer getUrlRequestPasswordCode(String emailTemplate, String subject, String from) throws Exception{ - String appKey = SbxAuth.getDefaultSbxAuth().getAppKey(); - // String token = SbxAuth.getDefaultSbxAuth().getToken(); - int domain = SbxAuth.getDefaultSbxAuth().getDomain(); - SbxUrlComposer sbxUrlComposer = new SbxUrlComposer( - UrlHelper.PASSWORD_REQUEST - , UrlHelper.POST - ); - JSONObject jsonObject = new JSONObject(); - jsonObject.put("domain", domain); - jsonObject.put("email_template", emailTemplate); - jsonObject.put("subject", subject); - jsonObject.put("user_email", from); - return sbxUrlComposer - .addHeader(UrlHelper.HEADER_KEY_APP_KEY, appKey) -// .addHeader(UrlHelper.HEADER_KEY_ENCODING, UrlHelper.HEADER_GZIP) -// .addHeader(UrlHelper.HEADER_KEY_CONTENT_TYPE, UrlHelper.HEADER_JSON) - // .addHeader(UrlHelper.HEADER_KEY_AUTORIZATION, UrlHelper.HEADER_BEARER+token) - .addBody(jsonObject); - } - - - public static SbxUrlComposer getUrlChangePasswordCode(int userId, int code, String password) throws Exception{ - String appKey = SbxAuth.getDefaultSbxAuth().getAppKey(); - // String token = SbxAuth.getDefaultSbxAuth().getToken(); - int domain = SbxAuth.getDefaultSbxAuth().getDomain(); - SbxUrlComposer sbxUrlComposer = new SbxUrlComposer( - UrlHelper.PASSWORD_REQUEST - , UrlHelper.PUT - ); - JSONObject jsonObject = new JSONObject(); - jsonObject.put("domain", domain); - jsonObject.put("user_id", userId); - jsonObject.put("code", code); - jsonObject.put("password", password); - return sbxUrlComposer - .addHeader(UrlHelper.HEADER_KEY_APP_KEY, appKey) -// .addHeader(UrlHelper.HEADER_KEY_ENCODING, UrlHelper.HEADER_GZIP) -// .addHeader(UrlHelper.HEADER_KEY_CONTENT_TYPE, UrlHelper.HEADER_JSON) - // .addHeader(UrlHelper.HEADER_KEY_AUTORIZATION, UrlHelper.HEADER_BEARER+token) - .addBody(jsonObject); - } - - - public static SbxUrlComposer getUrlDomainList() throws Exception{ - String appKey = SbxAuth.getDefaultSbxAuth().getAppKey(); - // String token = SbxAuth.getDefaultSbxAuth().getToken(); - SbxUrlComposer sbxUrlComposer = new SbxUrlComposer( - UrlHelper.DOMAIN - , UrlHelper.GET - ); - return sbxUrlComposer - .addHeader(UrlHelper.HEADER_KEY_APP_KEY, appKey); -// .addHeader(UrlHelper.HEADER_KEY_ENCODING, UrlHelper.HEADER_GZIP) -// .addHeader(UrlHelper.HEADER_KEY_CONTENT_TYPE, UrlHelper.HEADER_JSON) -// .addHeader(UrlHelper.HEADER_KEY_AUTORIZATION, UrlHelper.HEADER_BEARER+token); - } - - public static SbxUrlComposer validateToken(String token) throws Exception{ - String appKey = SbxAuth.getDefaultSbxAuth().getAppKey(); - // String token = SbxAuth.getDefaultSbxAuth().getToken(); - SbxUrlComposer sbxUrlComposer = new SbxUrlComposer( - UrlHelper.VALIDATE - , UrlHelper.GET - ); - return sbxUrlComposer - .addHeader(UrlHelper.HEADER_KEY_APP_KEY, appKey) - .setUrlParam("token",token); -// .addHeader(UrlHelper.HEADER_KEY_ENCODING, UrlHelper.HEADER_GZIP) -// .addHeader(UrlHelper.HEADER_KEY_CONTENT_TYPE, UrlHelper.HEADER_JSON) -// .addHeader(UrlHelper.HEADER_KEY_AUTORIZATION, UrlHelper.HEADER_BEARER+token); - } - -} diff --git a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/auth/config/SbxAppKeyField.java b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/auth/config/SbxAppKeyField.java deleted file mode 100644 index 4e88616..0000000 --- a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/auth/config/SbxAppKeyField.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.sbxcloud.android.sbxcloudsdk.auth.config; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Created by lgguzman on 18/02/17. - */ - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface SbxAppKeyField { -} diff --git a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/auth/config/SbxDomainField.java b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/auth/config/SbxDomainField.java deleted file mode 100644 index 0068382..0000000 --- a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/auth/config/SbxDomainField.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.sbxcloud.android.sbxcloudsdk.auth.config; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Created by lgguzman on 18/02/17. - */ - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface SbxDomainField { -} diff --git a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/auth/user/SbxAuthToken.java b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/auth/user/SbxAuthToken.java deleted file mode 100644 index 3b4cb59..0000000 --- a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/auth/user/SbxAuthToken.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.sbxcloud.android.sbxcloudsdk.auth.user; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Created by lgguzman on 20/02/17. - */ - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface SbxAuthToken { -} diff --git a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/auth/user/SbxEmailField.java b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/auth/user/SbxEmailField.java deleted file mode 100644 index 7e86c3d..0000000 --- a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/auth/user/SbxEmailField.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.sbxcloud.android.sbxcloudsdk.auth.user; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Created by lgguzman on 19/02/17. - */ - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface SbxEmailField { -} diff --git a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/auth/user/SbxNameField.java b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/auth/user/SbxNameField.java deleted file mode 100644 index 84bb891..0000000 --- a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/auth/user/SbxNameField.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.sbxcloud.android.sbxcloudsdk.auth.user; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Created by lgguzman on 19/02/17. - */ - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface SbxNameField { -} diff --git a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/auth/user/SbxPasswordField.java b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/auth/user/SbxPasswordField.java deleted file mode 100644 index e847dc0..0000000 --- a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/auth/user/SbxPasswordField.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.sbxcloud.android.sbxcloudsdk.auth.user; - -/** - * Created by lgguzman on 19/02/17. - */ - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface SbxPasswordField { -} diff --git a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/auth/user/SbxUsernameField.java b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/auth/user/SbxUsernameField.java deleted file mode 100644 index 4b586f3..0000000 --- a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/auth/user/SbxUsernameField.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.sbxcloud.android.sbxcloudsdk.auth.user; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Created by lgguzman on 19/02/17. - */ - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface SbxUsernameField { -} diff --git a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/cloudscript/SbxCloudScriptHelper.java b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/cloudscript/SbxCloudScriptHelper.java deleted file mode 100644 index 9e840e5..0000000 --- a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/cloudscript/SbxCloudScriptHelper.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.sbxcloud.android.sbxcloudsdk.cloudscript; - -import com.sbxcloud.android.sbxcloudsdk.auth.SbxAuth; -import com.sbxcloud.android.sbxcloudsdk.query.SbxQueryBuilder; -import com.sbxcloud.android.sbxcloudsdk.util.SbxUrlComposer; -import com.sbxcloud.android.sbxcloudsdk.util.UrlHelper; - -import org.json.JSONObject; - -/** - * Created by lgguzman on 12/06/17. - */ - -public class SbxCloudScriptHelper { - - /** - * - * @param key llave del cloudScript - * @param params parametros del CloudScript - * @return - * @throws Exception - */ - public static SbxUrlComposer getUrlRunCloudScript(String key, JSONObject params)throws Exception { - - // int domain = SbxAuth.getDefaultSbxAuth().getDomain(); - String appKey = SbxAuth.getDefaultSbxAuth().getAppKey(); - String token = SbxAuth.getDefaultSbxAuth().getToken(); - SbxUrlComposer sbxUrlComposer = new SbxUrlComposer( UrlHelper.CLOUDSCRIPT_RUN, UrlHelper.POST); - JSONObject jsonObject = new JSONObject(); - try{ - jsonObject.put("key",key); - jsonObject.put("params",params); - }catch (Exception ex){} - return sbxUrlComposer - .addHeader(UrlHelper.HEADER_KEY_APP_KEY, appKey) - // .addHeader(UrlHelper.HEADER_KEY_ENCODING, UrlHelper.HEADER_GZIP) - .addHeader(UrlHelper.HEADER_KEY_CONTENT_TYPE, UrlHelper.HEADER_JSON) - .addHeader(UrlHelper.HEADER_KEY_AUTORIZATION, UrlHelper.HEADER_BEARER+token) - .addBody(jsonObject); - } - -} diff --git a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/exception/SbxAuthException.java b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/exception/SbxAuthException.java deleted file mode 100644 index 57a5377..0000000 --- a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/exception/SbxAuthException.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.sbxcloud.android.sbxcloudsdk.exception; - -/** - * Created by lgguzman on 19/02/17. - */ - -public class SbxAuthException extends Exception{ - - public SbxAuthException(){ - super("No annotations found"); - } - - public SbxAuthException(String s){ - super(s); - } - - public SbxAuthException(Exception e){ - super(e); - } -} diff --git a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/exception/SbxConfigException.java b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/exception/SbxConfigException.java deleted file mode 100644 index 32d5659..0000000 --- a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/exception/SbxConfigException.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.sbxcloud.android.sbxcloudsdk.exception; - -/** - * Created by lgguzman on 18/02/17. - */ - -public class SbxConfigException extends Exception { - - public SbxConfigException(){ - super("No annotations found"); - } - - public SbxConfigException(String s){ - super(s); - } - - public SbxConfigException(Exception e){ - super(e); - } -} diff --git a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/exception/SbxModelException.java b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/exception/SbxModelException.java deleted file mode 100644 index 02170a3..0000000 --- a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/exception/SbxModelException.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.sbxcloud.android.sbxcloudsdk.exception; - -/** - * Created by lgguzman on 20/02/17. - */ - -public class SbxModelException extends Exception{ - - public SbxModelException(){ - super("No annotations found"); - } - - public SbxModelException(String s){ - super(s); - } - - public SbxModelException(Exception e){ - super(e); - } -} diff --git a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/message/SbxChannelHelper.java b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/message/SbxChannelHelper.java deleted file mode 100644 index edb8b8f..0000000 --- a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/message/SbxChannelHelper.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.sbxcloud.android.sbxcloudsdk.message; - -import com.sbxcloud.android.sbxcloudsdk.auth.SbxAuth; -import com.sbxcloud.android.sbxcloudsdk.query.SbxQueryBuilder; -import com.sbxcloud.android.sbxcloudsdk.util.SbxJsonModeler; -import com.sbxcloud.android.sbxcloudsdk.util.SbxUrlComposer; -import com.sbxcloud.android.sbxcloudsdk.util.UrlHelper; - -import org.json.JSONArray; -import org.json.JSONObject; - -/** - * Created by lgguzman on 24/03/17. - */ - -public class SbxChannelHelper { - - public static SbxUrlComposer getUrlCreateChannel(String channelName) throws Exception{ - String appKey = SbxAuth.getDefaultSbxAuth().getAppKey(); - String token = SbxAuth.getDefaultSbxAuth().getToken(); - SbxUrlComposer sbxUrlComposer = new SbxUrlComposer( - UrlHelper.MESSAGE_CHANNEL - , UrlHelper.POST - ); - JSONObject jsonObject = new JSONObject(); - jsonObject.put("name", channelName); - return sbxUrlComposer - .addHeader(UrlHelper.HEADER_KEY_APP_KEY, appKey) -// .addHeader(UrlHelper.HEADER_KEY_ENCODING, UrlHelper.HEADER_GZIP) -// .addHeader(UrlHelper.HEADER_KEY_CONTENT_TYPE, UrlHelper.HEADER_JSON) - .addHeader(UrlHelper.HEADER_KEY_AUTORIZATION, UrlHelper.HEADER_BEARER+token) - .addBody(jsonObject); - } - - public static SbxUrlComposer getUrlAddMember(int channelId, int []idUsers) throws Exception{ - String appKey = SbxAuth.getDefaultSbxAuth().getAppKey(); - String token = SbxAuth.getDefaultSbxAuth().getToken(); - SbxUrlComposer sbxUrlComposer = new SbxUrlComposer( - UrlHelper.MESSAGE_CHANNEL_MEMBER - , UrlHelper.POST - ); - JSONObject jsonObject = new JSONObject(); - JSONArray jsonArray = new JSONArray(); - for (int i=0;i clazz)throws Exception { if(sbxUser==null) { - SharedPreferences sharedPreferences = SbxAuth.getDefaultSbxAuth().getContext().getSharedPreferences(FILE_NAME,Context.MODE_PRIVATE); + SharedPreferences sharedPreferences = SbxAuthAndroid.getContext().getSharedPreferences(FILE_NAME,Context.MODE_PRIVATE); String s=sharedPreferences.getString(FILE_NAME_USER,""); if(s.equals("")) { return null; diff --git a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/callback/SbxArrayResponse.java b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/callback/SbxArrayResponse.java deleted file mode 100644 index 0ba9252..0000000 --- a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/callback/SbxArrayResponse.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.sbxcloud.android.sbxcloudsdk.net.callback; - -import java.util.List; - -/** - * Created by lgguzman on 21/02/17. - */ - -public interface SbxArrayResponse { - void onError(Exception e); - - void onSuccess(List response); -} diff --git a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/callback/SbxSimpleResponse.java b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/callback/SbxSimpleResponse.java deleted file mode 100644 index 57e4420..0000000 --- a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/callback/SbxSimpleResponse.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.sbxcloud.android.sbxcloudsdk.net.callback; - - -import okhttp3.Callback; - -/** - * Created by lgguzman on 21/02/17. - */ - -public interface SbxSimpleResponse { - - void onError(Exception e); - - void onSuccess(T tClass); -} diff --git a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/cloudscript/SbxCloudScript.java b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/cloudscript/SbxCloudScript.java index 1e6d146..cb59d95 100644 --- a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/cloudscript/SbxCloudScript.java +++ b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/cloudscript/SbxCloudScript.java @@ -1,12 +1,12 @@ package com.sbxcloud.android.sbxcloudsdk.net.cloudscript; -import com.sbxcloud.android.sbxcloudsdk.cloudscript.SbxCloudScriptHelper; +import com.sbxcloud.java.sbxcloudsdk.cloudscript.SbxCloudScriptHelper; import com.sbxcloud.android.sbxcloudsdk.net.ApiManager; -import com.sbxcloud.android.sbxcloudsdk.net.callback.SbxSimpleResponse; +import com.sbxcloud.java.sbxcloudsdk.callback.SbxSimpleResponse; import com.sbxcloud.android.sbxcloudsdk.net.model.SbxModel; -import com.sbxcloud.android.sbxcloudsdk.query.SbxModelHelper; -import com.sbxcloud.android.sbxcloudsdk.util.SbxDataValidator; -import com.sbxcloud.android.sbxcloudsdk.util.SbxUrlComposer; +import com.sbxcloud.java.sbxcloudsdk.query.SbxModelHelper; +import com.sbxcloud.java.sbxcloudsdk.util.SbxDataValidator; +import com.sbxcloud.java.sbxcloudsdk.util.SbxUrlComposer; import org.json.JSONArray; import org.json.JSONObject; diff --git a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/message/SbxChannel.java b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/message/SbxChannel.java index c0d029a..7485d8e 100644 --- a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/message/SbxChannel.java +++ b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/message/SbxChannel.java @@ -1,14 +1,14 @@ package com.sbxcloud.android.sbxcloudsdk.net.message; -import com.sbxcloud.android.sbxcloudsdk.message.SbxChannelHelper; +import com.sbxcloud.java.sbxcloudsdk.message.SbxChannelHelper; import com.sbxcloud.android.sbxcloudsdk.net.ApiManager; -import com.sbxcloud.android.sbxcloudsdk.net.callback.SbxArrayResponse; -import com.sbxcloud.android.sbxcloudsdk.net.callback.SbxSimpleResponse; -import com.sbxcloud.android.sbxcloudsdk.query.SbxModelHelper; -import com.sbxcloud.android.sbxcloudsdk.util.SbxDataValidator; -import com.sbxcloud.android.sbxcloudsdk.util.SbxJsonModeler; -import com.sbxcloud.android.sbxcloudsdk.util.SbxMagicComposer; -import com.sbxcloud.android.sbxcloudsdk.util.SbxUrlComposer; +import com.sbxcloud.java.sbxcloudsdk.callback.SbxArrayResponse; +import com.sbxcloud.java.sbxcloudsdk.callback.SbxSimpleResponse; +import com.sbxcloud.java.sbxcloudsdk.query.SbxModelHelper; +import com.sbxcloud.java.sbxcloudsdk.util.SbxDataValidator; +import com.sbxcloud.java.sbxcloudsdk.util.SbxJsonModeler; +import com.sbxcloud.java.sbxcloudsdk.util.SbxMagicComposer; +import com.sbxcloud.java.sbxcloudsdk.util.SbxUrlComposer; import org.json.JSONArray; import org.json.JSONObject; diff --git a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/message/SbxMessage.java b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/message/SbxMessage.java index 6b22a4f..252393d 100644 --- a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/message/SbxMessage.java +++ b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/message/SbxMessage.java @@ -1,6 +1,6 @@ package com.sbxcloud.android.sbxcloudsdk.net.message; -import com.sbxcloud.android.sbxcloudsdk.util.SbxJsonModeler; +import com.sbxcloud.java.sbxcloudsdk.util.SbxJsonModeler; import java.util.Date; diff --git a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/message/SbxPush.java b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/message/SbxPush.java index ba08b25..01edf01 100644 --- a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/message/SbxPush.java +++ b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/message/SbxPush.java @@ -1,10 +1,10 @@ package com.sbxcloud.android.sbxcloudsdk.net.message; import com.sbxcloud.android.sbxcloudsdk.net.ApiManager; -import com.sbxcloud.android.sbxcloudsdk.net.callback.SbxSimpleResponse; -import com.sbxcloud.android.sbxcloudsdk.push.SbxPushHelper; -import com.sbxcloud.android.sbxcloudsdk.util.SbxJsonModeler; -import com.sbxcloud.android.sbxcloudsdk.util.SbxUrlComposer; +import com.sbxcloud.java.sbxcloudsdk.callback.SbxSimpleResponse; +import com.sbxcloud.java.sbxcloudsdk.push.SbxPushHelper; +import com.sbxcloud.java.sbxcloudsdk.util.SbxJsonModeler; +import com.sbxcloud.java.sbxcloudsdk.util.SbxUrlComposer; import org.json.JSONObject; diff --git a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/model/SbxFile.java b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/model/SbxFile.java index 2c9012d..10ef37b 100644 --- a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/model/SbxFile.java +++ b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/model/SbxFile.java @@ -1,11 +1,11 @@ package com.sbxcloud.android.sbxcloudsdk.net.model; -import com.sbxcloud.android.sbxcloudsdk.message.SbxChannelHelper; +import com.sbxcloud.java.sbxcloudsdk.message.SbxChannelHelper; import com.sbxcloud.android.sbxcloudsdk.net.ApiManager; -import com.sbxcloud.android.sbxcloudsdk.net.callback.SbxSimpleResponse; +import com.sbxcloud.java.sbxcloudsdk.callback.SbxSimpleResponse; import com.sbxcloud.android.sbxcloudsdk.net.message.SbxChannel; -import com.sbxcloud.android.sbxcloudsdk.util.SbxFileHelper; -import com.sbxcloud.android.sbxcloudsdk.util.SbxUrlComposer; +import com.sbxcloud.java.sbxcloudsdk.util.SbxFileHelper; +import com.sbxcloud.java.sbxcloudsdk.util.SbxUrlComposer; import org.json.JSONObject; diff --git a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/model/SbxModel.java b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/model/SbxModel.java index 050432a..39cf076 100644 --- a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/model/SbxModel.java +++ b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/model/SbxModel.java @@ -2,16 +2,16 @@ import android.util.Log; -import com.sbxcloud.android.sbxcloudsdk.auth.SbxAuth; +import com.sbxcloud.java.sbxcloudsdk.auth.SbxAuth; import com.sbxcloud.android.sbxcloudsdk.net.ApiManager; import com.sbxcloud.android.sbxcloudsdk.net.auth.SbxUser; -import com.sbxcloud.android.sbxcloudsdk.net.callback.SbxArrayResponse; -import com.sbxcloud.android.sbxcloudsdk.net.callback.SbxSimpleResponse; -import com.sbxcloud.android.sbxcloudsdk.query.SbxModelHelper; -import com.sbxcloud.android.sbxcloudsdk.query.SbxQueryBuilder; -import com.sbxcloud.android.sbxcloudsdk.util.SbxDataValidator; -import com.sbxcloud.android.sbxcloudsdk.util.SbxMagicComposer; -import com.sbxcloud.android.sbxcloudsdk.util.SbxUrlComposer; +import com.sbxcloud.java.sbxcloudsdk.callback.SbxArrayResponse; +import com.sbxcloud.java.sbxcloudsdk.callback.SbxSimpleResponse; +import com.sbxcloud.java.sbxcloudsdk.query.SbxModelHelper; +import com.sbxcloud.java.sbxcloudsdk.query.SbxQueryBuilder; +import com.sbxcloud.java.sbxcloudsdk.util.SbxDataValidator; +import com.sbxcloud.java.sbxcloudsdk.util.SbxMagicComposer; +import com.sbxcloud.java.sbxcloudsdk.util.SbxUrlComposer; import org.json.JSONArray; import org.json.JSONObject; @@ -64,7 +64,7 @@ public void onResponse(Call call, Response response) throws IOException { }); } - public Single save(Class type)throws Exception{ + public Single save()throws Exception{ SbxUrlComposer sbxUrlComposer = SbxModelHelper.getUrlInsertOrUpdateRow(SbxModel.this); final Request request = ApiManager.getInstance().sbxUrlComposer2Request(sbxUrlComposer); return Single.create(new SingleOnSubscribe() { @@ -138,7 +138,7 @@ public SingleSource> apply(Throwable throwable) throws Excepti } - public Single fetch(Class type)throws Exception{ + public Single fetch()throws Exception{ String []keys = {SbxModelHelper.getKeyFromAnnotation(this)}; SbxQueryBuilder sbxQueryBuilder = (new SbxQuery(this.getClass())).sbxQueryBuilder; @@ -156,7 +156,7 @@ public void run() { if (jsonObject.getBoolean("success")) { JSONArray jsonArray=jsonObject.getJSONArray("results"); if(jsonArray.length()>0) { - SbxMagicComposer.getSbxModel(jsonArray.getJSONObject(0), SbxModel.this.getClass(),SbxModel.this, 0); + SbxMagicComposer.getSbxModel(jsonArray.getJSONObject(0), SbxModel.this, 0); e.onSuccess((T)SbxModel.this); }else{ @@ -182,7 +182,7 @@ public SingleSource apply(Throwable throwable) throws Exception { }); } - public Single fetch(Class type,String []properties)throws Exception{ + public Single fetch(String []properties)throws Exception{ String []keys = {SbxModelHelper.getKeyFromAnnotation(this)}; SbxQueryBuilder sbxQueryBuilder = (new SbxQuery(this.getClass())).fetch(properties).sbxQueryBuilder; SbxUrlComposer sbxUrlComposer = SbxModelHelper.getUrlQueryKeys(sbxQueryBuilder, keys); @@ -201,9 +201,9 @@ public void run() { JSONArray jsonArray=jsonObject.getJSONArray("results"); if(jsonArray.length()>0) { if(jsonObject.has("fetched_results")) { - SbxMagicComposer.getSbxModel(jsonArray.getJSONObject(0), SbxModel.this.getClass(), SbxModel.this, 0,jsonObject.getJSONObject("fetched_results")); + SbxMagicComposer.getSbxModel(jsonArray.getJSONObject(0), SbxModel.this, 0,jsonObject.getJSONObject("fetched_results")); }else{ - SbxMagicComposer.getSbxModel(jsonArray.getJSONObject(0), SbxModel.this.getClass(), SbxModel.this, 0); + SbxMagicComposer.getSbxModel(jsonArray.getJSONObject(0), SbxModel.this, 0); } e.onSuccess((T)SbxModel.this); @@ -250,7 +250,7 @@ public void onResponse(Call call, Response response) throws IOException { JSONArray jsonArray=jsonObject.getJSONArray("results"); if(jsonArray.length()>0) { - SbxMagicComposer.getSbxModel(jsonArray.getJSONObject(0), SbxModel.this.getClass(),SbxModel.this, 0); + SbxMagicComposer.getSbxModel(jsonArray.getJSONObject(0), SbxModel.this, 0); simpleResponse.onSuccess(SbxModel.this); }else{ simpleResponse.onError(new Exception("key not found")); @@ -288,9 +288,9 @@ public void onResponse(Call call, Response response) throws IOException { JSONArray jsonArray=jsonObject.getJSONArray("results"); if(jsonArray.length()>0) { if(jsonObject.has("fetched_results")) { - SbxMagicComposer.getSbxModel(jsonArray.getJSONObject(0), SbxModel.this.getClass(), SbxModel.this, 0,jsonObject.getJSONObject("fetched_results")); + SbxMagicComposer.getSbxModel(jsonArray.getJSONObject(0), SbxModel.this, 0,jsonObject.getJSONObject("fetched_results")); }else{ - SbxMagicComposer.getSbxModel(jsonArray.getJSONObject(0), SbxModel.this.getClass(), SbxModel.this, 0); + SbxMagicComposer.getSbxModel(jsonArray.getJSONObject(0), SbxModel.this, 0); } simpleResponse.onSuccess(SbxModel.this); }else{ @@ -308,7 +308,7 @@ public void onResponse(Call call, Response response) throws IOException { }); } - public Single delete(Class type)throws Exception{ + public Single delete()throws Exception{ SbxQueryBuilder sbxQueryBuilder = SbxModelHelper.prepareQueryToDelete(this.getClass()); sbxQueryBuilder.addDeleteKey(SbxModelHelper.getKeyFromAnnotation(this)); diff --git a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/model/SbxQuery.java b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/model/SbxQuery.java index 787edcb..f98d6a0 100644 --- a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/model/SbxQuery.java +++ b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/net/model/SbxQuery.java @@ -4,11 +4,11 @@ import android.util.Log; import com.sbxcloud.android.sbxcloudsdk.net.ApiManager; -import com.sbxcloud.android.sbxcloudsdk.net.callback.SbxArrayResponse; -import com.sbxcloud.android.sbxcloudsdk.query.SbxModelHelper; -import com.sbxcloud.android.sbxcloudsdk.query.SbxQueryBuilder; -import com.sbxcloud.android.sbxcloudsdk.util.SbxMagicComposer; -import com.sbxcloud.android.sbxcloudsdk.util.SbxUrlComposer; +import com.sbxcloud.java.sbxcloudsdk.callback.SbxArrayResponse; +import com.sbxcloud.java.sbxcloudsdk.query.SbxModelHelper; +import com.sbxcloud.java.sbxcloudsdk.query.SbxQueryBuilder; +import com.sbxcloud.java.sbxcloudsdk.util.SbxMagicComposer; +import com.sbxcloud.java.sbxcloudsdk.util.SbxUrlComposer; import org.json.JSONArray; import org.json.JSONException; diff --git a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/push/SbxPushHelper.java b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/push/SbxPushHelper.java deleted file mode 100644 index cd29788..0000000 --- a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/push/SbxPushHelper.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.sbxcloud.android.sbxcloudsdk.push; - -import com.sbxcloud.android.sbxcloudsdk.auth.SbxAuth; -import com.sbxcloud.android.sbxcloudsdk.util.SbxJsonModeler; -import com.sbxcloud.android.sbxcloudsdk.util.SbxUrlComposer; -import com.sbxcloud.android.sbxcloudsdk.util.UrlHelper; - -import org.json.JSONObject; - -/** - * Created by lgguzman on 24/03/17. - */ - -public class SbxPushHelper { - - public static SbxUrlComposer getUrlSendPush(String title, String alias, String message, SbxJsonModeler sbxJsonModeler) throws Exception{ - - String appKey = SbxAuth.getDefaultSbxAuth().getAppKey(); - String token = SbxAuth.getDefaultSbxAuth().getToken(); - int domain= SbxAuth.getDefaultSbxAuth().getDomain(); - - SbxUrlComposer sbxUrlComposer = new SbxUrlComposer( - UrlHelper.PUSH - , UrlHelper.POST - ); - JSONObject jsonObject = new JSONObject(); - jsonObject.put("domain", domain); - jsonObject.put("message", message); - jsonObject.put("title", title); - jsonObject.put("alias", alias); - jsonObject.put("custom_fields", sbxJsonModeler.toJson()); - jsonObject.put("platform", 1); - return sbxUrlComposer - .addHeader(UrlHelper.HEADER_KEY_APP_KEY, appKey) -// .addHeader(UrlHelper.HEADER_KEY_ENCODING, UrlHelper.HEADER_GZIP) -// .addHeader(UrlHelper.HEADER_KEY_CONTENT_TYPE, UrlHelper.HEADER_JSON) - .addHeader(UrlHelper.HEADER_KEY_AUTORIZATION, UrlHelper.HEADER_BEARER+token) - .addBody(jsonObject); - } -} diff --git a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/query/SbxModelHelper.java b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/query/SbxModelHelper.java deleted file mode 100644 index 2407960..0000000 --- a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/query/SbxModelHelper.java +++ /dev/null @@ -1,438 +0,0 @@ -package com.sbxcloud.android.sbxcloudsdk.query; - -import com.sbxcloud.android.sbxcloudsdk.auth.SbxAuth; -import com.sbxcloud.android.sbxcloudsdk.exception.SbxAuthException; -import com.sbxcloud.android.sbxcloudsdk.exception.SbxModelException; -import com.sbxcloud.android.sbxcloudsdk.net.model.SbxQuery; -import com.sbxcloud.android.sbxcloudsdk.query.annotation.SbxKey; -import com.sbxcloud.android.sbxcloudsdk.query.annotation.SbxModelName; -import com.sbxcloud.android.sbxcloudsdk.query.annotation.SbxParamField; -import com.sbxcloud.android.sbxcloudsdk.util.SbxDataValidator; -import com.sbxcloud.android.sbxcloudsdk.util.SbxUrlComposer; -import com.sbxcloud.android.sbxcloudsdk.util.UrlHelper; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Field; -import java.util.Date; -import java.util.List; -import java.util.Objects; - -/** - * Created by lgguzman on 19/02/17. - */ -@SuppressWarnings({ "unchecked", "rawtypes" }) -public class SbxModelHelper { - - public static SbxUrlComposer getUrlInsertOrUpdateRows(List objects)throws Exception { - - if(objects.isEmpty()) - throw new SbxModelException("Array can not be empty"); - int domain = SbxAuth.getDefaultSbxAuth().getDomain(); - String appKey = SbxAuth.getDefaultSbxAuth().getAppKey(); - String token = SbxAuth.getDefaultSbxAuth().getToken(); - String key=null; - - Object of=objects.get(0); - key=getKeyFromAnnotation(of); - Class myClass = of.getClass(); - if(!SbxDataValidator.hasKeyAnnotation(myClass)){ - throw new SbxModelException("SbxKey is required"); - } - Annotation annotationClass = myClass.getAnnotation(SbxModelName.class); - String modelName=""; - if(annotationClass instanceof SbxModelName){ - SbxModelName myAnnotation = (SbxModelName) annotationClass; - modelName=myAnnotation.value(); - }else{ - throw new SbxModelException("SbxModelName is required"); - } - - SbxUrlComposer sbxUrlComposer = new SbxUrlComposer( - key==null||key.equals("")? UrlHelper.URL_INSERT:UrlHelper.URL_UPDATE - , UrlHelper.POST - ); - SbxQueryBuilder queryBuilder = new SbxQueryBuilder(domain, modelName, SbxQueryBuilder.TYPE.INSERT); - - - for(Object o: objects) { - - key=getKeyFromAnnotation(o); - queryBuilder.insertNewEmptyRow(); - if (!(key == null || key.equals(""))) - queryBuilder.insertFieldLastRow("_KEY", key); - final Field[] variables = myClass.getDeclaredFields(); - - for (final Field variable : variables) { - - final Annotation annotation = variable.getAnnotation(SbxParamField.class); - - if (annotation != null && annotation instanceof SbxParamField) { - try { - boolean isAccessible = variable.isAccessible(); - variable.setAccessible(true); - String name = SbxDataValidator.getAnnotationName(variable, annotation); - String variabletype = variable.getGenericType().toString(); - switch (variabletype) { - case "class java.lang.String": { - Object os = variable.get(o); - if (os != null) { - String data = (String) os; - queryBuilder.insertFieldLastRow(name, data); - } - break; - } - case "int": { - int data = variable.getInt(o); - if(SbxDataValidator.saveDefaultValue(annotation) || data!=0) - queryBuilder.insertFieldLastRow(name, data); - break; - } - case "class java.lang.Integer": { - int data = variable.getInt(o); - if(SbxDataValidator.saveDefaultValue(annotation) || data!=0) - queryBuilder.insertFieldLastRow(name, data); - break; - } - case "long": { - long data = variable.getLong(o); - if(SbxDataValidator.saveDefaultValue(annotation) || data!=0) - queryBuilder.insertFieldLastRow(name, data); - break; - } - case "class java.lang.Long": { - long data = variable.getLong(o); - if(SbxDataValidator.saveDefaultValue(annotation) || data!=0) - queryBuilder.insertFieldLastRow(name, data); - break; - } - case "double": { - double data = variable.getDouble(o); - if(SbxDataValidator.saveDefaultValue(annotation) || data!=0) - queryBuilder.insertFieldLastRow(name, data); - break; - } - case "class java.lang.Double": { - double data = variable.getDouble(o); - if(SbxDataValidator.saveDefaultValue(annotation) || data!=0) - queryBuilder.insertFieldLastRow(name, data); - break; - } - case "float": { - float data = variable.getFloat(o); - if(SbxDataValidator.saveDefaultValue(annotation) || data!=0) - queryBuilder.insertFieldLastRow(name, data); - break; - } - case "class java.lang.Float": { - float data = variable.getFloat(o); - if(SbxDataValidator.saveDefaultValue(annotation) || data!=0) - queryBuilder.insertFieldLastRow(name, data); - break; - } - case "class java.util.Date": { - Object os = variable.get(o); - if (os != null) { - Date data = (Date) os; - queryBuilder.insertFieldLastRow(name, data); - } - break; - } - case "boolean": { - boolean data = variable.getBoolean(o); - if(SbxDataValidator.saveDefaultValue(annotation) || data) - queryBuilder.insertFieldLastRow(name, data); - break; - } - default: { - Object os = variable.get(o); - if (os != null) { - queryBuilder.insertFieldLastRow(name, getKeyFromAnnotation(os)); - } - break; - } - - - } - - variable.setAccessible(isAccessible); - } catch (IllegalArgumentException | IllegalAccessException e) { - throw new SbxAuthException(e); - } - - } - - - } - } - - return sbxUrlComposer - .addHeader(UrlHelper.HEADER_KEY_APP_KEY, appKey) - // .addHeader(UrlHelper.HEADER_KEY_ENCODING, UrlHelper.HEADER_GZIP) - .addHeader(UrlHelper.HEADER_KEY_CONTENT_TYPE, UrlHelper.HEADER_JSON) - .addHeader(UrlHelper.HEADER_KEY_AUTORIZATION, UrlHelper.HEADER_BEARER+token) - .addBody(queryBuilder.compile()); - } - - public static SbxUrlComposer getUrlInsertOrUpdateRow(Object o)throws Exception { - - int domain = SbxAuth.getDefaultSbxAuth().getDomain(); - String appKey = SbxAuth.getDefaultSbxAuth().getAppKey(); - String token = SbxAuth.getDefaultSbxAuth().getToken(); - String key=null; - Class myClass = o.getClass(); - if(!SbxDataValidator.hasKeyAnnotation(myClass)){ - throw new SbxModelException("SbxKey is required"); - } - Annotation annotationClass = myClass.getAnnotation(SbxModelName.class); - String modelName=""; - if(annotationClass instanceof SbxModelName){ - SbxModelName myAnnotation = (SbxModelName) annotationClass; - modelName=myAnnotation.value(); - }else{ - throw new SbxModelException("SbxModelName is required"); - } - - key=getKeyFromAnnotation(o); - SbxUrlComposer sbxUrlComposer = new SbxUrlComposer( - key==null||key.equals("")? UrlHelper.URL_INSERT:UrlHelper.URL_UPDATE - , UrlHelper.POST - ); - - SbxQueryBuilder queryBuilder = new SbxQueryBuilder(domain, modelName, SbxQueryBuilder.TYPE.INSERT); - - queryBuilder.insertNewEmptyRow(); - if(!(key==null||key.equals(""))) - queryBuilder.insertFieldLastRow("_KEY",key); - final Field[] variables = myClass.getDeclaredFields(); - - for (final Field variable : variables) { - - final Annotation annotation = variable.getAnnotation(SbxParamField.class); - - if (annotation != null && annotation instanceof SbxParamField) { - try { - boolean isAccessible=variable.isAccessible(); - variable.setAccessible(true); - String name= SbxDataValidator.getAnnotationName(variable,annotation); - String variabletype=variable.getGenericType().toString(); - switch (variabletype){ - case "class java.lang.String":{ - Object os=variable.get(o); - if(os!=null) { - String data = (String) os; - queryBuilder.insertFieldLastRow(name, data); - } - break; - } - case "int":{ - int data=variable.getInt(o); - if(SbxDataValidator.saveDefaultValue(annotation) || data!=0) - queryBuilder.insertFieldLastRow(name,data); - break; - } - case "class java.lang.Integer": { - int data = variable.getInt(o); - if(SbxDataValidator.saveDefaultValue(annotation) || data!=0) - queryBuilder.insertFieldLastRow(name, data); - break; - } - case "long": { - long data = variable.getLong(o); - if(SbxDataValidator.saveDefaultValue(annotation) || data!=0) - queryBuilder.insertFieldLastRow(name, data); - break; - } - case "class java.lang.Long": { - long data = variable.getLong(o); - if(SbxDataValidator.saveDefaultValue(annotation) || data!=0) - queryBuilder.insertFieldLastRow(name, data); - break; - } - case "double": { - double data = variable.getDouble(o); - if(SbxDataValidator.saveDefaultValue(annotation) || data!=0) - queryBuilder.insertFieldLastRow(name, data); - break; - } - case "class java.lang.Double": { - double data = variable.getDouble(o); - if(SbxDataValidator.saveDefaultValue(annotation) || data!=0) - queryBuilder.insertFieldLastRow(name, data); - break; - } - case "float": { - float data = variable.getFloat(o); - if(SbxDataValidator.saveDefaultValue(annotation) || data!=0) - queryBuilder.insertFieldLastRow(name, data); - break; - } - case "class java.lang.Float": { - float data = variable.getFloat(o); - if(SbxDataValidator.saveDefaultValue(annotation) || data!=0) - queryBuilder.insertFieldLastRow(name, data); - break; - } - case "class java.util.Date":{ - Object os=variable.get(o); - if(os!=null) { - Date data = (Date) os; - queryBuilder.insertFieldLastRow(name, data); - } - break; - } - case "boolean":{ - boolean data=variable.getBoolean(o); - if(SbxDataValidator.saveDefaultValue(annotation) || data) - queryBuilder.insertFieldLastRow(name,data); - break; - } - default:{ - Object os=variable.get(o); - if(os!=null) { - queryBuilder.insertFieldLastRow(name, getKeyFromAnnotation(os)); - } - break; - } - - - } - - variable.setAccessible(isAccessible); - } catch (IllegalArgumentException | IllegalAccessException e) { - throw new SbxAuthException(e); - } - - } - - - } - - return sbxUrlComposer - .addHeader(UrlHelper.HEADER_KEY_APP_KEY, appKey) - // .addHeader(UrlHelper.HEADER_KEY_ENCODING, UrlHelper.HEADER_GZIP) - .addHeader(UrlHelper.HEADER_KEY_CONTENT_TYPE, UrlHelper.HEADER_JSON) - .addHeader(UrlHelper.HEADER_KEY_AUTORIZATION, UrlHelper.HEADER_BEARER+token) - .addBody(queryBuilder.compile()); - } - - - public static String getKeyFromAnnotation(Object o) throws Exception{ - Class myClass = o.getClass(); - final Field[] variables = myClass.getDeclaredFields(); - - for (final Field variable : variables) { - - final Annotation annotation = variable.getAnnotation(SbxKey.class); - - if (annotation != null && annotation instanceof SbxKey) { - try { - boolean isAccessible=variable.isAccessible(); - variable.setAccessible(true); - Object object=variable.get(o); - if(object==null){ - return null; - } - String s= (String)object; - variable.setAccessible(isAccessible); - return s; - } catch (IllegalArgumentException | IllegalAccessException e) { - throw new SbxAuthException(e); - } - } - } - throw new SbxModelException("no Key present on object"); - } - - - - public static SbxQueryBuilder prepareQuery(Class myClass) throws Exception{ - int domain = SbxAuth.getDefaultSbxAuth().getDomain(); - Annotation annotationClass = myClass.getAnnotation(SbxModelName.class); - String modelName=""; - if(annotationClass instanceof SbxModelName){ - SbxModelName myAnnotation = (SbxModelName) annotationClass; - modelName=myAnnotation.value(); - }else{ - throw new SbxModelException("SbxModelName is required"); - } - return new SbxQueryBuilder(domain,modelName); - - } - - public static SbxQueryBuilder prepareQuery(Class myClass, int page, int limit) throws Exception{ - int domain = SbxAuth.getDefaultSbxAuth().getDomain(); - Annotation annotationClass = myClass.getAnnotation(SbxModelName.class); - String modelName=""; - if(annotationClass instanceof SbxModelName){ - SbxModelName myAnnotation = (SbxModelName) annotationClass; - modelName=myAnnotation.value(); - }else{ - throw new SbxModelException("SbxModelName is required"); - } - return new SbxQueryBuilder(domain,modelName,page,limit); - - } - - public static SbxQueryBuilder prepareQueryToDelete(Class myClass) throws Exception{ - int domain = SbxAuth.getDefaultSbxAuth().getDomain(); - Annotation annotationClass = myClass.getAnnotation(SbxModelName.class); - String modelName=""; - if(annotationClass instanceof SbxModelName){ - SbxModelName myAnnotation = (SbxModelName) annotationClass; - modelName=myAnnotation.value(); - }else{ - throw new SbxModelException("SbxModelName is required"); - } - return new SbxQueryBuilder(domain,modelName, SbxQueryBuilder.TYPE.DELETE); - - } - - public static SbxUrlComposer getUrlDelete(SbxQueryBuilder sbxQueryBuilder)throws Exception{ - if(sbxQueryBuilder.getKeysD()==null) - throw new SbxModelException("SbxQueryBuilder is not DELETE Type"); - String appKey = SbxAuth.getDefaultSbxAuth().getAppKey(); - String token = SbxAuth.getDefaultSbxAuth().getToken(); - SbxUrlComposer sbxUrlComposer = new SbxUrlComposer( - UrlHelper.URL_DELETE - , UrlHelper.POST - ); - return sbxUrlComposer - .addHeader(UrlHelper.HEADER_KEY_APP_KEY, appKey) -// .addHeader(UrlHelper.HEADER_KEY_ENCODING, UrlHelper.HEADER_GZIP) -// .addHeader(UrlHelper.HEADER_KEY_CONTENT_TYPE, UrlHelper.HEADER_JSON) - .addHeader(UrlHelper.HEADER_KEY_AUTORIZATION, UrlHelper.HEADER_BEARER+token) - .addBody(sbxQueryBuilder.compile()); - } - - public static SbxUrlComposer getUrlQuery(SbxQueryBuilder sbxQueryBuilder) throws Exception{ - String appKey = SbxAuth.getDefaultSbxAuth().getAppKey(); - String token = SbxAuth.getDefaultSbxAuth().getToken(); - SbxUrlComposer sbxUrlComposer = new SbxUrlComposer( - UrlHelper.URL_FIND - , UrlHelper.POST - ); - return sbxUrlComposer - .addHeader(UrlHelper.HEADER_KEY_APP_KEY, appKey) -// .addHeader(UrlHelper.HEADER_KEY_ENCODING, UrlHelper.HEADER_GZIP) -// .addHeader(UrlHelper.HEADER_KEY_CONTENT_TYPE, UrlHelper.HEADER_JSON) - .addHeader(UrlHelper.HEADER_KEY_AUTORIZATION, UrlHelper.HEADER_BEARER+token) - .addBody(sbxQueryBuilder.compile()); - } - - public static SbxUrlComposer getUrlQueryKeys(SbxQueryBuilder sbxQueryBuilder, String [] keys) throws Exception{ - String appKey = SbxAuth.getDefaultSbxAuth().getAppKey(); - String token = SbxAuth.getDefaultSbxAuth().getToken(); - SbxUrlComposer sbxUrlComposer = new SbxUrlComposer( - UrlHelper.URL_FIND - , UrlHelper.POST - ); - return sbxUrlComposer - .addHeader(UrlHelper.HEADER_KEY_APP_KEY, appKey) -// .addHeader(UrlHelper.HEADER_KEY_ENCODING, UrlHelper.HEADER_GZIP) -// .addHeader(UrlHelper.HEADER_KEY_CONTENT_TYPE, UrlHelper.HEADER_JSON) - .addHeader(UrlHelper.HEADER_KEY_AUTORIZATION, UrlHelper.HEADER_BEARER+token) - .addBody(sbxQueryBuilder.compileWithKeys(keys)); - } - - -} \ No newline at end of file diff --git a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/query/SbxQueryBuilder.java b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/query/SbxQueryBuilder.java deleted file mode 100644 index 6b88515..0000000 --- a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/query/SbxQueryBuilder.java +++ /dev/null @@ -1,611 +0,0 @@ -package com.sbxcloud.android.sbxcloudsdk.query; - -import com.sbxcloud.android.sbxcloudsdk.net.model.SbxQuery; -import com.sbxcloud.android.sbxcloudsdk.util.SbxDataValidator; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -/** - * Created by lgguzman on 18/02/17. - */ - -public class SbxQueryBuilder { - /** - * @author https://archivo.digital - * - * Example - * - * SELECT * from mi_modelo WHERE (profesion = 'cantante' OR - * profesion = 'guitarrista') AND (ganancias > 100000 AND ventas < 10) - * - * SbxQueryBuilder queryBuilder = new SbxQueryBuilder(ApiConstants.DOMAIN,"mi_modelo"); - * queryBuilder.whereIsEqual("profesion","cantante") - * .addOR() - * .whereIsEqual("profesion","guitarrista") - * .newGroup(ADQueryBuilder.ANDOR.AND) - * .whereGreaterThan("ganancias",100000) - * .addAND() // by default is the last operator used or AND it is the first time - * .whereLessThan("ventas",10); - * JSONObject jsonObject=queryBuilder.compile(); - * - * INSERT INTO mi_modelo (profesion,ganancias,ventas) VALUES ('cantante',30000,9) - * - * SbxQueryBuilder queryBuilder = new SbxQueryBuilder(ApiConstants.DOMAIN,"mi_modelo", SbxQueryBuilder.TYPE.INSERT); - * queryBuilder.insertNewEmptyRow() - * .insertFieldLastRow("profesion","cantante") - * .insertFieldLastRow("ganancias",3000) - * .insertFieldLastRow("ventas",9); - * JSONObject jsonObject=queryBuilder.compile(); - * - * - */ - - - private JSONArray fetch; - private JSONObject obj; - private JSONObject referenceJoin; - private JSONArray required; - private JSONArray where; - private JSONArray keysD; - private JSONObject currentGroup; - private JSONArray row; - public enum TYPE { - INSERT, SELECT, DELETE - } - - public enum ANDOR { - AND, OR - } - - private ANDOR lastANDOR=null; - public enum OP { - EQ("="), - LIKE("LIKE"), - IN("IN"), - NOTIN("NOT IN"), - LT("<"), - GT(">"), - LET("<="), - GET(">="), - NOT("<>"), - IS("IS"), - ISNOT("IS NOT"); - - private String val; - - OP(String s) { - this.val = s; - } - - public String getValue() { - return val; - } - } - - public JSONArray getKeysD() { - return keysD; - } - - public SbxQueryBuilder(int domain, String rowModel) throws JSONException { - init(domain, rowModel); - } - - private void init(int domain, String rowModel)throws JSONException { - obj = new JSONObject(); - obj.put("domain", domain); - obj.put("row_model", rowModel); - required = new JSONArray(); - fetch = new JSONArray(); - where = new JSONArray(); - currentGroup = new JSONObject(); - currentGroup.put("ANDOR", ANDOR.AND); - currentGroup.put("GROUP", new JSONArray()); - } - - - - public SbxQueryBuilder(int domain, String rowModel, TYPE type ) throws JSONException { - switch (type){ - case SELECT: - init(domain,rowModel); - break; - case INSERT: - obj = new JSONObject(); - obj.put("domain", domain); - obj.put("row_model", rowModel); - row = new JSONArray(); - break; - case DELETE: - obj = new JSONObject(); - obj.put("domain", domain); - obj.put("row_model", rowModel); - keysD = new JSONArray(); - break; - } - - } - - public SbxQueryBuilder addGeoSort(double lat, double lon, String latName, String lonName){ - - try { - JSONObject jsonObject = new JSONObject(); - jsonObject.put("lat",lat); - jsonObject.put("lon",lon); - jsonObject.put("latProperty",latName); - jsonObject.put("lonProperty",lonName); - obj.put("geosort",jsonObject); - }catch (Exception ex){} - return this; - } - - public SbxQueryBuilder insert(JSONObject jsonObject)throws Exception{ - if(row!=null){ - row.put(jsonObject); - }else{ - new Exception("it is not insert type"); - } - return this; - } - - public SbxQueryBuilder insertNewEmptyRow()throws Exception{ - if(row!=null){ - row.put(new JSONObject()); - }else{ - new Exception("it is not insert type"); - } - return this; - } - - public SbxQueryBuilder addDeleteKey(String key){ - if(keysD!=null){ - keysD.put(key); - } - return this; - } - - - public SbxQueryBuilder insertFieldAtRow(String field, Object data, int position)throws Exception{ - if(row!=null){ - if(position < row.length()) - row.getJSONObject(position).put(field, SbxDataValidator.validate( data)); - else - new Exception("index Of Bound"); - }else{ - new Exception("it is not insert type"); - } - return this; - } - - public SbxQueryBuilder insertFieldFirstRow(String field, Object data)throws Exception{ - int position=0; - if(row!=null){ - if(position < row.length()) - row.getJSONObject(position).put(field, SbxDataValidator.validate( data)); - else - new Exception("index Of bound"); - }else{ - new Exception("it is not insert type"); - } - return this; - } - - public SbxQueryBuilder insertFieldLastRow(String field, Object data)throws Exception{ - - if(row!=null){ - if( row.length() > 0) - row.getJSONObject(row.length()-1).put(field, SbxDataValidator.validate( data)); - else - new Exception("is Empty"); - }else{ - new Exception("it is not insert type"); - } - return this; - } - - public void setPage(int page) throws JSONException{ - obj.put("page", page); - } - - public int getPage(){ - return obj.optInt("page",1); - } - - public SbxQueryBuilder(int domain, String rowModel, int page, int size) throws JSONException { - init(domain,rowModel); - obj.put("page", page); - obj.put("size", size); - } - - private SbxQueryBuilder newGroup(ANDOR andor) throws JSONException { - - if(row==null) { - lastANDOR=null; - where.put(currentGroup); - currentGroup = new JSONObject(); - currentGroup.put("ANDOR", andor); - currentGroup.put("GROUP", new JSONArray()); - } - return this; - } - - public SbxQueryBuilder newGroupWithAnd() throws JSONException { - return newGroup(ANDOR.AND); - } - - public SbxQueryBuilder newGroupWithOr() throws JSONException { - return newGroup(ANDOR.OR); - } - - private SbxQueryBuilder addField(OP op, ANDOR andor, String field, Object value) throws JSONException { - if(row==null) { - JSONObject tmp = new JSONObject(); - if(currentGroup.getJSONArray("GROUP").length() > 0) - tmp.put("ANDOR", andor.toString()); - else - tmp.put("ANDOR", ANDOR.AND.toString()); - tmp.put("FIELD", field); - tmp.put("OP", op.getValue()); - tmp.put("VAL", value); - currentGroup.getJSONArray("GROUP").put(tmp); - } - return this; - } - - private SbxQueryBuilder setReferenceJoin(OP op, String filterField,String referenceField, String model ,Object value) throws JSONException { - referenceJoin = new JSONObject(); - referenceJoin.put("row_model",model); - JSONObject filter = new JSONObject(); - filter.put("OP", op.getValue()); - filter.put("VAL",value); - filter.put("FIELD",filterField); - referenceJoin.put("reference_field",referenceField); - referenceJoin.put("filter", filter); - return this; - } - - // PRIVATE QUERY METHODS - - private SbxQueryBuilder addAND(){ - lastANDOR = ANDOR.AND; - return this; - } - - private SbxQueryBuilder addOR(){ - if (lastANDOR != null) - lastANDOR = ANDOR.OR; - else - lastANDOR = ANDOR.AND; - return this; - } - - private SbxQueryBuilder whereIsEqual(String field, Object value) throws JSONException{ - return addField(OP.EQ,lastANDOR,field,value); - } - - private SbxQueryBuilder whereIsNotNull(String field) throws JSONException{ - return addField(OP.ISNOT,lastANDOR,field,null); - } - - private SbxQueryBuilder whereIsNull(String field) throws JSONException{ - return addField(OP.IS,lastANDOR,field,null); - } - - private SbxQueryBuilder whereIn(String field, Object value) throws JSONException{ - return addField(OP.IN,lastANDOR,field,value); - } - - private SbxQueryBuilder whereNotIn(String field, Object value) throws JSONException{ - return addField(OP.NOTIN,lastANDOR,field,value); - } - - private SbxQueryBuilder whereGreaterThan(String field, Object value) throws JSONException{ - return addField(OP.GT,lastANDOR,field,value); - } - - private SbxQueryBuilder whereLessThan(String field, Object value) throws JSONException{ - return addField(OP.LT,lastANDOR,field,value); - } - - private SbxQueryBuilder whereGreaterOrEqualThan(String field, Object value) throws JSONException{ - return addField(OP.GET,lastANDOR,field,value); - } - - private SbxQueryBuilder whereLessOrEqualThan(String field, Object value) throws JSONException{ - return addField(OP.LET,lastANDOR,field,value); - } - - private SbxQueryBuilder whereIsNotEqual(String field, Object value) throws JSONException{ - return addField(OP.NOT,lastANDOR,field,value); - } - - private SbxQueryBuilder whereLike(String field, Object value) throws JSONException{ - return addField(OP.LIKE,lastANDOR,field,value); - } - - - public class ReferenceJoin { - - private SbxQueryBuilder find; - private String field; - private String referenceField; - - ReferenceJoin(SbxQueryBuilder find, String field, String referenceField, String type) throws Exception { - this.find = find; - this.field = field; - this.referenceField = referenceField; - if (type.equals("AND")) { - this.find.andWhereIn(this.field, "@reference_join@"); - } else { - this.find.orWhereIn(this.field, "@reference_join@"); - } - } - - - public FilterJoin in(String referenceModel) { - return new FilterJoin(this.find, this.field, this.referenceField, referenceModel); - } - } - - - public class FilterJoin { - - private SbxQueryBuilder find; - private String field; - private String referenceField; - private String referenceModel; - - - FilterJoin(SbxQueryBuilder find,String field,String referenceField,String referenceModel) { - this.find = find; - this.field = field; - this.referenceField = referenceField; - this.referenceModel = referenceModel; - } - - - public SbxQueryBuilder filterWhereIsEqual(String field, Object value) throws Exception{ - this.find.setReferenceJoin(OP.EQ, field, this.referenceField, this.referenceModel, value); - return this.find; - } - - public SbxQueryBuilder filterWhereIsNotNull(String field) throws Exception{ - this.find.setReferenceJoin(OP.ISNOT, field, this.referenceField, this.referenceModel, null); - return this.find; - } - - public SbxQueryBuilder filterWhereIsNull(String field) throws Exception{ - this.find.setReferenceJoin(OP.IS, field, this.referenceField, this.referenceModel, null); - return this.find; - } - - public SbxQueryBuilder filterWhereGreaterThan(String field, Object value) throws Exception{ - this.find.setReferenceJoin(OP.GT, field, this.referenceField, this.referenceModel, value); - return this.find; - } - - public SbxQueryBuilder filterWhereLessThan(String field, Object value) throws Exception{ - this.find.setReferenceJoin(OP.LT, field, this.referenceField, this.referenceModel, value); - return this.find; - } - - public SbxQueryBuilder filterWhereGreaterOrEqualThan(String field, Object value) throws Exception{ - this.find.setReferenceJoin(OP.GET, field, this.referenceField, this.referenceModel, value); - return this.find; - } - - public SbxQueryBuilder filterWhereLessOrEqualThan(String field, Object value) throws Exception{ - this.find.setReferenceJoin(OP.LET, field, this.referenceField, this.referenceModel, value); - return this.find; - } - - public SbxQueryBuilder filterWhereIsNotEqual(String field, Object value) throws Exception{ - this.find.setReferenceJoin(OP.ISNOT, field, this.referenceField, this.referenceModel, value); - return this.find; - } - - public SbxQueryBuilder filterWhereLike(String field, Object value) throws Exception{ - this.find.setReferenceJoin(OP.LIKE, field, this.referenceField, this.referenceModel, value); - return this.find; - } - - public SbxQueryBuilder filterWhereIn(String field, Object value) throws Exception{ - this.find.setReferenceJoin(OP.IN, field, this.referenceField, this.referenceModel, value); - return this.find; - } - - public SbxQueryBuilder filterWhereNotIn(String field, Object value) throws Exception{ - this.find.setReferenceJoin(OP.NOTIN, field, this.referenceField, this.referenceModel, value); - return this.find; - } - - } - - - // PUBLIC QUERY METHODS - - public SbxQueryBuilder andWhereIsEqual(String field, Object value) throws JSONException{ - addAND(); - return whereIsEqual(field,value); - } - - public SbxQueryBuilder andWhereIsNotNull(String field) throws JSONException{ - addAND(); - return whereIsNotNull(field ); - } - - public SbxQueryBuilder andWhereGreaterThan(String field, Object value) throws JSONException{ - addAND(); - return whereGreaterThan(field,value); - } - - public SbxQueryBuilder andWhereLessThan(String field, Object value) throws JSONException{ - addAND(); - return whereLessThan(field,value); - } - - public SbxQueryBuilder andWhereGreaterOrEqualThan(String field, Object value) throws JSONException{ - addAND(); - return whereGreaterOrEqualThan(field,value); - } - - public SbxQueryBuilder andWhereLessOrEqualThan(String field, Object value) throws JSONException{ - addAND(); - return whereLessOrEqualThan(field,value); - } - - public SbxQueryBuilder andWhereIsNotEqual(String field, Object value) throws JSONException{ - addAND(); - return whereIsNotEqual(field,value); - } - - public SbxQueryBuilder andWhereLike(String field, Object value) throws JSONException{ - addAND(); - return whereLike(field,value); - } - - public SbxQueryBuilder andWhereIn(String field, Object value) throws JSONException{ - addAND(); - return whereIn(field,value); - } - - - public SbxQueryBuilder orWhereIsEqual(String field, Object value) throws JSONException{ - addOR(); - return whereIsEqual(field,value); - } - - public SbxQueryBuilder orWhereIsNotNull(String field) throws JSONException{ - addOR(); - return whereIsNotNull(field ); - } - - public SbxQueryBuilder orWhereGreaterThan(String field, Object value) throws JSONException{ - addOR(); - return whereGreaterThan(field,value); - } - - public SbxQueryBuilder orWhereLessThan(String field, Object value) throws JSONException{ - addOR(); - return whereLessThan(field,value); - } - - public SbxQueryBuilder orWhereGreaterOrEqualThan(String field, Object value) throws JSONException{ - addOR(); - return whereGreaterOrEqualThan(field,value); - } - - public SbxQueryBuilder orWhereLessOrEqualThan(String field, Object value) throws JSONException{ - addOR(); - return whereLessOrEqualThan(field,value); - } - - public SbxQueryBuilder orWhereIsNotEqual(String field, Object value) throws JSONException{ - addOR(); - return whereIsNotEqual(field,value); - } - - public SbxQueryBuilder orWhereLike(String field, Object value) throws JSONException{ - addOR(); - return whereLike(field,value); - } - - public SbxQueryBuilder orWhereIn(String field, Object value) throws JSONException{ - addOR(); - return whereIn(field,value); - } - - public ReferenceJoin orWhereReferenceJoinBetween(String field, String referenceField) throws Exception { - return new ReferenceJoin(this, field, referenceField, "OR"); - } - - public ReferenceJoin andWhereReferenceJoinBetween(String field, String referenceField) throws Exception { - return new ReferenceJoin(this, field, referenceField, "AND"); - } - - public SbxQueryBuilder addRequire(String model) { - if(row==null) { - required.put(model); - } - return this; - } - - public SbxQueryBuilder fetch(String[] models) { - if(row==null) { - for (String model : models) { - fetch.put(model); - - } - } - return this; - } - - - public JSONObject compileWithKeys(String[] keys) throws JSONException { - if(row==null) { - if (where.length() > 0) { - throw new IllegalStateException(""); - } - - for (String key : keys) { - where.put(key); - } - - JSONObject tmp = new JSONObject(); - tmp.put("keys", where); - - if (required.length() > 0) { - obj.put("require", required); - } - - if (fetch.length() > 0) { - obj.put("fetch", fetch); - } - - obj.put("where", tmp); - } - return obj; - } - - public JSONObject compile() throws Exception { - - if(row==null) { - if (currentGroup!=null && currentGroup.getJSONArray("GROUP").length() > 0) { - where.put(currentGroup); - } - - if (where!=null && where.length() > 0) { - obj.put("where", where); - } - if (referenceJoin!=null ) { - obj.put("reference_join", referenceJoin); - } - - if (required!=null && required.length() > 0) { - obj.put("require", required); - } - - if (fetch!=null && fetch.length() > 0) { - obj.put("fetch", fetch); - } - - if (keysD!=null){ - if(keysD.length()>0){ - JSONObject jsonObject= new JSONObject(); - jsonObject.put("keys",keysD); - obj.put("where",jsonObject); - }else{ - throw new Exception("A Key is required"); - } - } - }else{ - if (row.length() > 0) { - obj.put("rows", row); - } - } - return obj; - } - - -} diff --git a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/query/annotation/SbxCreatedAt.java b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/query/annotation/SbxCreatedAt.java deleted file mode 100644 index d98689e..0000000 --- a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/query/annotation/SbxCreatedAt.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.sbxcloud.android.sbxcloudsdk.query.annotation; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Created by lgguzman on 20/02/17. - */ - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface SbxCreatedAt { -} diff --git a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/query/annotation/SbxKey.java b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/query/annotation/SbxKey.java deleted file mode 100644 index 368bb3f..0000000 --- a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/query/annotation/SbxKey.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.sbxcloud.android.sbxcloudsdk.query.annotation; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Created by lgguzman on 20/02/17. - */ - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface SbxKey { -} diff --git a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/query/annotation/SbxModelName.java b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/query/annotation/SbxModelName.java deleted file mode 100644 index 24e7cd6..0000000 --- a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/query/annotation/SbxModelName.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.sbxcloud.android.sbxcloudsdk.query.annotation; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Created by lgguzman on 20/02/17. - */ - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -public @interface SbxModelName { - public String value(); -} \ No newline at end of file diff --git a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/query/annotation/SbxParamField.java b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/query/annotation/SbxParamField.java deleted file mode 100644 index 7c7a7bd..0000000 --- a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/query/annotation/SbxParamField.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.sbxcloud.android.sbxcloudsdk.query.annotation; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Created by lgguzman on 19/02/17. - */ - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface SbxParamField { - - String name() default ""; - boolean saveDefaultValue() default true; - -} diff --git a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/query/annotation/SbxUpdatedAt.java b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/query/annotation/SbxUpdatedAt.java deleted file mode 100644 index bcb976f..0000000 --- a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/query/annotation/SbxUpdatedAt.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.sbxcloud.android.sbxcloudsdk.query.annotation; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Created by lgguzman on 20/02/17. - */ - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface SbxUpdatedAt { -} diff --git a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/util/SbxDataValidator.java b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/util/SbxDataValidator.java deleted file mode 100644 index 7c2df8b..0000000 --- a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/util/SbxDataValidator.java +++ /dev/null @@ -1,104 +0,0 @@ -package com.sbxcloud.android.sbxcloudsdk.util; - -import com.sbxcloud.android.sbxcloudsdk.exception.SbxAuthException; -import com.sbxcloud.android.sbxcloudsdk.exception.SbxModelException; -import com.sbxcloud.android.sbxcloudsdk.query.annotation.SbxKey; -import com.sbxcloud.android.sbxcloudsdk.query.annotation.SbxModelName; -import com.sbxcloud.android.sbxcloudsdk.query.annotation.SbxParamField; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Field; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Locale; -import java.util.TimeZone; - -/** - * Created by lgguzman on 20/02/17. - */ - -public class SbxDataValidator { - public static Object validate(Object o){ - - if(o instanceof Date) { - DateFormat jsonDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US); - jsonDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); - return jsonDateFormat.format(o); - } - - return o; - } - - public static Date getDate(String o) throws Exception{ - - DateFormat jsonDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US); - jsonDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); - return jsonDateFormat.parse(o); - - } - - public static String getAnnotationName(Field variable, Annotation annotation ) throws Exception{ - String name=((SbxParamField)annotation).name(); - if(name.equals("")){ - name=variable.getName(); - - } - return name; - - } - - public static Boolean saveDefaultValue( Annotation annotation ) throws Exception{ - boolean data=((SbxParamField)annotation).saveDefaultValue(); - return data; - - } - - public static boolean hasKeyAnnotation(Class myClass){ - final Field[] variables = myClass.getDeclaredFields(); - - for (final Field variable : variables) { - - final Annotation annotation = variable.getAnnotation(SbxKey.class); - if (annotation != null && annotation instanceof SbxKey) { - return true; - } - } - return false; - } - - public static void setKeyFromAnnotation(Object o, String key) throws Exception{ - Class myClass = o.getClass(); - final Field[] variables = myClass.getDeclaredFields(); - - for (final Field variable : variables) { - - final Annotation annotation = variable.getAnnotation(SbxKey.class); - - if (annotation != null && annotation instanceof SbxKey) { - try { - boolean isAccessible=variable.isAccessible(); - variable.setAccessible(true); - variable.set(o,key); - variable.setAccessible(isAccessible); - return; - } catch (IllegalArgumentException | IllegalAccessException e) { - throw new SbxAuthException(e); - } - } - } - throw new SbxModelException("no Key present on object"); - } - - - public static String getAnnotationModelNameFromVariable(Field variable) throws Exception{ - - Annotation annotationClass = variable.getType().getAnnotation(SbxModelName.class); - String modelName=""; - if(annotationClass instanceof SbxModelName){ - SbxModelName myAnnotation = (SbxModelName) annotationClass; - modelName=myAnnotation.value(); - } - return modelName; - } -} diff --git a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/util/SbxFileHelper.java b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/util/SbxFileHelper.java deleted file mode 100644 index 82d6f24..0000000 --- a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/util/SbxFileHelper.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.sbxcloud.android.sbxcloudsdk.util; - -import com.sbxcloud.android.sbxcloudsdk.auth.SbxAuth; -import com.sbxcloud.android.sbxcloudsdk.query.SbxQueryBuilder; - -import java.io.File; - -/** - * Created by lgguzman on 25/03/17. - */ - -public class SbxFileHelper { - - public static SbxUrlComposer getUrlUploadFile(File file, String name, String folderKey) throws Exception{ - String appKey = SbxAuth.getDefaultSbxAuth().getAppKey(); - String token = SbxAuth.getDefaultSbxAuth().getToken(); - SbxUrlComposer sbxUrlComposer = new SbxUrlComposer( - UrlHelper.URL_UPLOAD_FILE - , UrlHelper.POST - ); - return sbxUrlComposer - .addHeader(UrlHelper.HEADER_KEY_APP_KEY, appKey) -// .addHeader(UrlHelper.HEADER_KEY_ENCODING, UrlHelper.HEADER_GZIP) -// .addHeader(UrlHelper.HEADER_KEY_CONTENT_TYPE, UrlHelper.HEADER_JSON) - .addHeader(UrlHelper.HEADER_KEY_AUTORIZATION, UrlHelper.HEADER_BEARER+token) - .addMultipartData(file,name,folderKey); - } -} diff --git a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/util/SbxJsonModeler.java b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/util/SbxJsonModeler.java deleted file mode 100644 index a7880ae..0000000 --- a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/util/SbxJsonModeler.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.sbxcloud.android.sbxcloudsdk.util; - -import org.json.JSONObject; - -/** - * Created by lgguzman on 24/03/17. - */ - -public interface SbxJsonModeler { - - void wrapFromJson(JSONObject jsonObject); - - JSONObject toJson(); - -} diff --git a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/util/SbxMagicComposer.java b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/util/SbxMagicComposer.java deleted file mode 100644 index 5323640..0000000 --- a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/util/SbxMagicComposer.java +++ /dev/null @@ -1,631 +0,0 @@ -package com.sbxcloud.android.sbxcloudsdk.util; - -import com.sbxcloud.android.sbxcloudsdk.exception.SbxAuthException; -import com.sbxcloud.android.sbxcloudsdk.exception.SbxModelException; -import com.sbxcloud.android.sbxcloudsdk.query.annotation.SbxCreatedAt; -import com.sbxcloud.android.sbxcloudsdk.query.annotation.SbxKey; -import com.sbxcloud.android.sbxcloudsdk.query.SbxModelHelper; -import com.sbxcloud.android.sbxcloudsdk.query.annotation.SbxParamField; - -import org.json.JSONObject; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; - -/** - * Created by lgguzman on 20/02/17. - */ - - -public class SbxMagicComposer { - - public static Object getSbxModel(JSONObject jsonObject, Class clazz, int level)throws Exception{ - level++; - //accept only two level - if (level==4) - return null; - if(!SbxDataValidator.hasKeyAnnotation(clazz)){ - throw new SbxModelException("SbxKey is required"); - } - Constructor ctor = clazz.getConstructor(); - Object o = ctor.newInstance(); - final Field[] variables = clazz.getDeclaredFields(); - - for (final Field variable : variables) { - boolean isAccessible=variable.isAccessible(); - variable.setAccessible(true); - final Annotation annotation = variable.getAnnotation(SbxParamField.class); - - if (annotation != null && annotation instanceof SbxParamField) { - try { - if(!jsonObject.isNull(SbxDataValidator.getAnnotationName(variable,annotation))) { - - String variabletype = variable.getGenericType().toString(); - switch (variabletype) { - case "class java.lang.String": { - variable.set(o, jsonObject.optString(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - case "class java.lang.Integer": { - variable.set(o, jsonObject.optInt(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - case "int": { - variable.set(o, jsonObject.optInt(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - case "long": { - variable.set(o, jsonObject.optLong(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - case "class java.lang.Long": { - variable.set(o, jsonObject.optLong(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - case "class java.lang.Double": { - variable.set(o, jsonObject.optDouble(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - case "double": { - variable.set(o, jsonObject.optDouble(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - case "class java.lang.Float": { - variable.set(o, (float)jsonObject.getDouble(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - case "float": { - variable.set(o, (float)jsonObject.optDouble(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - case "class java.util.Date": { - try { - variable.set(o, - SbxDataValidator.getDate( - jsonObject.optString(SbxDataValidator.getAnnotationName(variable, annotation)))); - } catch (Exception e) { - } - break; - } - case "boolean": { - variable.set(o, jsonObject.optBoolean(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - default: { - - Object obj = jsonObject.get(SbxDataValidator.getAnnotationName(variable, annotation)); - if (obj != null) { - if (obj instanceof String) { - Object reference = variable.getType().getConstructor().newInstance(); - final Field[] variables2 = variable.getType().getDeclaredFields(); - for (final Field variable2 : variables2) { - - final Annotation annotation2 = variable2.getAnnotation(SbxKey.class); - - if (annotation2 != null && annotation2 instanceof SbxKey) { - try { - boolean isAccessible2 = variable2.isAccessible(); - variable2.setAccessible(true); - variable2.set(reference, obj); - variable2.setAccessible(isAccessible2); - break; - } catch (IllegalArgumentException | IllegalAccessException e) { - throw new SbxAuthException(e); - } - } - } - variable.set(o, reference); - } else { - variable.set(o, - getSbxModel( - jsonObject.optJSONObject(SbxDataValidator.getAnnotationName(variable, annotation)) - , variable.getType(), level) - ); - } - } - break; - } - - - } - } - } catch (IllegalArgumentException | IllegalAccessException e) { - throw new SbxAuthException(e); - } - - } - final Annotation annotationK = variable.getAnnotation(SbxKey.class); - if (annotationK != null && annotationK instanceof SbxKey) { - try { - - variable.set(o,jsonObject.optString("_KEY")); - } catch (IllegalArgumentException | IllegalAccessException e) { - throw new SbxAuthException(e); - } - - } - final Annotation annotationDate = variable.getAnnotation(SbxCreatedAt.class); - if (annotationDate != null && annotationDate instanceof SbxCreatedAt) { - try { - - variable.set(o, - SbxDataValidator.getDate( - jsonObject.optJSONObject("_META").optString("created_time"))); - } catch (Exception e) { - // throw new SbxAuthException(e); - e.printStackTrace(); - } - - } - variable.setAccessible(isAccessible); - - } - - - return o; - } - - public static void getSbxModel(JSONObject jsonObject, Class clazz, Object o, int level)throws Exception{ - level++; - //accept only two level - if (level==4) - return ; - if(!SbxDataValidator.hasKeyAnnotation(clazz)){ - throw new SbxModelException("SbxKey is required"); - } - final Field[] variables = clazz.getDeclaredFields(); - - for (final Field variable : variables) { - boolean isAccessible=variable.isAccessible(); - variable.setAccessible(true); - final Annotation annotation = variable.getAnnotation(SbxParamField.class); - - if (annotation != null && annotation instanceof SbxParamField) { - try { - if(!jsonObject.isNull(SbxDataValidator.getAnnotationName(variable,annotation))) { - - String variabletype = variable.getGenericType().toString(); - switch (variabletype) { - case "class java.lang.String": { - variable.set(o, jsonObject.optString(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - case "class java.lang.Integer": { - variable.set(o, jsonObject.optInt(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - case "int": { - variable.set(o, jsonObject.optInt(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - case "long": { - variable.set(o, jsonObject.optLong(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - case "class java.lang.Long": { - variable.set(o, jsonObject.optLong(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - case "class java.lang.Double": { - variable.set(o, jsonObject.optDouble(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - case "double": { - variable.set(o, jsonObject.optDouble(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - case "class java.lang.Float": { - variable.set(o, (float)jsonObject.optDouble(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - case "float": { - variable.set(o, (float)jsonObject.optDouble(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - case "class java.util.Date": { - try { - variable.set(o, - SbxDataValidator.getDate( - jsonObject.optString(SbxDataValidator.getAnnotationName(variable, annotation)))); - } catch (Exception e) { - } - break; - } - case "boolean": { - variable.set(o, jsonObject.optBoolean(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - default: { - - Object obj = jsonObject.get(SbxDataValidator.getAnnotationName(variable, annotation)); - if (obj != null) { - if (obj instanceof String) { - Object reference = variable.getType().getConstructor().newInstance(); - final Field[] variables2 = variable.getType().getDeclaredFields(); - for (final Field variable2 : variables2) { - - final Annotation annotation2 = variable2.getAnnotation(SbxKey.class); - - if (annotation2 != null && annotation2 instanceof SbxKey) { - try { - boolean isAccessible2 = variable2.isAccessible(); - variable2.setAccessible(true); - variable2.set(reference, obj); - variable2.setAccessible(isAccessible2); - break; - } catch (IllegalArgumentException | IllegalAccessException e) { - throw new SbxAuthException(e); - } - } - } - variable.set(o, reference); - } else { - variable.set(o, - getSbxModel( - jsonObject.optJSONObject(SbxDataValidator.getAnnotationName(variable, annotation)) - , variable.getType(), level) - ); - } - } - break; - } - - - } - } - } catch (IllegalArgumentException | IllegalAccessException e) { - throw new SbxAuthException(e); - } - - } - final Annotation annotationK = variable.getAnnotation(SbxKey.class); - if (annotationK != null && annotationK instanceof SbxKey) { - try { - - variable.set(o,jsonObject.optString("_KEY")); - } catch (IllegalArgumentException | IllegalAccessException e) { - throw new SbxAuthException(e); - } - - } - final Annotation annotationDate = variable.getAnnotation(SbxCreatedAt.class); - if (annotationDate != null && annotationDate instanceof SbxCreatedAt) { - try { - - variable.set(o, - SbxDataValidator.getDate( - jsonObject.optJSONObject("_META").optString("created_time"))); - } catch ( Exception e) { - e.printStackTrace(); - // throw new SbxAuthException(e); - } - - } - variable.setAccessible(isAccessible); - - } - - - return ; - } - - public static void getSbxModel(JSONObject jsonObject, Class clazz, Object o, int level, JSONObject fetches)throws Exception{ - level++; - //accept only two level - if (level==4) - return ; - if(!SbxDataValidator.hasKeyAnnotation(clazz)){ - throw new SbxModelException("SbxKey is required"); - } - final Field[] variables = clazz.getDeclaredFields(); - - for (final Field variable : variables) { - boolean isAccessible=variable.isAccessible(); - variable.setAccessible(true); - final Annotation annotation = variable.getAnnotation(SbxParamField.class); - - if (annotation != null && annotation instanceof SbxParamField) { - try { - if(!jsonObject.isNull(SbxDataValidator.getAnnotationName(variable,annotation))) { - - String variabletype = variable.getGenericType().toString(); - switch (variabletype) { - case "class java.lang.String": { - variable.set(o, jsonObject.optString(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - case "class java.lang.Integer": { - variable.set(o, jsonObject.optInt(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - case "int": { - variable.set(o, jsonObject.optInt(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - case "long": { - variable.set(o, jsonObject.optLong(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - case "class java.lang.Long": { - variable.set(o, jsonObject.optLong(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - case "class java.lang.Double": { - variable.set(o, jsonObject.optDouble(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - case "double": { - variable.set(o, jsonObject.optDouble(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - case "class java.lang.Float": { - variable.set(o, (float)jsonObject.optDouble(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - case "float": { - variable.set(o, (float)jsonObject.optDouble(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - case "class java.util.Date": { - try { - variable.set(o, - SbxDataValidator.getDate( - jsonObject.optString(SbxDataValidator.getAnnotationName(variable, annotation)))); - } catch (Exception e) { - } - break; - } - case "boolean": { - variable.set(o, jsonObject.optBoolean(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - default: { - - Object obj = jsonObject.get(SbxDataValidator.getAnnotationName(variable, annotation)); - if (obj != null) { - if (obj instanceof String) { - - Object reference = null; - try { - reference = SbxMagicComposer.getSbxModel(fetches.getJSONObject(SbxDataValidator - .getAnnotationModelNameFromVariable(variable)).getJSONObject((String) obj), - variable.getType(), level,fetches); - } catch (Exception ex) { - } - - if (reference == null) { - reference = variable.getType().getConstructor().newInstance(); - final Field[] variables2 = variable.getType().getDeclaredFields(); - for (final Field variable2 : variables2) { - - final Annotation annotation2 = variable2.getAnnotation(SbxKey.class); - - if (annotation2 != null && annotation2 instanceof SbxKey) { - try { - boolean isAccessible2 = variable2.isAccessible(); - variable2.setAccessible(true); - variable2.set(reference, obj); - variable2.setAccessible(isAccessible2); - break; - } catch (IllegalArgumentException | IllegalAccessException e) { - throw new SbxAuthException(e); - } - } - } - - } - variable.set(o, reference); - } else { - variable.set(o, - getSbxModel( - jsonObject.optJSONObject(SbxDataValidator.getAnnotationName(variable, annotation)) - , variable.getType(), level) - ); - } - break; - } - } - - - } - } - } catch (IllegalArgumentException | IllegalAccessException e) { - throw new SbxAuthException(e); - } - - } - final Annotation annotationK = variable.getAnnotation(SbxKey.class); - if (annotationK != null && annotationK instanceof SbxKey) { - try { - - variable.set(o,jsonObject.optString("_KEY")); - } catch (IllegalArgumentException | IllegalAccessException e) { - throw new SbxAuthException(e); - } - - } - final Annotation annotationDate = variable.getAnnotation(SbxCreatedAt.class); - if (annotationDate != null && annotationDate instanceof SbxCreatedAt) { - try { - - variable.set(o, - SbxDataValidator.getDate( - jsonObject.optJSONObject("_META").optString("created_time"))); - } catch ( Exception e) { - // throw new SbxAuthException(e); - } - - } - variable.setAccessible(isAccessible); - - } - - - return ; - } - - public static Object getSbxModel(JSONObject jsonObject, Class clazz, int level, JSONObject fetches)throws Exception{ - level++; - //accept only two level - if (level==4) - return null; - if(!SbxDataValidator.hasKeyAnnotation(clazz)){ - throw new SbxModelException("SbxKey is required"); - } - Constructor ctor = clazz.getConstructor(); - Object o = ctor.newInstance(); - final Field[] variables = clazz.getDeclaredFields(); - - for (final Field variable : variables) { - boolean isAccessible=variable.isAccessible(); - variable.setAccessible(true); - final Annotation annotation = variable.getAnnotation(SbxParamField.class); - - if (annotation != null && annotation instanceof SbxParamField) { - try { - if(!jsonObject.isNull(SbxDataValidator.getAnnotationName(variable,annotation))) { - - String variabletype = variable.getGenericType().toString(); - switch (variabletype) { - case "class java.lang.String": { - variable.set(o, jsonObject.optString(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - case "class java.lang.Integer": { - variable.set(o, jsonObject.optInt(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - case "int": { - variable.set(o, jsonObject.optInt(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - case "long": { - variable.set(o, jsonObject.optLong(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - case "class java.lang.Long": { - variable.set(o, jsonObject.optLong(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - case "class java.lang.Double": { - variable.set(o, jsonObject.optDouble(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - case "double": { - variable.set(o, jsonObject.optDouble(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - case "class java.lang.Float": { - variable.set(o, (float)jsonObject.optDouble(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - case "float": { - variable.set(o, (float)jsonObject.optDouble(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - case "class java.util.Date": { - try { - variable.set(o, - SbxDataValidator.getDate( - jsonObject.optString(SbxDataValidator.getAnnotationName(variable, annotation)))); - } catch (Exception e) { - } - break; - } - case "boolean": { - variable.set(o, jsonObject.optBoolean(SbxDataValidator.getAnnotationName(variable, annotation))); - break; - } - default: { - - Object obj = jsonObject.get(SbxDataValidator.getAnnotationName(variable, annotation)); - if (obj != null) { - if (obj instanceof String) { - - Object reference = null; - try { - reference = SbxMagicComposer.getSbxModel(fetches.getJSONObject(SbxDataValidator - .getAnnotationModelNameFromVariable(variable)).getJSONObject((String) obj), - variable.getType(), level,fetches); - } catch (Exception ex) { - } - - if (reference == null) { - reference = variable.getType().getConstructor().newInstance(); - final Field[] variables2 = variable.getType().getDeclaredFields(); - for (final Field variable2 : variables2) { - - final Annotation annotation2 = variable2.getAnnotation(SbxKey.class); - - if (annotation2 != null && annotation2 instanceof SbxKey) { - try { - boolean isAccessible2 = variable2.isAccessible(); - variable2.setAccessible(true); - variable2.set(reference, obj); - variable2.setAccessible(isAccessible2); - break; - } catch (IllegalArgumentException | IllegalAccessException e) { - throw new SbxAuthException(e); - } - } - } - } - - - variable.set(o, reference); - - - } else { - variable.set(o, - getSbxModel( - jsonObject.optJSONObject(SbxDataValidator.getAnnotationName(variable, annotation)) - , variable.getType(), level) - ); - } - break; - } - } - - - } - } - } catch (IllegalArgumentException | IllegalAccessException e) { - throw new SbxAuthException(e); - } - - } - final Annotation annotationK = variable.getAnnotation(SbxKey.class); - if (annotationK != null && annotationK instanceof SbxKey) { - try { - - variable.set(o,jsonObject.optString("_KEY")); - } catch (IllegalArgumentException | IllegalAccessException e) { - throw new SbxAuthException(e); - } - - } - - final Annotation annotationDate = variable.getAnnotation(SbxCreatedAt.class); - if (annotationDate != null && annotationDate instanceof SbxCreatedAt) { - try { - - variable.set(o, - SbxDataValidator.getDate( - jsonObject.optJSONObject("_META").optString("created_time"))); - } catch ( Exception e) { - e.printStackTrace(); - //throw new SbxAuthException(e); - } - - } - - variable.setAccessible(isAccessible); - } - - - return o; - } -} - - diff --git a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/util/SbxUrlComposer.java b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/util/SbxUrlComposer.java deleted file mode 100644 index f5e677f..0000000 --- a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/util/SbxUrlComposer.java +++ /dev/null @@ -1,155 +0,0 @@ -package com.sbxcloud.android.sbxcloudsdk.util; - -import org.json.JSONObject; - -import java.io.File; -import java.net.URL; -import java.net.URLDecoder; -import java.net.URLEncoder; -import java.util.HashMap; -import java.util.List; -import java.util.StringTokenizer; - -/** - * Created by lgguzman on 18/02/17. - */ - -public class SbxUrlComposer { - private String url; - private String type; - private HashMap header; - private JSONObject body; - private File file; - private String fileName; - private String fileModel; - - /** - * - * @return if the request is a PUT - */ - public boolean isPOST(){ - return type.equals(UrlHelper.POST); - } - - /** - * - * @return if the request is a GET - */ - public boolean isGET(){ - return type.equals(UrlHelper.GET); - } - - /** - * - * @return if the request is a PUT - */ - public boolean isPUT(){ - return type.equals(UrlHelper.PUT); - } - - /** - * - * @return the type of request of this object, PUT GET or POST - */ - public String getType(){ - return type; - } - - public File getFile() { - return file; - } - - public String getFileName() { - return fileName; - } - - public String getFileModel() { - return fileModel; - } - - /** - * - * @param url - * @param type - */ - public SbxUrlComposer(String url, String type){ - this.url= UrlHelper.URL_BASE+ url; - this.type=type; - header= new HashMap<>(); - addHeader("User-Agent","AndroidALib"); - body= new JSONObject(); - } - - - - /** - * - * @param key - * @param value - */ - public SbxUrlComposer setUrlParam(String key, String value){ - - if(!this.url.contains("?")) - this.url=this.url+"?"+key+"="+URLEncoder.encode(value); - else - this.url=this.url+"&"+key+"="+URLEncoder.encode(value); - - return this; - } - - - public SbxUrlComposer addMultipartData(File file, String name, String key){ - - this.file=file; - this.fileName=name; - this.fileModel="{\"key\":\""+key+"\"}"; - return this; - } - - /** - * - * @param jsonObject - */ - public SbxUrlComposer addBody(JSONObject jsonObject){ - body = jsonObject; - return this; - } - - - /** - * - * @param key - * @param value - */ - public SbxUrlComposer addHeader(String key, String value){ - header.put(key,value); - return this; - } - - - public HashMap getHeader() { - return header; - } - - public String getHeaderString(){ - StringBuilder stringBuilder=new StringBuilder(""); - for (String key:header.keySet()){ - stringBuilder.append(key+": "+header.get(key)+":\n"); - } - return stringBuilder.toString(); - } - - public JSONObject getBody() { - return body; - } - - public String getUrl() { - return url; - } - - @Override - public String toString(){ - return "\n"+getType()+"\n"+getUrl()+"\nHEADER\n"+getHeaderString()+"\nBODY\n"+((getBody().toString()==null)?"":getBody().toString())+"\n" - +file==null?"":"\nMULTIPART\n"+"file:\n"+fileName+"\n"+"model:\n"+fileModel; - } -} diff --git a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/util/UrlHelper.java b/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/util/UrlHelper.java deleted file mode 100644 index fe17bd2..0000000 --- a/app/src/main/java/com/sbxcloud/android/sbxcloudsdk/util/UrlHelper.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.sbxcloud.android.sbxcloudsdk.util; - -/** - * Created by lgguzman on 18/02/17. - */ - -public interface UrlHelper { - - public static final String URL_BASE="https://sbxcloud.com/"; - public static final String URL_FIND="api/data/v1/row/find "; - public static final String URL_LOGIN="api/user/v1/login"; - public static final String URL_SIGN_UP="api/user/v1/register"; - public static final String URL_INSERT="api/data/v1/row"; - public static final String URL_UPDATE="api/data/v1/row/update"; - public static final String URL_UPLOAD_FILE="api/content/v1/upload"; - public static final String PASSWORD_REQUEST="api/user/v1/password/request/"; - public static final String PUSH = "api/push/v1/send"; - public static final String URL_DELETE="api/data/v1/row/delete"; - public static final String HEADER_KEY_APP_KEY="App-Key"; - public static final String HEADER_KEY_ENCODING="Accept-Encoding"; - public static final String HEADER_KEY_CONTENT_TYPE="Content-Type"; - public static final String HEADER_KEY_AUTORIZATION="Authorization"; - public static final String MESSAGE_CHANNEL = "api/message/v1/channel"; - public static final String MESSAGE_CHANNEL_MEMBER = "api/message/v1/channel/member"; - public static final String MESSAGE_LIST = "api/message/v1/list"; - public static final String MESSAGE_SEND = "api/message/v1/send"; - public static final String CLOUDSCRIPT_RUN = "api/cloudscript/v1/run"; - public static final String DOMAIN ="api/domain/v1/list/app"; - // public static final String HEADER_GZIP="gzip"; - public static final String HEADER_JSON="application/json"; - public static final String HEADER_BEARER="Bearer "; - public static final String VALIDATE="api/user/v1/validate "; - public static final String POST="POST"; - public static final String GET="GET"; - public static final String PUT="PUT"; - -} diff --git a/app/src/test/java/com/sbxcloud/android/sbxcloudsdk/Category.java b/app/src/test/java/com/sbxcloud/android/sbxcloudsdk/Category.java index 920895f..8e8958e 100644 --- a/app/src/test/java/com/sbxcloud/android/sbxcloudsdk/Category.java +++ b/app/src/test/java/com/sbxcloud/android/sbxcloudsdk/Category.java @@ -1,9 +1,9 @@ package com.sbxcloud.android.sbxcloudsdk; import com.sbxcloud.android.sbxcloudsdk.net.model.SbxModel; -import com.sbxcloud.android.sbxcloudsdk.query.annotation.SbxKey; -import com.sbxcloud.android.sbxcloudsdk.query.annotation.SbxModelName; -import com.sbxcloud.android.sbxcloudsdk.query.annotation.SbxParamField; +import com.sbxcloud.java.sbxcloudsdk.query.annotation.SbxKey; +import com.sbxcloud.java.sbxcloudsdk.query.annotation.SbxModelName; +import com.sbxcloud.java.sbxcloudsdk.query.annotation.SbxParamField; /** * Created by lgguzman on 20/02/17. diff --git a/app/src/test/java/com/sbxcloud/android/sbxcloudsdk/ExampleUnitTest.java b/app/src/test/java/com/sbxcloud/android/sbxcloudsdk/ExampleUnitTest.java index 6227af6..f25f475 100644 --- a/app/src/test/java/com/sbxcloud/android/sbxcloudsdk/ExampleUnitTest.java +++ b/app/src/test/java/com/sbxcloud/android/sbxcloudsdk/ExampleUnitTest.java @@ -7,13 +7,13 @@ import android.test.suitebuilder.annotation.MediumTest; import android.util.Log; -import com.sbxcloud.android.sbxcloudsdk.auth.SbxAuth; -import com.sbxcloud.android.sbxcloudsdk.net.callback.SbxArrayResponse; -import com.sbxcloud.android.sbxcloudsdk.net.callback.SbxSimpleResponse; +import com.sbxcloud.java.sbxcloudsdk.auth.SbxAuth; +import com.sbxcloud.java.sbxcloudsdk.callback.SbxArrayResponse; +import com.sbxcloud.java.sbxcloudsdk.callback.SbxSimpleResponse; import com.sbxcloud.android.sbxcloudsdk.net.model.SbxQuery; -import com.sbxcloud.android.sbxcloudsdk.query.SbxModelHelper; -import com.sbxcloud.android.sbxcloudsdk.query.SbxQueryBuilder; -import com.sbxcloud.android.sbxcloudsdk.util.SbxMagicComposer; +import com.sbxcloud.java.sbxcloudsdk.query.SbxModelHelper; +import com.sbxcloud.java.sbxcloudsdk.query.SbxQueryBuilder; +import com.sbxcloud.java.sbxcloudsdk.util.SbxMagicComposer; import org.json.JSONObject; import org.junit.Assert; diff --git a/app/src/test/java/com/sbxcloud/android/sbxcloudsdk/Product.java b/app/src/test/java/com/sbxcloud/android/sbxcloudsdk/Product.java index 9132071..72158a6 100644 --- a/app/src/test/java/com/sbxcloud/android/sbxcloudsdk/Product.java +++ b/app/src/test/java/com/sbxcloud/android/sbxcloudsdk/Product.java @@ -1,9 +1,9 @@ package com.sbxcloud.android.sbxcloudsdk; import com.sbxcloud.android.sbxcloudsdk.net.model.SbxModel; -import com.sbxcloud.android.sbxcloudsdk.query.annotation.SbxKey; -import com.sbxcloud.android.sbxcloudsdk.query.annotation.SbxModelName; -import com.sbxcloud.android.sbxcloudsdk.query.annotation.SbxParamField; +import com.sbxcloud.java.sbxcloudsdk.query.annotation.SbxKey; +import com.sbxcloud.java.sbxcloudsdk.query.annotation.SbxModelName; +import com.sbxcloud.java.sbxcloudsdk.query.annotation.SbxParamField; import java.util.Date; diff --git a/app/src/test/java/com/sbxcloud/android/sbxcloudsdk/User.java b/app/src/test/java/com/sbxcloud/android/sbxcloudsdk/User.java index deef65a..8c5529e 100644 --- a/app/src/test/java/com/sbxcloud/android/sbxcloudsdk/User.java +++ b/app/src/test/java/com/sbxcloud/android/sbxcloudsdk/User.java @@ -1,12 +1,12 @@ package com.sbxcloud.android.sbxcloudsdk; -import com.sbxcloud.android.sbxcloudsdk.auth.user.SbxAuthToken; -import com.sbxcloud.android.sbxcloudsdk.auth.user.SbxEmailField; -import com.sbxcloud.android.sbxcloudsdk.auth.user.SbxNameField; -import com.sbxcloud.android.sbxcloudsdk.auth.user.SbxPasswordField; +import com.sbxcloud.java.sbxcloudsdk.auth.user.SbxAuthToken; +import com.sbxcloud.java.sbxcloudsdk.auth.user.SbxEmailField; +import com.sbxcloud.java.sbxcloudsdk.auth.user.SbxNameField; +import com.sbxcloud.java.sbxcloudsdk.auth.user.SbxPasswordField; import com.sbxcloud.android.sbxcloudsdk.net.auth.SbxUser; -import com.sbxcloud.android.sbxcloudsdk.auth.user.SbxUsernameField; -import com.sbxcloud.android.sbxcloudsdk.query.annotation.SbxKey; +import com.sbxcloud.java.sbxcloudsdk.auth.user.SbxUsernameField; +import com.sbxcloud.java.sbxcloudsdk.query.annotation.SbxKey; /** * Created by lgguzman on 20/02/17. diff --git a/build.gradle b/build.gradle index c945734..ed70f1f 100644 --- a/build.gradle +++ b/build.gradle @@ -3,10 +3,14 @@ buildscript { repositories { jcenter() + maven { + url 'https://maven.google.com/' + name 'Google' + } } dependencies { - classpath 'com.android.tools.build:gradle:2.2.3' - classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' // Add this line + classpath 'com.android.tools.build:gradle:3.1.2' + classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0' // Add this line // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -16,6 +20,11 @@ buildscript { allprojects { repositories { jcenter() + maven { url 'https://jitpack.io' } + maven { + url 'https://maven.google.com/' + name 'Google' + } } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 04e285f..6a55f45 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Dec 28 10:00:20 PST 2015 +#Thu May 24 13:44:59 COT 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip