Skip to content

Commit

Permalink
add addParts(Map<Part>)、addParts(List<Part>) method
Browse files Browse the repository at this point in the history
  • Loading branch information
liujingxing committed Apr 13, 2024
1 parent 93f0695 commit 7f631d4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,15 @@ open class RxHttpFormParam(param: FormParam) : RxHttpAbstractBodyParam<FormParam
requestBody: RequestBody
) = addPart(OkHttpCompat.part(key, fileName, requestBody))

fun addPart(key: String, requestBody: RequestBody) = addFormDataPart(key, null, requestBody)

fun addParts(partMap: Map<String, RequestBody>) = apply {
partMap.forEach { (key, value) -> addPart(key, value) }
}

fun addPart(part: MultipartBody.Part) = apply { param.addPart(part) }

fun addParts(parts: List<MultipartBody.Part>) = apply { parts.forEach { addPart(it) } }

//Set content-type to multipart/form-data
fun setMultiForm() = setMultiType(MultipartBody.FORM)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,11 +388,6 @@ class ClassHelper(private val isAndroidPlatform: Boolean) {
return this;
}
""")}
public RxHttpFormParam addPart(MultipartBody.Part part) {
param.addPart(part);
return this;
}
public RxHttpFormParam addPart(RequestBody requestBody) {
return addPart(OkHttpCompat.part(requestBody));
}
Expand All @@ -404,6 +399,29 @@ class ClassHelper(private val isAndroidPlatform: Boolean) {
public RxHttpFormParam addFormDataPart(String key, @Nullable String fileName, RequestBody requestBody) {
return addPart(OkHttpCompat.part(key, fileName, requestBody));
}
public RxHttpFormParam addPart(String key, RequestBody requestBody) {
return addFormDataPart(key, null, requestBody);
}
public RxHttpFormParam addParts(Map<String, RequestBody> partMap) {
for (Entry<String, RequestBody> entry : partMap.entrySet()) {
addPart(entry.getKey(), entry.getValue());
}
return this;
}
public RxHttpFormParam addPart(MultipartBody.Part part) {
param.addPart(part);
return this;
}
public RxHttpFormParam addParts(List<MultipartBody.Part> parts) {
for (MultipartBody.Part part: parts) {
addPart(part);
}
return this;
}
//Set content-type to multipart/form-data
public RxHttpFormParam setMultiForm() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,15 @@ class KClassHelper(
requestBody: RequestBody
) = addPart(OkHttpCompat.part(key, fileName, requestBody))
fun addPart(key: String, requestBody: RequestBody) = addFormDataPart(key, null, requestBody)
fun addParts(partMap: Map<String, RequestBody>) = apply {
partMap.forEach { (key, value) -> addPart(key, value) }
}
fun addPart(part: MultipartBody.Part) = apply { param.addPart(part) }
fun addParts(parts: List<MultipartBody.Part>) = apply { parts.forEach { addPart(it) } }
//Set content-type to multipart/form-data
fun setMultiForm() = setMultiType(MultipartBody.FORM)
Expand Down

0 comments on commit 7f631d4

Please sign in to comment.