Last active
February 16, 2016 11:31
-
-
Save korniltsev/53b184d5cc9414733764 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
def createSlackTasks() { | |
mAndroidAppExtension.applicationVariants.all{ | |
if (!it.buildType.debuggable){ | |
def task = mProject.tasks.create("slack${it.name.capitalize()}", UploadSlackTask) | |
task.variant = it | |
task.dependsOn it.assemble | |
} | |
} | |
} | |
class UploadSlackTask extends DefaultTask { | |
@Input | |
ApplicationVariant variant; | |
@TaskAction | |
def upload(){ | |
File apkFile = variant.outputs[0].outputFile | |
def http = new HTTPBuilder("https://slack.com/api/files.upload") | |
http.request(Method.POST) { req -> | |
requestContentType: "multipart/form-data" | |
MultipartEntity multiPartContent = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE) | |
multiPartContent.addPart("channels", new StringBody("android")) | |
multiPartContent.addPart("token", new StringBody("xoxp-")) | |
multiPartContent.addPart("file", new FileBody(apkFile)) | |
req.setEntity(multiPartContent) | |
response.success = { resp, reader -> | |
if (resp.statusLine.statusCode == 200) { | |
println(reader.getText()) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
could you provide a complete example ?
I can not integrate it in my script .
Thanks Ivan