Skip to content

SMFDrummer/Medal-core

Repository files navigation

logo


Medal-core

English | 简体中文

Medal's core library, the ultimate tool for packet delivery

Medal-core is fully developed by Kotlin, compatible with Kotlin Multiplatform, with rich extension functions and Kotlin-DSL, supports flexible policy configuration, and is compatible with IOS/Android and packet delivery of various channels.

Kotlin version Maven Central Version GitHub License


Introduction

Medal-core is a unified core library for packet DSL, build, modify, delivery, and post-processing, and completes all processing of packets in the fastest and most efficient way.

  • PacketBuiltIn:The core library has a built-in structure for most of the packets, allowing for rapid packet building
  • Self-implementation policy configuration resolution:Custom JSON policy configuration, Kotlin-DSL configuration, and dynamic policy configuration are supported
  • MultiPlatformSupport:It supports IOS/Android and data packet delivery from various channels, which is easy to set up and easy to use
  • AbundantExtensionFunctions:A large number of extension functions are supported to facilitate the rapid construction of data packets
  • BuiltInSQLite:In the future, built-in SQLite will be supported to support the construction and operation of user databases

SimpleExample

Here's a simple example of using Medal-core, showing how to use Medal-core to quickly process packets

suspend fun main() {
    latestVersion = getLatestVersion()
    platformManager.switchToAndroid(Channel.Official)

    val user = User(
        userId = primitive { 12345678 },
        password = "medal-test-password"
    )
    
    buildStrategy {
        version = 1
        description = "Android - Get user credentials"

        packet {
            i = "V202"
            retry = 4
            ext("sk") { "sk" }
            ext("ui") { "ui" }
            onSuccess { true }
        }
    }.execute(user) {
        println("Response: ${responses["V202"]}")
        println("Val sk: ${variables["sk"]}")
        println("Val ui: ${variables["ui"]}")
    }
}
suspend fun main() {
    latestVersion = getLatestVersion()
    platformManager.switchToAndroid(Channel.Official)

    val user = User(
        userId = primitive { 12345678 },
        password = "medal-test-password"
    )
    
    """
        {
            "version": 1,
            "description": "Android - Get user credentials",
            "packets": [
                {
                    "i": "V202",
                    "r": 0,
                    "t": {},
                    "repeat": 1,
                    "retry": 4,
                    "extract": {
                        "sk": "d.sk",
                        "ui": "d.ui"
                    },
                    "onSuccess": true
                }
            ]
        }
    """.trimIndent().to<StrategyConfig>().execute(user) {
        println("Response: ${responses["V202"]}")
        println("Val sk: ${variables["sk"]}")
        println("Val ui: ${variables["ui"]}")
    }
}

The above two methods are completely equivalent, and both use the Medal-core method to construct packets, execute packets, and process packets

OperatingEnvironment

  • JDK 21 - jvmJDK 17 - android
  • Kotlin 2.1.0
  • Maven 3.6.3+ or Gradle 8.10.2

Make sure that the kotlin plugin for your IDE supports kotlin 2.1.0 or later

Incompatible Gradle 8.12 or above

If you build in Intellij IDEA with an error,or build with Maven、 try enabling the following settings: Settings / Build, Execution, Deployment / Build Tools / Maven / Runner / Delegate IDE build/run actions to Maven.


Installation

Gradle(kts)

Make sure your project root of settings.gradle.kts is added Maven Central repository

dependencyResolutionManagement {
    repositories {
        mavenCentral()
        maven("https://maven.aliyun.com/repository/public") // Optional for China Mainland users
    }
}

Then add dependency in build.gradle.kts

dependencies {
    implementation("io.github.smfdrummer:medal-core:${latest.version}")
}

Including latest.version is the latest version number,you can find it in Maven Central

Gradle(groovy)

Make sure your project root of settings.gradle is added Maven Central repository

dependencyResolutionManagement {
    repositories {
        mavenCentral()
        maven { url 'https://maven.aliyun.com/repository/public' } // Optional for China Mainland users
    }
}

Then add dependency in build.gradle

dependencies {
    implementation 'io.github.smfdrummer:medal-core:{{latest.version}}'
}

Including latest.version is the latest version number,you can find it in Maven Central

Maven

Add the following to the pom.xml file:

  1. Add Maven Central repository (If it is not included by default):
<repositories>
    <repository>
        <id>central</id>
        <url>https://repo.maven.apache.org/maven2</url>
    </repository>
    <!-- Aliyun public Maven repository for China Mainland users -->
    <repository>
        <id>aliyun-central</id>
        <url>https://maven.aliyun.com/repository/public</url>
    </repository>
</repositories>
  1. Add medal-core dependency:
<dependencies>
    <dependency>
        <groupId>io.github.smfdrummer</groupId>
        <artifactId>medal-core</artifactId>
        <version>latest.version</version>
    </dependency>
</dependencies>

Including latest.version is the latest version number,you can find it in Maven Central


Usage

For more information, please visit: Wiki learn how to use it


License

Medal-core is released under the AGPL 3.0 license

Unless commercially licensed, the code needs to be open source in any way you modify or use it

Only projects for personal use and open source can use this library, otherwise there will be a fee

Please comply with the license regulations and do not violate the license regulations, otherwise you will be held legally responsible


Acknowledgment

Thank you for using Medal-core, and if you have any questions or suggestions, please take Issues

Projects cite the following open source projects (in no particular order):


Sponsored

If you like Medal-core and want to support the development of the project, you can sponsor in the following ways: AiFaDian


This project uses Intellij IDEA to build and publish

If you like this project, please give a star ⭐️. Thank you for your support

About

A core library for Medal project.

Resources

License

Stars

Watchers

Forks

Languages