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

commonMain.io.revenuemonster.sdk.module.MemberModule.kt Maven / Gradle / Ivy

There is a newer version: 2.2.0
Show newest version
package io.revenuemonster.sdk.module

import io.ktor.http.*
import io.revenuemonster.sdk.RevenueMonsterSDK
import io.revenuemonster.sdk.model.Item
import io.revenuemonster.sdk.model.Items
import io.revenuemonster.sdk.model.Response
import io.revenuemonster.sdk.model.common.MemberProfile
import io.revenuemonster.sdk.model.request.RegisterMemberRequest
import io.revenuemonster.sdk.model.response.CheckMemberResponse
import io.revenuemonster.sdk.model.response.Reward
import io.revenuemonster.sdk.model.response.Voucher
import kotlinx.serialization.json.JsonNull

class MemberModule(private val sdk: RevenueMonsterSDK) {

    // member
    suspend fun registerLoyaltyMember(data: RegisterMemberRequest): Item {
        return sdk.call(
            url = "/v3/loyalty/member",
            method = HttpMethod.Post,
            body = data
        )
    }

    suspend fun checkLoyaltyMember(
        countryCode: String,
        phoneNumber: String
    ): Item {
        return sdk.call(
            url = "/v3/loyalty/member/check",
            method = HttpMethod.Post,
            body = mapOf(
                "countryCode" to countryCode,
                "phoneNumber" to phoneNumber
            )
        )
    }

    suspend fun getMemberProfile(
        countryCode: String,
        phoneNumber: String
    ): Item {
        return sdk.call>(
            url = "/v3/loyalty/me?countryCode=$countryCode&phoneNumber=$phoneNumber"
        )
    }

    // member -> vouchers
    suspend fun getVouchers(
        countryCode: String,
        phoneNumber: String
    ): Items {
        return sdk.call>(
            url = "/v3/loyalty/me/vouchers?countryCode=$countryCode&phoneNumber=$phoneNumber"
        )
    }

    suspend fun getVoucherByCode(
        code: String,
        countryCode: String,
        phoneNumber: String
    ): Item {
        return sdk.call>(
            url = "/v3/loyalty/me/voucher/$code?countryCode=$countryCode&phoneNumber=$phoneNumber"
        )
    }

    suspend fun redeemVoucher(
        code: String,
        countryCode: String,
        phoneNumber: String
    ): Item {
        return sdk.call>(
            url = "/v3/loyalty/me/voucher/$code/redeem?countryCode=$countryCode&phoneNumber=$phoneNumber",
            method = HttpMethod.Post
        )
    }

    // member -> rewards
    suspend fun getRewards(
        countryCode: String,
        phoneNumber: String
    ): Items {
        return sdk.call>(
            url = "/v3/loyalty/me/rewards?countryCode=$countryCode&phoneNumber=$phoneNumber"
        )
    }

    suspend fun getRewardByID(
        rewardId: String,
        countryCode: String,
        phoneNumber: String
    ): Item {
        return sdk.call>(
            url = "/v3/loyalty/me/reward/$rewardId?countryCode=$countryCode&phoneNumber=$phoneNumber"
        )
    }

    suspend fun redeemReward(
        rewardId: String,
        countryCode: String,
        phoneNumber: String
    ): Response {
        return sdk.call(
            url = "/v3/loyalty/me/reward/$rewardId/redeem?countryCode=$countryCode&phoneNumber=$phoneNumber",
            method = HttpMethod.Post
        )
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy