diff --git a/.idea/markdown-exported-files.xml b/.idea/markdown-exported-files.xml new file mode 100644 index 0000000..5d1f129 --- /dev/null +++ b/.idea/markdown-exported-files.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index cbd46bd..3827dc0 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -27,7 +27,11 @@ - +<<<<<<< HEAD + +======= + +>>>>>>> d1327f10938106fc8c356505d4ae81c30a76cc71 diff --git a/app/src/main/java/androidsdk/devless/io/devlesssdkofficial/MainActivity.java b/app/src/main/java/androidsdk/devless/io/devlesssdkofficial/MainActivity.java index 33cc811..df8d8e6 100644 --- a/app/src/main/java/androidsdk/devless/io/devlesssdkofficial/MainActivity.java +++ b/app/src/main/java/androidsdk/devless/io/devlesssdkofficial/MainActivity.java @@ -6,6 +6,20 @@ import android.os.Bundle; import android.util.Log; +import java.util.HashMap; +import java.util.Map; + +import androidsdk.devless.io.devless.interfaces.DeleteResponse; +import androidsdk.devless.io.devless.interfaces.EditDataResponse; +import androidsdk.devless.io.devless.interfaces.GetDataResponse; +import androidsdk.devless.io.devless.interfaces.LoginResponse; +import androidsdk.devless.io.devless.interfaces.PostDataResponse; +import androidsdk.devless.io.devless.interfaces.SearchResponse; +import androidsdk.devless.io.devless.interfaces.SignUpResponse; +import androidsdk.devless.io.devless.main.Devless; +import androidsdk.devless.io.devless.messages.ErrorMessage; +import androidsdk.devless.io.devless.messages.Payload; +import androidsdk.devless.io.devless.messages.ResponsePayload; public class MainActivity extends AppCompatActivity { @@ -17,6 +31,192 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + //Create a shared preference like this + SharedPreferences sp = getSharedPreferences(getPackageName(), Context.MODE_PRIVATE); + + //Now go ahead and set devless up + String appUrl = "http://buildgallery.herokuapp.com"; // remember no slash after the com just the absolute URL + String devlessToken = "41b1f8b6dd4823f63f8eeed626bfafa8"; //this is my token + + //This is how to create a devless instance + //Devless devless = new Devless(this, appUrl, devlessToken); + + /* + setUpDevlessUserToken Right under the instance and pass in the + name of your shared preference variable. Im my case I called my shared preference *sp* + */ + //devless.addUserToken(sp); + + //Log.e("token", devless.getDevlessUserToken()); + + + //Log.e("==repo==", devless.getDevlessUserToken()); + + + // Sign Up + /* + devless.signUpWithEmailAndPassword("email1@email.com", "password", sp, new SignUpResponse() { + @Override + public void onSignUpSuccess(Payload payload) { + Log.e("==Success==", payload.toString()); + } + + @Override + public void onSignUpFailed(ErrorMessage errorMessage) { + Log.e("==Failure==", errorMessage.toString()); + } + }); + */ + + + + +// devless.loginWithEmailAndPassword("email1@email.com", "password", sp, new LoginResponse() { +// @Override +// public void onLogInSuccess(ResponsePayload response) { +// Log.e("==Passed==", response.toString()); +// } +// +// @Override +// public void onLogInFailed(ErrorMessage errorMessage) { +// Log.e("==Failure==", errorMessage.toString()); +// } +// }); + + +// +// devless.getData("gitmo", "test_table", new GetDataResponse() { +// @Override +// public void onSuccess(ResponsePayload response) { +// Log.e("Success", response.toString()); +// } +// +// @Override +// public void onFailed(ErrorMessage errorMessage) { +// Log.e("Failure", errorMessage.toString()); +// } +// +// @Override +// public void userNotAuthenticated(ErrorMessage message) { +// Log.e("UserNotAuth", message.toString()); +// } +// +// @Override +// public void fullRequestResponse(ResponsePayload response) { +// Log.e("Full", response.toString()); +// } +// }); + + + + + + + + //Post Data +// Map data = new HashMap(); +// data.put("name", "koobi"); +// +// devless.postData("plans", "test_table", data, new PostDataResponse() { +// @Override +// public void onSuccess(ResponsePayload response) { +// Log.e("success", response.toString()); +// } +// +// @Override +// public void onFailed(ErrorMessage errorMessage) { +// Log.e("Failed", errorMessage.toString()); +// } +// +// @Override +// public void userNotAuthenticated(ErrorMessage message) { +// Log.e("UnAuth", message.toString()); +// } +// +// @Override +// public void fullPostDataResponse(ResponsePayload response) { +// Log.e("FullPostdata", response.toString()); +// } +// }); + + + /* get data + devless.getData("plans", "test_table", new GetDataResponse() { + @Override + public void onSuccess(ResponsePayload response) { + Log.e("success", response.toString()); + } + + @Override + public void onFailed(ErrorMessage errorMessage) { + Log.e("Failed", errorMessage.toString()); + } + + @Override + public void userNotAuthenticated(ErrorMessage message) { + Log.e("UnAuth", message.toString()); + } + + @Override + public void fullRequestResponse(ResponsePayload response) { + Log.e("FullPostData", response.toString()); + } + }); + */ + + + /* + Map change = new HashMap<>(); + change.put("name", "kulee"); + + devless.edit("plans", "test_table", change, "1", new EditDataResponse() { + @Override + public void onSuccess(ResponsePayload response) { + Log.e("success", response.toString()); + } + + @Override + public void onFailed(ErrorMessage errorMessage) { + Log.e("Failed", errorMessage.toString()); + } + + @Override + public void userNotAuthenticated(ErrorMessage message) { + Log.e("UnAuth", message.toString()); + } + + @Override + public void fullEditDataResponse(ResponsePayload response) { + Log.e("FullPostData", response.toString()); + } + }); + */ + + /* Delete Message + devless.delete("plans", "test_table", "1", new DeleteResponse() { + @Override + public void onSuccess(ResponsePayload response) { + Log.e("success", response.toString()); + } + + @Override + public void onFailed(ErrorMessage errorMessage) { + Log.e("Failed", errorMessage.toString()); + } + + @Override + public void userNotAuthenticated(ErrorMessage message) { + Log.e("UnAuth", message.toString()); + } + + @Override + public void fullDeleteResponse(ResponsePayload response) { + Log.e("FullPostData", response.toString()); + } + }); + */ + + } diff --git a/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/interfaces/DeleteResponse.java b/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/interfaces/DeleteResponse.java index e85c832..7aa5ce4 100644 --- a/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/interfaces/DeleteResponse.java +++ b/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/interfaces/DeleteResponse.java @@ -12,5 +12,6 @@ public interface DeleteResponse { void onSuccess(ResponsePayload response); void onFailed(ErrorMessage errorMessage); void userNotAuthenticated(ErrorMessage message); + void fullDeleteResponse (ResponsePayload response); } diff --git a/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/interfaces/EditDataResponse.java b/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/interfaces/EditDataResponse.java index f0e08dd..279dc6b 100644 --- a/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/interfaces/EditDataResponse.java +++ b/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/interfaces/EditDataResponse.java @@ -12,4 +12,5 @@ public interface EditDataResponse { void onSuccess(ResponsePayload response); void onFailed(ErrorMessage errorMessage); void userNotAuthenticated(ErrorMessage message); + void fullEditDataResponse(ResponsePayload response); } diff --git a/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/interfaces/GetDataResponse.java b/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/interfaces/GetDataResponse.java index 044e820..6f6af97 100644 --- a/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/interfaces/GetDataResponse.java +++ b/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/interfaces/GetDataResponse.java @@ -11,4 +11,5 @@ public interface GetDataResponse { void onSuccess(ResponsePayload response); void onFailed(ErrorMessage errorMessage); void userNotAuthenticated(ErrorMessage message); + void fullRequestResponse (ResponsePayload response); } diff --git a/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/interfaces/LoginResponse.java b/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/interfaces/LoginResponse.java index e73f41b..3a3cbb0 100644 --- a/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/interfaces/LoginResponse.java +++ b/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/interfaces/LoginResponse.java @@ -10,4 +10,5 @@ public interface LoginResponse { void onLogInSuccess(ResponsePayload response); void onLogInFailed(ErrorMessage errorMessage); + } diff --git a/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/interfaces/LogoutResponse.java b/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/interfaces/LogoutResponse.java index ad8c13e..21637cc 100644 --- a/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/interfaces/LogoutResponse.java +++ b/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/interfaces/LogoutResponse.java @@ -8,4 +8,5 @@ public interface LogoutResponse { void onLogOutSuccess(ResponsePayload response); + void fullLogoutResponse(ResponsePayload response); } diff --git a/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/interfaces/PostDataResponse.java b/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/interfaces/PostDataResponse.java index e4ac641..3296844 100644 --- a/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/interfaces/PostDataResponse.java +++ b/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/interfaces/PostDataResponse.java @@ -11,4 +11,5 @@ public interface PostDataResponse { void onSuccess(ResponsePayload response); void onFailed(ErrorMessage errorMessage); void userNotAuthenticated(ErrorMessage message); + void fullPostDataResponse(ResponsePayload response); } diff --git a/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/interfaces/RequestResponse.java b/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/interfaces/RequestResponse.java index 051ec52..3242c55 100644 --- a/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/interfaces/RequestResponse.java +++ b/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/interfaces/RequestResponse.java @@ -10,4 +10,5 @@ public interface RequestResponse { void onSuccess(ResponsePayload response); void userNotAuthenticated(ErrorMessage message); +// void fullRequestResponse(ResponsePayload response); } diff --git a/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/interfaces/SearchResponse.java b/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/interfaces/SearchResponse.java index 445e93d..e41c40f 100644 --- a/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/interfaces/SearchResponse.java +++ b/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/interfaces/SearchResponse.java @@ -10,4 +10,5 @@ public interface SearchResponse { void onSuccess(ResponsePayload response); void userNotAuthenticated(ErrorMessage errorMessage); + void fullSearchResponse(ResponsePayload responsePayload); } diff --git a/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/interfaces/SignUpResponse.java b/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/interfaces/SignUpResponse.java index 726d9fc..8badc5c 100644 --- a/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/interfaces/SignUpResponse.java +++ b/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/interfaces/SignUpResponse.java @@ -2,6 +2,7 @@ import androidsdk.devless.io.devless.messages.ErrorMessage; import androidsdk.devless.io.devless.messages.Payload; +import androidsdk.devless.io.devless.messages.ResponsePayload; /** * Created by pianoafrik on 6/8/17. @@ -10,4 +11,5 @@ public interface SignUpResponse { void onSignUpSuccess(Payload payload); void onSignUpFailed(ErrorMessage errorMessage); + } diff --git a/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/main/Devless.java b/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/main/Devless.java index 4b4d474..df11bcc 100644 --- a/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/main/Devless.java +++ b/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/main/Devless.java @@ -6,6 +6,8 @@ import android.text.TextUtils; import android.util.Log; +import com.google.gson.Gson; + import org.json.JSONException; import org.json.JSONObject; import java.io.IOException; @@ -46,6 +48,7 @@ public class Devless extends AppCompatActivity implements Serializable{ Context mContext; private String rootUrl, token, devlessUserToken="", where = "", orderBy="id", empty; private int size = -1 ; + private static String TAG="Devless"; public Devless(Context mContext, String rootUrl, String token) { @@ -93,11 +96,67 @@ public void onFailure(Call call, Throwable t) { }); } + public void postMassData(String serviceName, String tableName, ArrayList> dataToAdd, final PostDataResponse requestResponseresponse){ + Retrofit retrofit = new Retrofit.Builder() + .baseUrl(DevlessBuilder.formUrl(rootUrl, serviceName)) + .addConverterFactory(GsonConverterFactory.create()) + .build(); + + POSTAPI postapi = retrofit.create(POSTAPI.class); + Call result = postapi.sendPosts("db?table="+tableName, + token, devlessUserToken ,DevlessBuilder.createMultiAssign(tableName, dataToAdd)); + + + result.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + try { + + String result = response.body().string(); + Log.d(TAG,"Invites response "+response.body().string()); + boolean bool = DevlessBuilder.checkAuth(result); + if (bool){ + + int successPull = DevlessBuilder.checkPostSuccess(result); + Log.d(TAG,"Devless Edit "+result); + if(successPull == 1){ + // successful + requestResponseresponse.onSuccess(new ResponsePayload(result)); + + } else if (successPull == 0){ + //wrong fieldname + String errorMessage = "Error: Post failed because there was a wrong fieldName please check it"; + requestResponseresponse.onFailed(new ErrorMessage(errorMessage)); + + } else { + // errorMessage + String errorMessage = "Error: The ServiceName or TableName doesn't exist"; + requestResponseresponse.onFailed(new ErrorMessage(errorMessage)); + } + + + } else{ + requestResponseresponse.userNotAuthenticated( new ErrorMessage("Token expired please log in again")); + } + + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + requestResponseresponse.onSuccess( new ResponsePayload( t.toString())); + } + }); + } + public void postData(String serviceName, String tableName, Map dataToAdd, final PostDataResponse requestResponseresponse) { Retrofit retrofit = new Retrofit.Builder() .baseUrl(DevlessBuilder.formUrl(rootUrl, serviceName)) .addConverterFactory(GsonConverterFactory.create()) .build(); + POSTAPI postapi = retrofit.create(POSTAPI.class); Call result = postapi.sendPosts("db?table="+tableName, token, devlessUserToken ,DevlessBuilder.createPostBody(tableName, dataToAdd)); @@ -112,6 +171,7 @@ public void onResponse(Call call, Response response) if (bool){ int successPull = DevlessBuilder.checkPostSuccess(result); + Log.d(TAG,"Devless Edit "+result); if(successPull == 1){ // successful requestResponseresponse.onSuccess(new ResponsePayload(result)); @@ -160,6 +220,7 @@ public void onResponse(Call call, Response response) boolean bool = DevlessBuilder.checkAuth(result); if (bool){ int successPull = DevlessBuilder.checkPostSuccess(result); + Log.d(TAG,"Devless Edit Result "+result); if(successPull == 1){ // successful requestResponseresponse.onSuccess(new ResponsePayload(result)); @@ -297,6 +358,7 @@ public void onSuccess(ResponsePayload response) { String token = resultObject.getString("token"); editor.putString("devlessUserToken", token); editor.commit(); + setDevlessUserToken(token); } else if (resultObject.length() == 3) { ErrorMessage errorMessage = new ErrorMessage("Seems Email already exists wool"); signUpResponse.onSignUpFailed(errorMessage); @@ -337,15 +399,19 @@ public void onSuccess(ResponsePayload response) { JSONObject JO = new JSONObject(response.toString()); String payload = JO.getString("payload"); JSONObject payloadObject = new JSONObject(payload); - String result = payloadObject.getString("result"); - JSONObject resultObject = new JSONObject(result); - if(resultObject.length() == 2){ + if (payloadObject.has("result")){ + String result = payloadObject.getString("result"); + JSONObject resultObject = new JSONObject(result); Payload resultPayload = new Payload(payload); signUpResponse.onSignUpSuccess(resultPayload); String token = resultObject.getString("token"); editor.putString("devlessUserToken", token); editor.commit(); - } else if (resultObject.length() == 3) { + setDevlessUserToken(token); + }else if (payloadObject.has("error")){ + ErrorMessage errorMessage = new ErrorMessage(payloadObject.getJSONObject("error").getString("message")); + signUpResponse.onSignUpFailed(errorMessage); + }else{ ErrorMessage errorMessage = new ErrorMessage("Seems PhoneNumber already exists"); signUpResponse.onSignUpFailed(errorMessage); } @@ -390,6 +456,7 @@ public void onSuccess(ResponsePayload response) { String token = resultObject.getString("token"); editor.putString("devlessUserToken", token); editor.commit(); + setDevlessUserToken(token); } else if (resultObject.length() == 3) { ErrorMessage errorMessage = new ErrorMessage("Seems UserName already exists"); signUpResponse.onSignUpFailed(errorMessage); @@ -412,6 +479,7 @@ public void userNotAuthenticated(ErrorMessage errorMessage) { } public void methodCall(String serviceName, String actionName, List params, final RequestResponse requestResponseresponse) { + Retrofit retrofit = new Retrofit.Builder() .baseUrl(rootUrl + "/api/v1/service/"+ serviceName + "/") .addConverterFactory(GsonConverterFactory.create()) @@ -419,11 +487,14 @@ public void methodCall(String serviceName, String actionName, List param POSTAPI postapi = retrofit.create(POSTAPI.class); Call result = postapi.sendPosts("rpc?action="+ actionName, token,devlessUserToken, DevlessBuilder.callBodyBuilder(serviceName, params)); + Log.d(TAG,"token "+token); + Log.d(TAG,"devlessToken "+devlessUserToken); result.enqueue(new Callback() { @Override public void onResponse(Call call, Response response) { try { + Log.d("DevlessEnque",new Gson().toJson(response)); requestResponseresponse.onSuccess( new ResponsePayload( response.body().string())); } catch (IOException e) { @@ -443,7 +514,7 @@ public void loginWithEmailAndPassword(String email, final String password, final final SharedPreferences.Editor editor = sp.edit(); List loginParams = new ArrayList<>(Arrays.asList( "", - email, + email, "", password )); @@ -462,6 +533,7 @@ public void onSuccess(ResponsePayload response) { String token = payloadReturnedObject.getString("token"); editor.putString("devlessUserToken", token); editor.commit(); + setDevlessUserToken(token); ResponsePayload responsePayload = new ResponsePayload(result); loginResponse.onLogInSuccess(responsePayload); } else { @@ -504,6 +576,7 @@ public void onSuccess(ResponsePayload response) { String token = payloadReturnedObject.getString("token"); editor.putString("devlessUserToken", token); editor.commit(); + setDevlessUserToken(token); ResponsePayload responsePayload = new ResponsePayload(result); loginResponse.onLogInSuccess(responsePayload); } else { @@ -548,6 +621,7 @@ public void onSuccess(ResponsePayload response) { String token = payloadReturnedObject.getString("token"); editor.putString("devlessUserToken", token); editor.commit(); + setDevlessUserToken(token); ResponsePayload responsePayload = new ResponsePayload(result); loginResponse.onLogInSuccess(responsePayload); } else { @@ -655,11 +729,11 @@ public void onResponse(Call call, Response response) String result = response.body().string(); boolean bool = DevlessBuilder.checkAuth(result); - if (bool){ + if (bool){ searchResponse.onSuccess(new ResponsePayload(result)); - } else{ - searchResponse.userNotAuthenticated(new ErrorMessage("Token expired please log in again")); - } + } else{ + searchResponse.userNotAuthenticated(new ErrorMessage("Token expired please log in again")); + } } catch (IOException e) { e.printStackTrace(); @@ -689,32 +763,32 @@ public Devless queryOrderedData(String serviceName, final String tableName, fina .build(); final APISERVICE service = retrofit.create(APISERVICE.class); - final Call result = service.getCalls("db?table=" + tableName + "&size="+this.size+ "&orderBy=" + this.orderBy, token, devlessUserToken); - result.enqueue(new Callback() { - @Override - public void onResponse(Call call, Response response) { - try { + final Call result = service.getCalls("db?table=" + tableName + "&size="+this.size+ "&orderBy=" + this.orderBy, token, devlessUserToken); + result.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + try { - String result = response.body().string(); + String result = response.body().string(); - boolean bool = DevlessBuilder.checkAuth(result); - if (bool){ - searchResponse.onSuccess(new ResponsePayload(result)); - } else{ - searchResponse.userNotAuthenticated(new ErrorMessage("Token expired please log in again") ); - } + boolean bool = DevlessBuilder.checkAuth(result); + if (bool){ + searchResponse.onSuccess(new ResponsePayload(result)); + } else{ + searchResponse.userNotAuthenticated(new ErrorMessage("Token expired please log in again") ); + } - } catch (IOException e) { - e.printStackTrace(); - } + } catch (IOException e) { + e.printStackTrace(); } + } - @Override - public void onFailure(Call call, Throwable t) { - searchResponse.onSuccess(new ResponsePayload(t.toString())); - } - }); + @Override + public void onFailure(Call call, Throwable t) { + searchResponse.onSuccess(new ResponsePayload(t.toString())); + } + }); return this; } @@ -768,6 +842,8 @@ public void onFailure(Call call, Throwable t) { + + private List loopJson (JSONObject jsonObject){ List ele = new ArrayList<>(); int i = 0; @@ -806,9 +882,10 @@ public void updateProfile( String phoneNumber, String firstname, String lastname, - String others, + String others,SharedPreferences sharedPreferences, final RequestResponse requestResponse) { + devlessUserToken= sharedPreferences.getString("devlessUserToken",""); List updateDetails = new ArrayList<>(Arrays.asList( email, password, username, phoneNumber, firstname, lastname, others )); diff --git a/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/utils/DevlessBuilder.java b/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/utils/DevlessBuilder.java index 6d2cf93..5e9f333 100644 --- a/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/utils/DevlessBuilder.java +++ b/dv-android-sdk-1.0/src/main/java/androidsdk/devless/io/devless/utils/DevlessBuilder.java @@ -1,5 +1,7 @@ package androidsdk.devless.io.devless.utils; +import android.util.Log; + import org.json.JSONException; import org.json.JSONObject; @@ -9,10 +11,13 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.function.Consumer; public class DevlessBuilder { + + public static String formUrl (String rootUrl, String serviceName) { return rootUrl + "/api/v1/service/" + serviceName + "/"; } @@ -30,6 +35,22 @@ public static Map createPostBody (String table_name, Map createMultiAssign (String table_name, ArrayList> fieldMap){ + Map map = new HashMap(); + List mainList = new ArrayList(); + Map miniMap = new HashMap(); + List fieldList = new ArrayList(); + for (Map temp : fieldMap) { + fieldList.add(temp); + } + + miniMap.put("name", table_name); + miniMap.put("field", fieldList); + mainList.add(miniMap); + map.put("resource", mainList); + Log.d("MassAssign ",map.toString()); + return map; + } public static Map createPatchBody (String table_name, Map dataChange, String id) { Map map = new HashMap(); @@ -83,11 +104,11 @@ public static Map createDeleteAllBody (String table_name) { } public static Map signUpBuilder (String userName, - String email, - String password, - String phoneNumber, - String firstName, - String lastName) + String email, + String password, + String phoneNumber, + String firstName, + String lastName) { Map signUp = new HashMap<>(); @@ -139,11 +160,11 @@ public static boolean checkAuth ( String response){ } - return bool; + return bool; } public static boolean checkGetSuccess(String response){ - boolean bool = false; + boolean bool = false; try { JSONObject JO = new JSONObject(response); int statusCode = JO.getInt("status_code");