Skip to content

Instantly share code, notes, and snippets.

@RoRoche
Last active November 20, 2019 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RoRoche/d0904d45db98ebe5bad2f2f8b7b256f1 to your computer and use it in GitHub Desktop.
Save RoRoche/d0904d45db98ebe5bad2f2f8b7b256f1 to your computer and use it in GitHub Desktop.
import okhttp3.Response
import org.json.JSONArray
class JsonRepos(private val repos: List<Repo>) : List<Repo> by repos {
constructor(json: String) : this(JSONArray(json))
constructor(jsonArray: JSONArray) : this(
(0 until jsonArray.length())
.map(jsonArray::getJSONObject)
.map { JsonRepo(it) }
)
constructor(restRequest: RestRequest) : this(restRequest.response())
constructor(response: Response) : this(
response.body!!.string()
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment