mirror of https://github.com/MISP/misp-bump
improved rest api
parent
c11d12932c
commit
436c5bafac
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -12,108 +12,114 @@ import android.support.v7.widget.Toolbar;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.Toast;
|
||||||
|
import com.android.volley.VolleyError;
|
||||||
import de.overview.wg.its.mispauth.R;
|
import de.overview.wg.its.mispauth.R;
|
||||||
import de.overview.wg.its.mispauth.adapter.ExtOrgAdapter;
|
import de.overview.wg.its.mispauth.adapter.ExtOrgAdapter;
|
||||||
import de.overview.wg.its.mispauth.auxiliary.PreferenceManager;
|
import de.overview.wg.its.mispauth.auxiliary.PreferenceManager;
|
||||||
|
import de.overview.wg.its.mispauth.auxiliary.ReadableError;
|
||||||
import de.overview.wg.its.mispauth.model.Organisation;
|
import de.overview.wg.its.mispauth.model.Organisation;
|
||||||
|
import de.overview.wg.its.mispauth.network.MispRequest;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private Organisation[] externalOrganisations;
|
private Organisation[] externalOrganisations;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
|
||||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
getExternalOrganisations();
|
getExternalOrganisations();
|
||||||
setUpRecyclerView();
|
setUpRecyclerView();
|
||||||
|
|
||||||
FloatingActionButton fabAdd = findViewById(R.id.fab_add);
|
FloatingActionButton fabAdd = findViewById(R.id.fab_add);
|
||||||
final FloatingActionButton fabSync = findViewById(R.id.fab_sync);
|
final FloatingActionButton fabSync = findViewById(R.id.fab_sync);
|
||||||
|
|
||||||
fabAdd.setOnClickListener(new View.OnClickListener() {
|
fabAdd.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if(fabSync.getVisibility() == View.GONE){
|
if (fabSync.getVisibility() == View.GONE) {
|
||||||
fabSync.setVisibility(View.VISIBLE);
|
fabSync.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
fabSync.setVisibility(View.GONE);
|
fabSync.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
fabSync.setOnClickListener(new View.OnClickListener() {
|
fabSync.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
startSyncActivity();
|
startSyncActivity();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
getMenuInflater().inflate(R.menu.menu_main, menu);
|
getMenuInflater().inflate(R.menu.menu_main, menu);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
|
||||||
int id = item.getItemId();
|
|
||||||
|
|
||||||
if (id == R.id.menu_item_settings) {
|
@Override
|
||||||
startActivity(new Intent(this, SettingsActivity.class));
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
return true;
|
int id = item.getItemId();
|
||||||
}
|
|
||||||
|
|
||||||
return super.onOptionsItemSelected(item);
|
if (id == R.id.menu_item_settings) {
|
||||||
}
|
startActivity(new Intent(this, SettingsActivity.class));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private void setUpRecyclerView() {
|
return super.onOptionsItemSelected(item);
|
||||||
RecyclerView orgRecyclerView = findViewById(R.id.orgRecyclerView);
|
}
|
||||||
orgRecyclerView.setHasFixedSize(true);
|
|
||||||
|
|
||||||
RecyclerView.LayoutManager orgLayoutManager = new LinearLayoutManager(this);
|
private void setUpRecyclerView() {
|
||||||
orgRecyclerView.setLayoutManager(orgLayoutManager);
|
RecyclerView orgRecyclerView = findViewById(R.id.orgRecyclerView);
|
||||||
|
orgRecyclerView.setHasFixedSize(true);
|
||||||
|
|
||||||
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(orgRecyclerView.getContext(), 1);
|
RecyclerView.LayoutManager orgLayoutManager = new LinearLayoutManager(this);
|
||||||
orgRecyclerView.addItemDecoration(dividerItemDecoration);
|
orgRecyclerView.setLayoutManager(orgLayoutManager);
|
||||||
|
|
||||||
RecyclerView.Adapter orgAdapter = new ExtOrgAdapter(this, externalOrganisations);
|
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(orgRecyclerView.getContext(), 1);
|
||||||
orgRecyclerView.setAdapter(orgAdapter);
|
orgRecyclerView.addItemDecoration(dividerItemDecoration);
|
||||||
|
|
||||||
if(externalOrganisations.length == 0){
|
RecyclerView.Adapter orgAdapter = new ExtOrgAdapter(this, externalOrganisations);
|
||||||
orgRecyclerView.setVisibility(View.GONE);
|
orgRecyclerView.setAdapter(orgAdapter);
|
||||||
findViewById(R.id.empty_view).setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
orgRecyclerView.setVisibility(View.VISIBLE);
|
|
||||||
findViewById(R.id.empty_view).setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
final SwipeRefreshLayout refreshLayout = findViewById(R.id.recycler_refresh);
|
if (externalOrganisations.length == 0) {
|
||||||
refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
orgRecyclerView.setVisibility(View.GONE);
|
||||||
@Override
|
findViewById(R.id.empty_view).setVisibility(View.VISIBLE);
|
||||||
public void onRefresh() {
|
} else {
|
||||||
// TODO do stuff
|
orgRecyclerView.setVisibility(View.VISIBLE);
|
||||||
// refreshLayout.setRefreshing(false);
|
findViewById(R.id.empty_view).setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getExternalOrganisations(){
|
final SwipeRefreshLayout refreshLayout = findViewById(R.id.recycler_refresh);
|
||||||
Organisation a = new Organisation();
|
refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||||
a.setName("Ferrari");
|
@Override
|
||||||
a.setDescription("Ferrari has nothing to share");
|
public void onRefresh() {
|
||||||
a.setSector("Fast cars");
|
// TODO do stuff
|
||||||
a.setNationality("Italy");
|
// refreshLayout.setRefreshing(false);
|
||||||
a.setUserCount(67);
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
externalOrganisations = new Organisation[] {a};
|
private void getExternalOrganisations() {
|
||||||
}
|
Organisation a = new Organisation();
|
||||||
|
a.setName("Ferrari");
|
||||||
|
a.setDescription("Ferrari has nothing to share");
|
||||||
|
a.setSector("Fast cars");
|
||||||
|
a.setNationality("Italy");
|
||||||
|
a.setLocal(false);
|
||||||
|
|
||||||
private void startSyncActivity(){
|
externalOrganisations = new Organisation[]{a};
|
||||||
startActivity(new Intent(this, SyncActivity.class));
|
}
|
||||||
}
|
|
||||||
|
private void startSyncActivity() {
|
||||||
|
startActivity(new Intent(this, SyncActivity.class));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,7 +153,7 @@ public class SettingsActivity extends AppCompatActivity {
|
||||||
|
|
||||||
progressBar.setVisibility(View.VISIBLE);
|
progressBar.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
request.myUserInformation(new MispRequest.UserInformationCallback() {
|
request.myUserInformation(new MispRequest.UserCallback() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResult(JSONObject myUserInformation) {
|
public void onResult(JSONObject myUserInformation) {
|
||||||
|
@ -163,7 +163,7 @@ public class SettingsActivity extends AppCompatActivity {
|
||||||
|
|
||||||
int orgID = user.getOrgId();
|
int orgID = user.getOrgId();
|
||||||
|
|
||||||
request.OrganisationInformation(orgID, new MispRequest.OrganisationInformationCallback() {
|
request.OrganisationInformation(orgID, new MispRequest.OrganisationCallback() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResult(JSONObject organisationInformation) {
|
public void onResult(JSONObject organisationInformation) {
|
||||||
|
|
|
@ -2,7 +2,11 @@ package de.overview.wg.its.mispauth.activity;
|
||||||
|
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import com.android.volley.VolleyError;
|
||||||
import de.overview.wg.its.mispauth.R;
|
import de.overview.wg.its.mispauth.R;
|
||||||
|
import de.overview.wg.its.mispauth.model.Organisation;
|
||||||
|
import de.overview.wg.its.mispauth.network.MispRequest;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
public class SyncActivity extends AppCompatActivity {
|
public class SyncActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
@ -11,4 +15,20 @@ public class SyncActivity extends AppCompatActivity {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_sync);
|
setContentView(R.layout.activity_sync);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void uploadOrganisation(Organisation org) {
|
||||||
|
MispRequest mispRequest = MispRequest.Instance(this);
|
||||||
|
|
||||||
|
mispRequest.addOrganisation(org, new MispRequest.OrganisationCallback() {
|
||||||
|
@Override
|
||||||
|
public void onResult(JSONObject organisationInformation) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(VolleyError volleyError) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,14 +3,37 @@ package de.overview.wg.its.mispauth.auxiliary;
|
||||||
import com.android.volley.AuthFailureError;
|
import com.android.volley.AuthFailureError;
|
||||||
import com.android.volley.NoConnectionError;
|
import com.android.volley.NoConnectionError;
|
||||||
import com.android.volley.VolleyError;
|
import com.android.volley.VolleyError;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
public class ReadableError {
|
public class ReadableError {
|
||||||
|
|
||||||
public static String toReadable(VolleyError volleyError) {
|
public static String toReadable(VolleyError volleyError) {
|
||||||
|
|
||||||
if(volleyError instanceof NoConnectionError) {
|
if (volleyError.networkResponse != null) {
|
||||||
|
try {
|
||||||
|
JSONObject response = new JSONObject(new String(volleyError.networkResponse.data, StandardCharsets.UTF_8));
|
||||||
|
JSONObject error = response.getJSONObject("errors");
|
||||||
|
|
||||||
|
String name = response.getString("name");
|
||||||
|
String errorName = error.getJSONArray("name").get(0).toString();
|
||||||
|
|
||||||
|
if(!errorName.equals("")) {
|
||||||
|
return errorName;
|
||||||
|
} else if (!name.equals("")) {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (volleyError instanceof NoConnectionError) {
|
||||||
return "Connection failed";
|
return "Connection failed";
|
||||||
} else if(volleyError instanceof AuthFailureError) {
|
} else if (volleyError instanceof AuthFailureError) {
|
||||||
return "Authentication failed";
|
return "Authentication failed";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,6 @@ public class Organisation {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONObject toJSON() {
|
public JSONObject toJSON() {
|
||||||
JSONObject org = new JSONObject();
|
JSONObject org = new JSONObject();
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ import com.android.volley.VolleyError;
|
||||||
import com.android.volley.toolbox.JsonObjectRequest;
|
import com.android.volley.toolbox.JsonObjectRequest;
|
||||||
import com.android.volley.toolbox.Volley;
|
import com.android.volley.toolbox.Volley;
|
||||||
import de.overview.wg.its.mispauth.auxiliary.PreferenceManager;
|
import de.overview.wg.its.mispauth.auxiliary.PreferenceManager;
|
||||||
|
import de.overview.wg.its.mispauth.model.Organisation;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
@ -21,148 +22,199 @@ import java.util.Map;
|
||||||
*/
|
*/
|
||||||
public class MispRequest {
|
public class MispRequest {
|
||||||
|
|
||||||
private static final String TAG = "MISP-TAG";
|
private static final String TAG = "DEBUG";
|
||||||
private static MispRequest instance;
|
private static MispRequest instance;
|
||||||
|
|
||||||
private RequestQueue requestQueue;
|
private RequestQueue requestQueue;
|
||||||
private PreferenceManager preferenceManager;
|
private PreferenceManager preferenceManager;
|
||||||
|
private String serverUrl, apiKey;
|
||||||
|
|
||||||
private String serverUrl, apiKey;
|
/**
|
||||||
|
* @param context for Volley and PreferenceManager
|
||||||
|
*/
|
||||||
|
private MispRequest(Context context) {
|
||||||
|
requestQueue = Volley.newRequestQueue(context);
|
||||||
|
preferenceManager = PreferenceManager.Instance(context);
|
||||||
|
loadSavedCredentials();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
private void loadSavedCredentials() {
|
||||||
* @param context for Volley and PreferenceManager
|
serverUrl = preferenceManager.getMyServerUrl();
|
||||||
*/
|
apiKey = preferenceManager.getMyServerApiKey();
|
||||||
private MispRequest(Context context) {
|
}
|
||||||
requestQueue = Volley.newRequestQueue(context);
|
|
||||||
preferenceManager = PreferenceManager.Instance(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param orgId organisation ID on the MISP-Instance
|
* @param orgId organisation ID on the MISP-Instance
|
||||||
* @param callback returns a single Organisation-JSON
|
* @param callback returns a single Organisation-JSON
|
||||||
*/
|
*/
|
||||||
public void OrganisationInformation(int orgId, final OrganisationInformationCallback callback) {
|
public void OrganisationInformation(int orgId, final OrganisationCallback callback) {
|
||||||
|
|
||||||
Response.Listener<JSONObject> listener = new Response.Listener<JSONObject>() {
|
Response.Listener<JSONObject> listener = new Response.Listener<JSONObject>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(JSONObject response) {
|
public void onResponse(JSONObject response) {
|
||||||
try {
|
try {
|
||||||
callback.onResult(response.getJSONObject("Organisation"));
|
callback.onResult(response.getJSONObject("Organisation"));
|
||||||
return;
|
return;
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
callback.onResult(response);
|
callback.onResult(response);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Response.ErrorListener errorListener = new Response.ErrorListener() {
|
Response.ErrorListener errorListener = new Response.ErrorListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onErrorResponse(VolleyError error) {
|
public void onErrorResponse(VolleyError error) {
|
||||||
callback.onError(error);
|
callback.onError(error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Request r = objectRequest(Request.Method.GET,
|
Request r = objectRequest(Request.Method.GET,
|
||||||
serverUrl + "/organisations/view/"+orgId,
|
serverUrl + "/organisations/view/" + orgId,
|
||||||
null,
|
null,
|
||||||
listener,
|
listener,
|
||||||
errorListener);
|
errorListener);
|
||||||
|
|
||||||
requestQueue.add(r);
|
requestQueue.add(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Typically used to get the organisation linked with this user
|
* Typically used to get the organisation linked with this user
|
||||||
* @param callback return user associated with this API-Key
|
*
|
||||||
*/
|
* @param callback return user associated with this API-Key
|
||||||
public void myUserInformation(final UserInformationCallback callback) {
|
*/
|
||||||
|
public void myUserInformation(final UserCallback callback) {
|
||||||
|
|
||||||
Response.Listener<JSONObject> listener = new Response.Listener<JSONObject>() {
|
Response.Listener<JSONObject> listener = new Response.Listener<JSONObject>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(JSONObject response) {
|
public void onResponse(JSONObject response) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
callback.onResult(response.getJSONObject("User"));
|
callback.onResult(response.getJSONObject("User"));
|
||||||
return;
|
return;
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
callback.onResult(response);
|
callback.onResult(response);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Response.ErrorListener errorListener = new Response.ErrorListener() {
|
Response.ErrorListener errorListener = new Response.ErrorListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onErrorResponse(VolleyError error) {
|
public void onErrorResponse(VolleyError error) {
|
||||||
Log.e(TAG, "onErrorResponse: " + error.toString());
|
Log.e(TAG, "onErrorResponse: " + error.toString());
|
||||||
callback.onError(error);
|
callback.onError(error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if(serverUrl.isEmpty() || apiKey.isEmpty()) {
|
if (serverUrl.isEmpty() || apiKey.isEmpty()) {
|
||||||
Log.e(TAG, "myUserInformation: server or api key is empty!");
|
Log.e(TAG, "myUserInformation: server or api key is empty!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Request r = objectRequest(
|
Request r = objectRequest(
|
||||||
Request.Method.GET,
|
Request.Method.GET,
|
||||||
serverUrl + "/users/view/me",
|
serverUrl + "/users/view/me",
|
||||||
null,
|
null,
|
||||||
listener,
|
listener,
|
||||||
errorListener);
|
errorListener);
|
||||||
|
|
||||||
requestQueue.add(r);
|
requestQueue.add(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param organisation The organisation that will be added
|
||||||
|
* @param callback returns complete organisation JSON
|
||||||
|
*/
|
||||||
|
public void addOrganisation(Organisation organisation, final OrganisationCallback callback) {
|
||||||
|
Response.Listener<JSONObject> listener = new Response.Listener<JSONObject>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(JSONObject response) {
|
||||||
|
try {
|
||||||
|
callback.onResult(response.getJSONObject("Organisation"));
|
||||||
|
return;
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
callback.onResult(response);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Response.ErrorListener errorListener = new Response.ErrorListener() {
|
||||||
|
@Override
|
||||||
|
public void onErrorResponse(VolleyError error) {
|
||||||
|
callback.onError(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Request r = objectRequest(
|
||||||
|
Request.Method.POST,
|
||||||
|
serverUrl + "/admin/organisations/add",
|
||||||
|
organisation.toJSON(),
|
||||||
|
listener,
|
||||||
|
errorListener
|
||||||
|
);
|
||||||
|
|
||||||
|
requestQueue.add(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private JsonObjectRequest objectRequest(int method,
|
private JsonObjectRequest objectRequest(int method,
|
||||||
String url,
|
String url,
|
||||||
@Nullable JSONObject body,
|
@Nullable JSONObject body,
|
||||||
Response.Listener<JSONObject> listener,
|
Response.Listener<JSONObject> listener,
|
||||||
Response.ErrorListener errorListener){
|
Response.ErrorListener errorListener) {
|
||||||
|
|
||||||
return new JsonObjectRequest(method, url, body, listener, errorListener) {
|
return new JsonObjectRequest(method, url, body, listener, errorListener) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String> getHeaders() {
|
public Map<String, String> getHeaders() {
|
||||||
Map<String, String> params = new HashMap<>();
|
Map<String, String> params = new HashMap<>();
|
||||||
|
|
||||||
params.put("Authorization", apiKey);
|
params.put("Authorization", apiKey);
|
||||||
params.put("Accept", "application/json");
|
params.put("Accept", "application/json");
|
||||||
params.put("Content-Type", "application/json; utf-8");
|
params.put("Content-Type", "application/json; utf-8");
|
||||||
|
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setServerCredentials(String serverUrl, String apiKey) {
|
public void setServerCredentials(String serverUrl, String apiKey) {
|
||||||
this.serverUrl = serverUrl;
|
this.serverUrl = serverUrl;
|
||||||
this.apiKey = apiKey;
|
this.apiKey = apiKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static MispRequest Instance(Context context) {
|
||||||
|
if (instance == null) {
|
||||||
|
instance = new MispRequest(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static MispRequest Instance(Context context) {
|
public interface IntegerCallback {
|
||||||
if(instance == null) {
|
void onResult(int result);
|
||||||
instance = new MispRequest(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
return instance;
|
void onError(VolleyError volleyError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface OrganisationCallback {
|
||||||
|
void onResult(JSONObject organisationInformation);
|
||||||
|
|
||||||
public interface OrganisationInformationCallback {
|
void onError(VolleyError volleyError);
|
||||||
void onResult(JSONObject organisationInformation);
|
}
|
||||||
void onError(VolleyError volleyError);
|
|
||||||
}
|
public interface UserCallback {
|
||||||
public interface UserInformationCallback {
|
void onResult(JSONObject myOrganisationInformation);
|
||||||
void onResult(JSONObject myOrganisationInformation);
|
|
||||||
void onError(VolleyError volleyError);
|
void onError(VolleyError volleyError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue