lytics / ios-sdk

MIT License
0 stars 0 forks source link

Request Cache #24

Closed mgacy closed 2 years ago

mgacy commented 2 years ago

Implements the RequestCache to persist failed requests. It uses Storage to handle reading and writing to a file and CodableRequestContainer to make an array of existentials encodable and decodable. It works by encoding each underlying PendingRequest as the String of its mangled type name (including its generic values) and the encoded JSON String. The encoded values look like:

[
  "6Lytics8UploaderC14PendingRequestCy_AA18DataUploadResponseVG",
  "{\"id\":\"3939AB0F-566B-4257-94EF-BDF8B504EC3A\",\"request\":{\"body\":\"eyJpZGVudGlmaWVycyI6eyJlbWFpbCI6InNvbWVlbWFpbEBseXRpY3MuY29tIiwidXNlcklEIjoxMjM0LCJuZXN0ZWQiOnsiYiI6IjIiLCJhIjoxfX0sInByb3BlcnRpZXMiOnsib3JkZXJJZCI6InNvbWUtb3JkZXItaWQiLCJ0b3RhbCI6MTkuOTUwMDAwNzYyOTM5NDUzfSwiX3RzIjoxNjY2MDAwMDAyNTAwLCJuYW1lIjoibmFtZSJ9\",\"method\":\"POST\",\"headers\":[{\"name\":\"Content-Type\",\"value\":\"application\\/json\"},{\"name\":\"Authorization\",\"value\":\"abcd\"}],\"url\":\"https:\\/\\/api.lytics.io\\/collect\\/json\\/stream_3\"}}"
]

As CodableRequestContainer uses a Swift Foundation method that is only available on iOS 14+ this bumps the minimum supported version to iOS 14.0.

Tests will be included in the next PR to keep the size of this one manageable.