Leanplum / Leanplum-Android-SDK

Leanplum's integrated solution delivers meaningful engagement across messaging and the in-app experience.
https://www.leanplum.com
Apache License 2.0
46 stars 40 forks source link

Configurable API endpoint #485

Closed hborisoff closed 2 years ago

hborisoff commented 2 years ago
What Where/Who
JIRA Issue SDK-665
People Involved @hborisoff

Background

Change API and Dev server endpoints based on API response. HTTP status will be 200 OK and success false. Example of response:

{
  "response": [
    {
      "success": false,
      "apiHost": "api2.leanplum.com",
      "apiPath": "new-api",
      "devServerHost": "dev2.leanplum.com",
      "error": {
        "message": "App endpoint configuration mismatch."
      }
    }
  ]
}

Implementation

RequestSender.sendRequests checks if the response returns a new API config, then changes the hosts and retries the request. Callbacks will be executed by the subsequent request.

Socket layer is modified to allow disconnecting of old socket and connecting a new one. Important to note is that you need to wait until socket is connected to disconnect it successfully.

New API and Dev server configs are saved in shared preferences from APIConfig.

Testing steps

Added couple of unit tests in ChangeHostTest.java. Most modifications are tested manually.