Skip to content

Instantly share code, notes, and snippets.

@Rizwan-Hasan
Last active September 11, 2019 17:24
Show Gist options
  • Save Rizwan-Hasan/556120cd18c04679901d18ab50d11ef9 to your computer and use it in GitHub Desktop.
Save Rizwan-Hasan/556120cd18c04679901d18ab50d11ef9 to your computer and use it in GitHub Desktop.
/*
Used module from https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple/1.1.1
*/
import org.json.simple.JSONArray
import org.json.simple.JSONObject
import org.json.simple.parser.JSONParser
import java.net.URL
import java.nio.charset.Charset
fun main() {
val userName = "magpie-robins" // User name of the repository
val repoName = "gpa-calculator-android" // Repository name
val releaseTag = "latest" // Using tag 'latest' for latest released download count
val url = "https://api.github.com/repos/$userName/$repoName/releases/$releaseTag" // API URL
val jsonString = URL(url).readText(Charset.forName("UTF-8"))
var jsonObject: JSONObject = JSONParser().parse(jsonString) as JSONObject
jsonObject = (jsonObject["assets"] as JSONArray)[0] as JSONObject
val downloadCount: Any? = jsonObject["download_count"]
print("Total downloads: $downloadCount")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment