-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1260 from embrace-io/refactor-api-code
Begin refactoring api code
- Loading branch information
Showing
73 changed files
with
809 additions
and
542 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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
43 changes: 43 additions & 0 deletions
43
...id-core/src/main/kotlin/io/embrace/android/embracesdk/internal/comms/api/ApiRequestExt.kt
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,43 @@ | ||
package io.embrace.android.embracesdk.internal.comms.api | ||
|
||
import io.embrace.android.embracesdk.network.http.HttpMethod | ||
import java.io.IOException | ||
|
||
public fun ApiRequest.getHeaders(): Map<String, String> { | ||
val headers = mutableMapOf( | ||
"Accept" to accept, | ||
"User-Agent" to userAgent, | ||
"Content-Type" to contentType | ||
) | ||
contentEncoding?.let { headers["Content-Encoding"] = it } | ||
acceptEncoding?.let { headers["Accept-Encoding"] = it } | ||
appId?.let { headers["X-EM-AID"] = it } | ||
deviceId?.let { headers["X-EM-DID"] = it } | ||
eventId?.let { headers["X-EM-SID"] = it } | ||
logId?.let { headers["X-EM-LID"] = it } | ||
eTag?.let { headers["If-None-Match"] = it } | ||
return headers | ||
} | ||
|
||
internal fun ApiRequest.toConnection(): EmbraceConnection { | ||
try { | ||
val connection = EmbraceUrl.create(url.url).openConnection() | ||
|
||
getHeaders().forEach { | ||
connection.setRequestProperty(it.key, it.value) | ||
} | ||
connection.setRequestMethod(httpMethod.name) | ||
if (httpMethod == HttpMethod.POST) { | ||
connection.setDoOutput(true) | ||
} | ||
return connection | ||
} catch (ex: IOException) { | ||
throw IllegalStateException(ex.localizedMessage ?: "", ex) | ||
} | ||
} | ||
|
||
/** | ||
* Returns true if the request is a session request. This heuristic should not be widely used | ||
* - it is only used to prioritise session requests over other requests. | ||
*/ | ||
public fun ApiRequest.isSessionRequest(): Boolean = url.url.endsWith("spans") |
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
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
Oops, something went wrong.