-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dynamic config feature and adjust default endpoint to api2 (#247)
* Add dynamic config feature and adjust default endpoint to api2 * Revert change on test file * Minor format change
- Loading branch information
1 parent
e0be8af
commit 9af032b
Showing
3 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.amplitude.api; | ||
|
||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.net.HttpURLConnection; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
|
||
public class ConfigManager { | ||
private static String KEY_INGESTION_ENDPOINT = "ingestionEndpoint"; | ||
|
||
private static ConfigManager instance = null; | ||
|
||
private String ingestionEndpoint = Constants.EVENT_LOG_URL; | ||
|
||
public String getIngestionEndpoint() { | ||
return ingestionEndpoint; | ||
} | ||
|
||
private ConfigManager() { | ||
} | ||
|
||
public void refresh(RefreshListener listener) { | ||
try { | ||
URL obj = new URL(Constants.DYNAMIC_CONFIG_URL); | ||
HttpURLConnection con = (HttpURLConnection) obj.openConnection(); | ||
|
||
int responseCode = con.getResponseCode(); | ||
|
||
if (responseCode == 200) { | ||
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); | ||
String inputLine; | ||
StringBuffer response = new StringBuffer(); | ||
|
||
while ((inputLine = in.readLine()) != null) { | ||
response.append(inputLine); | ||
} | ||
in.close(); | ||
|
||
JSONObject json = new JSONObject(response.toString()); | ||
if (json.has(KEY_INGESTION_ENDPOINT)) { | ||
this.ingestionEndpoint = "https://" + json.getString(KEY_INGESTION_ENDPOINT); | ||
} | ||
} | ||
} catch (MalformedURLException e) { | ||
|
||
} catch (IOException e) { | ||
|
||
} catch (JSONException e) { | ||
|
||
} | ||
|
||
listener.onFinished(); | ||
} | ||
|
||
public static ConfigManager getInstance() { | ||
if (instance == null) { | ||
instance = new ConfigManager(); | ||
} | ||
|
||
return instance; | ||
} | ||
|
||
interface RefreshListener { | ||
void onFinished(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters