Skip to content

Commit

Permalink
feat: rename callbacks for proxy server
Browse files Browse the repository at this point in the history
  • Loading branch information
abhilashdas-cred committed Mar 27, 2024
1 parent 888696e commit 5498108
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void setUp() {
private void setUpInstance(boolean trackAutomaticEvents) {
final RemoteService mockPoster = new HttpService() {
@Override
public byte[] performRequest(String endpointUrl, ProxyServerInteractor callback, Map<String, Object> params, SSLSocketFactory socketFactory) {
public byte[] performRequest(String endpointUrl, ProxyServerInteractor interactor, Map<String, Object> params, SSLSocketFactory socketFactory) {

final String jsonData = Base64Coder.decodeString(params.get("data").toString());
assertTrue(params.containsKey("data"));
Expand Down Expand Up @@ -212,7 +212,7 @@ public void testAutomaticMultipleInstances() throws InterruptedException {

final HttpService mpSecondPoster = new HttpService() {
@Override
public byte[] performRequest(String endpointUrl, ProxyServerInteractor callback, Map<String, Object> params, SSLSocketFactory socketFactory) {
public byte[] performRequest(String endpointUrl, ProxyServerInteractor interactor, Map<String, Object> params, SSLSocketFactory socketFactory) {
final String jsonData = Base64Coder.decodeString(params.get("data").toString());
assertTrue(params.containsKey("data"));
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void setUp() {

final RemoteService mockPoster = new HttpService() {
@Override
public byte[] performRequest(String endpointUrl, ProxyServerInteractor callback, Map<String, Object> params, SSLSocketFactory socketFactory)
public byte[] performRequest(String endpointUrl, ProxyServerInteractor interactor, Map<String, Object> params, SSLSocketFactory socketFactory)
throws ServiceUnavailableException, IOException {
try {
if (mFlushResults.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ public int addJSON(JSONObject message, String token, MPDbAdapter.Table table) {

final RemoteService mockPoster = new HttpService() {
@Override
public byte[] performRequest(String endpointUrl, ProxyServerInteractor callback, Map<String, Object> params, SSLSocketFactory socketFactory) {
public byte[] performRequest(String endpointUrl, ProxyServerInteractor interactor, Map<String, Object> params, SSLSocketFactory socketFactory) {
final boolean isIdentified = isIdentifiedRef.get();
assertTrue(params.containsKey("data"));
final String decoded = Base64Coder.decodeString(params.get("data").toString());
Expand Down Expand Up @@ -1398,7 +1398,7 @@ protected AnalyticsMessages getAnalyticsMessages() {
public void testAlias() {
final RemoteService mockPoster = new HttpService() {
@Override
public byte[] performRequest(String endpointUrl, ProxyServerInteractor callback, Map<String, Object> params, SSLSocketFactory socketFactory) {
public byte[] performRequest(String endpointUrl, ProxyServerInteractor interactor, Map<String, Object> params, SSLSocketFactory socketFactory) {
try {
assertTrue(params.containsKey("data"));
final String jsonData = Base64Coder.decodeString(params.get("data").toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void setUp() {

final RemoteService mockPoster = new HttpService() {
@Override
public byte[] performRequest(String endpointUrl, ProxyServerInteractor callback, Map<String, Object> params, SSLSocketFactory socketFactory) {
public byte[] performRequest(String endpointUrl, ProxyServerInteractor interactor, Map<String, Object> params, SSLSocketFactory socketFactory) {
if (params != null) {
final String jsonData = Base64Coder.decodeString(params.get("data").toString());
assertTrue(params.containsKey("data"));
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/mixpanel/android/mpmetrics/MPConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,9 @@ public String getEventsEndpoint() {

public boolean getTrackAutomaticEvents() { return mTrackAutomaticEvents; }

public void setServerURL(String serverURL, ProxyServerInteractor callback) {
public void setServerURL(String serverURL, ProxyServerInteractor interactor) {
setServerURL(serverURL);
setProxyServerInteractor(callback);
setProxyServerInteractor(interactor);
}

// In parity with iOS SDK
Expand Down Expand Up @@ -423,8 +423,8 @@ public ProxyServerInteractor getMixpanelServerCallback() {
return this.serverCallbacks;
}

public void setProxyServerInteractor(ProxyServerInteractor callback) {
this.serverCallbacks = callback;
public void setProxyServerInteractor(ProxyServerInteractor interactor) {
this.serverCallbacks = interactor;
}

// Package access for testing only- do not call directly in library code
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/mixpanel/android/util/HttpService.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private boolean onOfflineMode(OfflineMode offlineMode) {
}

@Override
public byte[] performRequest(String endpointUrl, ProxyServerInteractor callback, Map<String, Object> params, SSLSocketFactory socketFactory) throws ServiceUnavailableException, IOException {
public byte[] performRequest(String endpointUrl, ProxyServerInteractor interactor, Map<String, Object> params, SSLSocketFactory socketFactory) throws ServiceUnavailableException, IOException {
MPLog.v(LOGTAG, "Attempting request to " + endpointUrl);

byte[] response = null;
Expand All @@ -114,8 +114,8 @@ public byte[] performRequest(String endpointUrl, ProxyServerInteractor callback,
((HttpsURLConnection) connection).setSSLSocketFactory(socketFactory);
}

if (callback != null && isProxyRequest(endpointUrl)) {
Map<String,String> headers = callback.getProxyRequestHeaders();
if (interactor != null && isProxyRequest(endpointUrl)) {
Map<String,String> headers = interactor.getProxyRequestHeaders();
if (headers != null) {
for (Map.Entry<String, String> entry : headers.entrySet()) {
connection.setRequestProperty(entry.getKey(), entry.getValue());
Expand Down Expand Up @@ -144,8 +144,8 @@ public byte[] performRequest(String endpointUrl, ProxyServerInteractor callback,
out.close();
out = null;
}
if (callback != null && isProxyRequest(endpointUrl)) {
callback.onProxyResponse(endpointUrl, connection.getResponseCode());
if (interactor != null && isProxyRequest(endpointUrl)) {
interactor.onProxyResponse(endpointUrl, connection.getResponseCode());
}
in = connection.getInputStream();
response = slurp(in);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/mixpanel/android/util/RemoteService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface RemoteService {

void checkIsMixpanelBlocked();

byte[] performRequest(String endpointUrl, ProxyServerInteractor callback, Map<String, Object> params, SSLSocketFactory socketFactory)
byte[] performRequest(String endpointUrl, ProxyServerInteractor interactor, Map<String, Object> params, SSLSocketFactory socketFactory)
throws ServiceUnavailableException, IOException;

class ServiceUnavailableException extends Exception {
Expand Down

0 comments on commit 5498108

Please sign in to comment.