All Downloads are FREE. Search and download functionalities are using the official Maven repository.

kotlin-client.libraries.jvm-volley.request.IRequestFactory.mustache Maven / Gradle / Ivy

There is a newer version: 7.9.0
Show newest version
package {{packageName}}.request

import com.android.volley.Request
import com.android.volley.Response
import java.io.UnsupportedEncodingException
import java.lang.reflect.Type
import java.net.URLEncoder
import java.text.ParseException
import java.text.SimpleDateFormat
import java.util.*
import java.time.format.DateTimeFormatter
import java.time.OffsetDateTime
import java.time.LocalDate


interface IRequestFactory {

    companion object {
        /**
         * ISO 8601 date time format.
         * @see https://en.wikipedia.org/wiki/ISO_8601
         */
        fun formatDateTime(datetime: OffsetDateTime) = DateTimeFormatter.ISO_INSTANT.format(datetime)
        fun formatDate(date: LocalDate) = DateTimeFormatter.ISO_LOCAL_DATE.format(date)

        fun escapeString(str: String): String {
            return try {
                URLEncoder.encode(str, "UTF-8")
            } catch (e: UnsupportedEncodingException) {
                str
            }
        }

        fun parameterToString(param: Any?) =
            when (param) {
                null -> ""
                is OffsetDateTime -> formatDateTime(param)
                is Collection<*> -> {
                  val b = StringBuilder()
                  for (o in param) {
                      if (b.isNotEmpty()) {
                          b.append(",")
                      }
                      b.append(o.toString())
                  }
                  b.toString()
                }
                else -> param.toString()
            }
        }


    fun  build(
        method: Int,
        url : String,
        body: Any?,
        headers: Map?,
        queryParams: Map?,
        formParams: Map?,
        contentTypeForBody: String?,
        type: Type,
        responseListener: Response.Listener,
        errorListener: Response.ErrorListener): Request
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy