Last active
September 11, 2019 17:24
-
-
Save Rizwan-Hasan/556120cd18c04679901d18ab50d11ef9 to your computer and use it in GitHub Desktop.
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
/* | |
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