Skip to content

Commit

Permalink
Optimize package structure
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzicheng committed Aug 15, 2023
1 parent 33ea05f commit e7f6506
Show file tree
Hide file tree
Showing 25 changed files with 119 additions and 111 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
application
}

group = "com.zicheng.demo"
group = "com.zhzc0x.demo"
version = "1.0-SNAPSHOT"

repositories {
Expand Down
2 changes: 1 addition & 1 deletion library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}
apply(from="${rootDir}/library/upload-archives.gradle")

group = "com.zicheng.net.cxhttp"
group = "com.zhzc0x.cxhttp"

repositories {
mavenCentral()
Expand Down
11 changes: 0 additions & 11 deletions library/src/main/kotlin/com/zicheng/net/cxhttp/call/CxHttpCall.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.zicheng.net.cxhttp

import com.zicheng.net.cxhttp.converter.ResponseConverter
import com.zicheng.net.cxhttp.response.CxHttpResult
import com.zicheng.net.cxhttp.response.Response
import com.zicheng.net.cxhttp.request.*
import com.zicheng.net.cxhttp.response.result
import com.zicheng.net.cxhttp.response.resultList
package cxhttp

import cxhttp.converter.ResponseConverter
import cxhttp.response.CxHttpResult
import cxhttp.response.Response
import cxhttp.request.Request
import cxhttp.response.result
import cxhttp.response.resultList
import kotlinx.coroutines.*
import java.io.IOException

Expand All @@ -18,31 +18,31 @@ class CxHttp private constructor(private val request: Request, private val block

companion object{

fun get(url: String, block: suspend Request.() -> Unit = {}): CxHttp{
fun get(url: String, block: suspend Request.() -> Unit = {}): CxHttp {
return request(url, Request.Method.GET.value, block)
}

fun head(url: String, block: suspend Request.() -> Unit = {}): CxHttp{
fun head(url: String, block: suspend Request.() -> Unit = {}): CxHttp {
return request(url, Request.Method.HEAD.value, block)
}

fun post(url: String, block: suspend Request.() -> Unit = {}): CxHttp{
fun post(url: String, block: suspend Request.() -> Unit = {}): CxHttp {
return request(url, Request.Method.POST.value, block)
}

fun delete(url: String, block: suspend Request.() -> Unit = {}): CxHttp{
fun delete(url: String, block: suspend Request.() -> Unit = {}): CxHttp {
return request(url, Request.Method.DELETE.value, block)
}

fun put(url: String, block: suspend Request.() -> Unit = {}): CxHttp{
fun put(url: String, block: suspend Request.() -> Unit = {}): CxHttp {
return request(url, Request.Method.PUT.value, block)
}

fun patch(url: String, block: suspend Request.() -> Unit = {}): CxHttp{
fun patch(url: String, block: suspend Request.() -> Unit = {}): CxHttp {
return request(url, Request.Method.PATCH.value, block)
}

fun request(url: String, method: String, block: suspend Request.() -> Unit = {}): CxHttp{
fun request(url: String, method: String, block: suspend Request.() -> Unit = {}): CxHttp {
return CxHttp(Request(url, method), block)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.zicheng.net.cxhttp

import com.zicheng.net.cxhttp.call.CxHttpCall
import com.zicheng.net.cxhttp.call.Okhttp3Call
import com.zicheng.net.cxhttp.converter.CxHttpConverter
import com.zicheng.net.cxhttp.converter.JacksonConverter
import com.zicheng.net.cxhttp.response.Response
import com.zicheng.net.cxhttp.hook.*
import com.zicheng.net.cxhttp.request.Request
package cxhttp

import cxhttp.call.CxHttpCall
import cxhttp.call.Okhttp3Call
import cxhttp.converter.CxHttpConverter
import cxhttp.converter.JacksonConverter
import cxhttp.response.Response
import cxhttp.request.Request
import cxhttp.hook.HookRequest
import cxhttp.hook.HookRequestFunction
import cxhttp.hook.HookResponse
import cxhttp.hook.HookResponseFunction
import kotlinx.coroutines.CoroutineScope
import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaType
Expand Down Expand Up @@ -52,11 +55,12 @@ object CxHttpHelper {
if (debugLog) {
addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
}
}, converter: CxHttpConverter = JacksonConverter()){
this.scope = scope
this.debugLog = debugLog
this.call = call
this.converter = converter
}, converter: CxHttpConverter = JacksonConverter()
){
CxHttpHelper.scope = scope
CxHttpHelper.debugLog = debugLog
CxHttpHelper.call = call
CxHttpHelper.converter = converter
}

fun hookRequest(hook: HookRequestFunction){
Expand Down
11 changes: 11 additions & 0 deletions library/src/main/kotlin/cxhttp/call/CxHttpCall.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package cxhttp.call

import cxhttp.response.Response
import cxhttp.request.Request


interface CxHttpCall {

suspend fun await(request: Request): Response

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.zicheng.net.cxhttp.call
package cxhttp.call

import com.zicheng.net.cxhttp.response.Response
import com.zicheng.net.cxhttp.request.Request
import com.zicheng.net.cxhttp.request.buildOkhttp3Request
import cxhttp.response.Response
import cxhttp.request.Request
import cxhttp.request.buildOkhttp3Request
import kotlinx.coroutines.suspendCancellableCoroutine
import okhttp3.Call
import okhttp3.Callback
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package com.zicheng.net.cxhttp.converter
package cxhttp.converter

interface CxHttpConverter: RequestBodyConverter, ResponseConverter
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.zicheng.net.cxhttp.converter
package cxhttp.converter

import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.google.gson.reflect.TypeToken
import com.zicheng.net.cxhttp.CxHttpHelper
import com.zicheng.net.cxhttp.response.CxHttpResult
import com.zicheng.net.cxhttp.response.Response
import cxhttp.CxHttpHelper
import cxhttp.response.CxHttpResult
import cxhttp.response.Response
import java.lang.reflect.Type

class GsonConverter(private var _gson: Gson? = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.zicheng.net.cxhttp.converter
package cxhttp.converter

import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.core.json.JsonWriteFeature
Expand All @@ -7,9 +7,9 @@ import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.SerializationFeature
import com.fasterxml.jackson.databind.json.JsonMapper
import com.fasterxml.jackson.module.kotlin.KotlinModule
import com.zicheng.net.cxhttp.CxHttpHelper
import com.zicheng.net.cxhttp.response.CxHttpResult
import com.zicheng.net.cxhttp.response.Response
import cxhttp.CxHttpHelper
import cxhttp.response.CxHttpResult
import cxhttp.response.Response
import java.lang.reflect.Type
import java.text.SimpleDateFormat
import java.util.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.zicheng.net.cxhttp.converter
package cxhttp.converter

import java.lang.reflect.ParameterizedType
import java.lang.reflect.Type
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.zicheng.net.cxhttp.converter
package cxhttp.converter

interface RequestBodyConverter {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.zicheng.net.cxhttp.converter
package cxhttp.converter

import com.zicheng.net.cxhttp.CxHttpHelper
import com.zicheng.net.cxhttp.response.CxHttpResult
import com.zicheng.net.cxhttp.response.Response
import cxhttp.CxHttpHelper
import cxhttp.response.CxHttpResult
import cxhttp.response.Response
import java.lang.reflect.Type

interface ResponseConverter {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.zicheng.net.cxhttp.hook
package cxhttp.hook

import com.zicheng.net.cxhttp.request.Request
import cxhttp.request.Request

typealias HookRequestFunction = suspend HookRequest.(Request) -> Request

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.zicheng.net.cxhttp.hook
package cxhttp.hook

import com.zicheng.net.cxhttp.response.Response
import com.zicheng.net.cxhttp.request.Request
import cxhttp.response.Response
import cxhttp.request.Request

typealias HookResponseFunction = suspend HookResponse.(Response) -> Response

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.zicheng.net.cxhttp.request
package cxhttp.request

import java.io.File

Expand All @@ -11,11 +11,14 @@ class StringBody internal constructor(override val content: String, override val

class FileBody internal constructor(override val content: File, override val contentType: String): Body<File>

class ByteArrayBody internal constructor(override val content: ByteArray, override val contentType: String): Body<ByteArray>
class ByteArrayBody internal constructor(override val content: ByteArray, override val contentType: String):
Body<ByteArray>

class EntityBody<T> internal constructor(override val content: T, val tType: Class<T>, override val contentType: String): Body<T>
class EntityBody<T> internal constructor(override val content: T, val tType: Class<T>, override val contentType: String):
Body<T>

class FormBody internal constructor(override val content: MutableList<PartData>, override val contentType: String): Body<List<PartData>>{
class FormBody internal constructor(override val content: MutableList<PartData>, override val contentType: String):
Body<List<PartData>> {

var encoded = false

Expand All @@ -31,7 +34,8 @@ class FormBody internal constructor(override val content: MutableList<PartData>,

}

class MultipartBody internal constructor (override val content: MutableList<PartData>, override val contentType: String): Body<List<PartData>>{
class MultipartBody internal constructor (override val content: MutableList<PartData>, override val contentType: String):
Body<List<PartData>> {

fun append(name: String, value: String) {
content += StringPart(name, value)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.zicheng.net.cxhttp.request
package cxhttp.request

import com.zicheng.net.cxhttp.CxHttpHelper
import cxhttp.CxHttpHelper
import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.MediaType.Companion.toMediaTypeOrNull
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.zicheng.net.cxhttp.request
package cxhttp.request

import java.io.File

Expand All @@ -10,6 +10,8 @@ sealed interface PartData{

data class StringPart internal constructor(override val name: String, override val value: String): PartData

data class FilePart internal constructor(override val name: String, override val value: String?, val data: File, val contentType: String?): PartData
data class FilePart internal constructor(override val name: String, override val value: String?, val data: File, val contentType: String?):
PartData

data class ByteArrayPart internal constructor(override val name: String, override val value: String?, val data: ByteArray, val contentType: String?): PartData
data class ByteArrayPart internal constructor(override val name: String, override val value: String?, val data: ByteArray, val contentType: String?):
PartData
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.zicheng.net.cxhttp.request
package cxhttp.request

import com.zicheng.net.cxhttp.CxHttpHelper
import com.zicheng.net.cxhttp.converter.RequestBodyConverter
import cxhttp.CxHttpHelper
import cxhttp.converter.RequestBodyConverter
import java.io.File
import java.lang.IllegalArgumentException

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.zicheng.net.cxhttp.response
package cxhttp.response

import com.zicheng.net.cxhttp.CxHttpHelper
import cxhttp.CxHttpHelper

/**
* CxHttp所有请求返回的结果基类,T为任意类型,默认实现 @see HttpResult
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.zicheng.net.cxhttp.response
package cxhttp.response

import com.zicheng.net.cxhttp.CxHttpHelper
import com.zicheng.net.cxhttp.converter.ResponseConverter
import com.zicheng.net.cxhttp.request.Request
import cxhttp.CxHttpHelper
import cxhttp.converter.ResponseConverter
import cxhttp.request.Request
import java.io.InputStream

data class Response(val code: Int, val message: String, val body: Body?){
Expand Down
10 changes: 5 additions & 5 deletions library/upload-archives.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ publishing {
pom {
name = 'cxhttp'
description = 'Network request framework based on kotlin coroutine and okhttp3 package'
url = 'https://github.com/zicheng1992/cxhttp'
url = 'https://github.com/zhzc0x/cxhttp'

licenses {
license {
Expand All @@ -32,15 +32,15 @@ publishing {
}
developers {
developer {
id = 'zicheng1992'
id = 'zhzc0x'
name = 'zhangzicheng'
email = '[email protected]'
}
}
scm {
connection = 'https://github.com/zicheng1992/cxhttp.git'
developerConnection = 'https://github.com/zicheng1992/cxhttp.git'
url = 'https://github.com/zicheng1992/cxhttp'
connection = 'https://github.com/zhzc0x/cxhttp.git'
developerConnection = 'https://github.com/zhzc0x/cxhttp.git'
url = 'https://github.com/zhzc0x/cxhttp'
}
}
}
Expand Down
Loading

0 comments on commit e7f6506

Please sign in to comment.