Skip to content

Commit

Permalink
chore: merge branch 'feature/okhttp3' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ghasemdev committed Aug 22, 2022
2 parents 6f4955b + 6a61d58 commit 46ce581
Show file tree
Hide file tree
Showing 55 changed files with 2,797 additions and 162 deletions.
11 changes: 7 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [🎉 1.5.0 Structure, Logger] - 2022-08-22
## [🎉 1.5.0 Structure, Logger, OkHttp] - 2022-08-22

### 🚀 Features

* Add `okhttp-android` module
* okhttp builder extension `okhttpClient {}` , `Response.new {}` and `OkHttpClient.new {}`.
* download and upload progress listener `DownloadStreamResponseBody`, `UploadStreamRequestBody`.
* Add `logger-android` module
* `LogLevel` enum.
* `logcat` extension.
* Singleton `Logger`.
* `LogLevel` enum.
* `logcat` extension.
* Singleton `Logger`.

### 💥 Breaking Changes

Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ data class Foo(val bar: String)
YandexMetricaX.reportEvent("event_name", Foo("bar"))
```

### [Okhttp](https://github.com/ghasemdev/affogato/wiki/Okhttp)

Okhttp builder is part of this module. You can use it for building okhttp client with a simple
syntax. Also, you can track download and upload progress with `DownloadStreamResponseBody`
and `UploadStreamRequestBody`.

```kotlin
val client = okHttp {
addInterceptor(HttpLoggingInterceptor())
cache(Cache(cacheDir, cacheSize))
}
```

### [Structure](https://github.com/ghasemdev/affogato/wiki/Structure)

This module contains useful structure class like `DataState` and `EntityMapper`. Also, it contains
Expand Down
2 changes: 0 additions & 2 deletions affogato-core-ktx/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ tasks.test {
dependencies {
// Serialization ---------------------------------------------------------------------------------
api("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.0")

// Immutable Collections -------------------------------------------------------------------------
api("org.jetbrains.kotlinx:kotlinx-collections-immutable:0.3.5")

// DateTime --------------------------------------------------------------------------------------
api("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0")

Expand Down
18 changes: 0 additions & 18 deletions affogato-coroutines-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,6 @@ plugins {
android {
compileSdk = 33
buildToolsVersion = "33.0.0"

defaultConfig {
minSdk = 21
targetSdk = 33

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
Expand Down
Empty file.
21 changes: 0 additions & 21 deletions affogato-coroutines-android/proguard-rules.pro

This file was deleted.

18 changes: 0 additions & 18 deletions affogato-logger-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,6 @@ plugins {
android {
compileSdk = 33
buildToolsVersion = "33.0.0"

defaultConfig {
minSdk = 14
targetSdk = 33

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
Expand Down
Empty file.
21 changes: 0 additions & 21 deletions affogato-logger-android/proguard-rules.pro

This file was deleted.

18 changes: 0 additions & 18 deletions affogato-metrica-ktx/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,6 @@ plugins {
android {
compileSdk = 33
buildToolsVersion = "33.0.0"

defaultConfig {
minSdk = 14
targetSdk = 33

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
Expand Down
Empty file.
21 changes: 0 additions & 21 deletions affogato-metrica-ktx/proguard-rules.pro

This file was deleted.

2 changes: 2 additions & 0 deletions affogato-okhttp-android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build
.gradle
43 changes: 43 additions & 0 deletions affogato-okhttp-android/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
plugins {
id("com.android.library")
kotlin("android")
id("maven-publish")
}

android {
compileSdk = 33
buildToolsVersion = "33.0.0"
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
apiVersion = "1.7"
languageVersion = "1.7"
jvmTarget = "11"
}
}

dependencies {
// define a BOM and its version
implementation(platform("com.squareup.okhttp3:okhttp-bom:4.10.0"))

// define any required OkHttp artifacts without version
api("com.squareup.okhttp3:okhttp")
api("com.squareup.okhttp3:logging-interceptor")
testApi("com.squareup.okhttp3:mockwebserver")
}

afterEvaluate {
publishing {
publications {
create<MavenPublication>("release") {
groupId = "com.parsuomash.affogato"
artifactId = "affogato-okhttp-android"
version = "1.5.0"

from(components["release"])
}
}
}
}
2 changes: 2 additions & 0 deletions affogato-okhttp-android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.parsuomash.affogato.okhttp.android" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package com.parsuomash.affogato.okhttp.android

import java.util.concurrent.ExecutorService
import okhttp3.Cache
import okhttp3.Call
import okhttp3.ConnectionPool
import okhttp3.OkHttpClient
import okhttp3.Response

/**
* Factory for [calls][Call], which can be used to send HTTP requests and read their responses.
*
* ## OkHttpClients Should Be Shared
*
* OkHttp performs best when you create a single `OkHttpClient` instance and reuse it for all of
* your HTTP calls. This is because each client holds its own connection pool and thread pools.
* Reusing connections and threads reduces latency and saves memory. Conversely, creating a client
* for each request wastes resources on idle pools.
*
* Use `OkHttpClient()` to create a shared instance with the default settings:
*
* ```
* // The singleton HTTP client.
* val client = OkHttpClient()
* ```
*
* Or use `okHttp { }` to create a shared instance with custom settings:
*
* ```
* // The singleton HTTP client.
* val client = okHttp {
* addInterceptor(HttpLoggingInterceptor())
* cache(Cache(cacheDir, cacheSize))
* }
* ```
*
* ## Customize Your Client With newBuilder()
*
* You can customize a shared OkHttpClient instance with [new]. This builds a client that
* shares the same connection pool, thread pools, and configuration. Use the builder methods to
* configure the derived client for a specific purpose.
*
* This example shows a call with a short 500 millisecond timeout:
*
* ```
* val eagerClient = okHttp {
* readTimeout(500, TimeUnit.MILLISECONDS)
* }
* val response = eagerClient.newCall(request).execute()
* ```
*
* ## Shutdown Isn't Necessary
*
* The threads and connections that are held will be released automatically if they remain idle. But
* if you are writing an application that needs to aggressively release unused resources you may do
* so.
*
* Shutdown the dispatcher's executor service with [shutdown()][ExecutorService.shutdown]. This will
* also cause future calls to the client to be rejected.
*
* ```
* client.dispatcher().executorService().shutdown()
* ```
*
* Clear the connection pool with [evictAll()][ConnectionPool.evictAll]. Note that the connection
* pool's daemon thread may not exit immediately.
*
* ```
* client.connectionPool().evictAll()
* ```
*
* If your client has a cache, call [close()][Cache.close]. Note that it is an error to create calls
* against a cache that is closed, and doing so will cause the call to crash.
*
* ```
* client.cache().close()
* ```
*
* OkHttp also uses daemon threads for HTTP/2 connections. These will exit automatically if they
* remain idle.
* @since 1.5.0
* @see OkHttpClient
*/
inline fun okHttp(
init: OkHttpClient.Builder.() -> Unit
): OkHttpClient {
val builder: OkHttpClient.Builder = OkHttpClient.Builder().also { init(it) }
return builder.build()
}

/**
* @since 1.5.0
* @see OkHttpClient
*/
inline fun OkHttpClient.new(
init: OkHttpClient.Builder.() -> Unit
): OkHttpClient {
val builder: OkHttpClient.Builder = newBuilder().also { init(it) }
return builder.build()
}

/**
* @since 1.5.0
* @see Response
*/
inline fun Response.new(
init: Response.Builder.() -> Unit
): Response {
val builder: Response.Builder = newBuilder().also { init(it) }
return builder.build()
}
Loading

0 comments on commit 46ce581

Please sign in to comment.