Skip to content
This repository has been archived by the owner on Jul 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #4 from suitetecsa/feature/add-new-portal-nauta-su…
Browse files Browse the repository at this point in the history
…pport

Feature/add new portal nauta support
  • Loading branch information
lesclaz authored Feb 25, 2024
2 parents a35168a + dbb9d59 commit f322bb5
Show file tree
Hide file tree
Showing 32 changed files with 920 additions and 2 deletions.
14 changes: 13 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
plugins {
kotlin("jvm") version "1.9.22"
id("cl.franciscosolis.sonatype-central-upload") version "1.0.0"
id("com.google.devtools.ksp").version("1.9.22-1.0.17")
}

group = "io.github.suitetecsa.sdk"
version = "0.1.3"
version = "0.1.4-alpha01"

repositories {
mavenCentral()
Expand All @@ -15,6 +16,17 @@ dependencies {
testImplementation("org.mockito:mockito-core:3.12.4")
testImplementation("junit:junit:4.13.1")
implementation("org.jsoup:jsoup:1.17.2")
implementation("com.squareup.retrofit2:retrofit:2.9.0")
implementation("com.squareup.retrofit2:converter-moshi:2.9.0")
implementation("com.squareup.moshi:moshi-kotlin:1.15.1")
// Adaptador de Coroutines para Retrofit
implementation("com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2")
// Adaptador RxJava para Retrofit
implementation("com.squareup.retrofit2:adapter-rxjava3:2.9.0")

implementation("com.auth0:java-jwt:3.18.2")

ksp("com.squareup.moshi:moshi-kotlin-codegen:1.15.0")
}

tasks.test {
Expand Down
8 changes: 7 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
pluginManagement {
repositories {
mavenCentral()
gradlePluginPortal()
}
}

plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
}
rootProject.name = "nauta-connect"

39 changes: 39 additions & 0 deletions src/main/kotlin/io/github/suitetecsa/sdk/nauta/PortalClient.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.github.suitetecsa.sdk.nauta

import com.squareup.moshi.Moshi
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import io.github.suitetecsa.sdk.nauta.model.login.LoginResponse
import io.github.suitetecsa.sdk.nauta.model.login.LoginResponseAdapter
import io.github.suitetecsa.sdk.nauta.model.users.UsersResponse
import io.github.suitetecsa.sdk.nauta.model.users.UsersResponseAdapter
import io.github.suitetecsa.sdk.nauta.network.PortalAuthService
import io.github.suitetecsa.sdk.nauta.network.RxPortalAuthService
import retrofit2.Retrofit
import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory
import retrofit2.converter.moshi.MoshiConverterFactory

object PortalClient {
private val moshi = Moshi.Builder()
.add(LoginResponse::class.java, LoginResponseAdapter())
.add(UsersResponse::class.java, UsersResponseAdapter())
.addLast(KotlinJsonAdapterFactory())
.build()
private val retrofit = Retrofit.Builder()
.baseUrl("https://www.nauta.cu:5002")
.addConverterFactory(MoshiConverterFactory.create(moshi))
.build()
private val retrofitRX = Retrofit.Builder()
.baseUrl("https://www.nauta.cu:5002")
.addConverterFactory(MoshiConverterFactory.create(moshi))
.addCallAdapterFactory(RxJava3CallAdapterFactory.create())
.build()

val portalAuthService: PortalAuthService by lazy {
retrofit.create(PortalAuthService::class.java)
}

@JvmStatic
val portalAuthServiceRX: RxPortalAuthService by lazy {
retrofitRX.create(RxPortalAuthService::class.java)
}
}
59 changes: 59 additions & 0 deletions src/main/kotlin/io/github/suitetecsa/sdk/nauta/model/Client.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package io.github.suitetecsa.sdk.nauta.model

import com.squareup.moshi.*

data class Client(
val email: String,
val name: String,
val mailNotifications: String,
val mobileNotifications: String,
val operations: List<Operation>,
val phoneNumber: String,
val portalUser: String,
)

class ClientAdapter : JsonAdapter<Client>() {
private val options: JsonReader.Options = JsonReader.Options.of("email", "nombre", "notificaciones_mail", "notificaciones_movil", "operaciones", "telefono", "usuario_portal")
private val moshi: Moshi = Moshi.Builder()
.add(Operation::class.java, OperationAdapter())
.build()
private val operationAdapter: JsonAdapter<Operation> = moshi.adapter(Operation::class.java)

override fun fromJson(reader: JsonReader): Client {
var email: String? = null
var name: String? = null
var mailNotifications: String? = null
var mobileNotifications: String? = null
val operations = mutableListOf<Operation>()
var phoneNumber: String? = null
var portalUser: String? = null

reader.beginObject()
while (reader.hasNext()) {
when (reader.selectName(options)) {
0 -> email = reader.nextString()
1 -> name = reader.nextString()
2 -> mailNotifications = reader.nextString()
3 -> mobileNotifications = reader.nextString()
4 -> {
reader.beginObject()
while (reader.hasNext()) {
reader.skipName()
val operation = operationAdapter.fromJson(reader)
operation?.let { operations.add(it) }
}
reader.endObject()
}
5 -> phoneNumber = reader.nextString()
6 -> portalUser = reader.nextString()
else -> reader.skipValue()
}
}
reader.endObject()
return Client(email!!, name!!, mailNotifications!!, mobileNotifications!!, operations, phoneNumber!!, portalUser!!)
}

override fun toJson(p0: JsonWriter, p1: Client?) {
throw UnsupportedOperationException("toJson not supported")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package io.github.suitetecsa.sdk.nauta.model

import com.squareup.moshi.*

data class FixedTelephony(
val operations: List<Operation>,
val profile: FixedTelephonyProfile,
)

class FixedTelephonyAdapter : JsonAdapter<FixedTelephony>() {
private val options: JsonReader.Options = JsonReader.Options.of("operaciones", "perfil")
private val moshi: Moshi = Moshi.Builder()
.add(Operation::class.java, OperationAdapter())
.add(FixedTelephonyLists::class.java, FixedTelephonyListsAdapter())
.build()
private val operationJsonAdapter: JsonAdapter<Operation> = moshi.adapter(Operation::class.java)
private val profileJsonAdapter: JsonAdapter<FixedTelephonyProfile> = moshi.adapter(FixedTelephonyProfile::class.java)

override fun fromJson(reader: JsonReader): FixedTelephony {
val operations = mutableListOf<Operation>()
var profile: FixedTelephonyProfile? = null

reader.beginObject()
while (reader.hasNext()) {
when (reader.selectName(options)) {
0 -> {
reader.beginObject()
while (reader.hasNext()) {
reader.skipName()
val operation = operationJsonAdapter.fromJson(reader)
operation?.let { operations.add(it) }
}
reader.endObject()
}
1 -> profile = profileJsonAdapter.fromJson(reader)
else -> reader.skipName()
}
}
reader.endObject()
return FixedTelephony(operations, profile!!)
}

override fun toJson(p0: JsonWriter, p1: FixedTelephony?) {
throw UnsupportedOperationException("toJson not supported")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.github.suitetecsa.sdk.nauta.model

import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.JsonReader
import com.squareup.moshi.JsonWriter
import com.squareup.moshi.Moshi

data class FixedTelephonyLists(
val supplementaryServices: List<SupplementaryService>,
)

class FixedTelephonyListsAdapter : JsonAdapter<FixedTelephonyLists>() {
private val options: JsonReader.Options = JsonReader.Options.of("Servicios suplementarios")
private val moshi: Moshi = Moshi.Builder().build()
private val serviceJsonAdapter = moshi.adapter(SupplementaryService::class.java)
override fun fromJson(reader: JsonReader): FixedTelephonyLists {
val supplementaryServices = mutableListOf<SupplementaryService>()
reader.beginObject()
while (reader.hasNext()) {
when (reader.selectName(options)) {
0 -> {
reader.beginObject()
while (reader.hasNext()) {
reader.skipName()
val service = serviceJsonAdapter.fromJson(reader)
service?.let { supplementaryServices.add(it) }
}
reader.endObject()
}
else -> reader.skipValue()
}
}
reader.endObject()
return FixedTelephonyLists(supplementaryServices)
}

override fun toJson(p0: JsonWriter, p1: FixedTelephonyLists?) {
throw UnsupportedOperationException("toJson not supported")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.github.suitetecsa.sdk.nauta.model

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class FixedTelephonyProfile(
val id: String,
@Json(name = "Listas") val lists: FixedTelephonyLists?,
@Json(name = "Número de teléfono") val phoneNumber: String,
)
54 changes: 54 additions & 0 deletions src/main/kotlin/io/github/suitetecsa/sdk/nauta/model/Lists.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package io.github.suitetecsa.sdk.nauta.model

import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.JsonReader
import com.squareup.moshi.JsonWriter
import com.squareup.moshi.Moshi

data class Lists(
val plans: List<MobilePlan>,
val bonuses: List<MobileBonus>,
)

class ListsAdapter : JsonAdapter<Lists>() {
private val options: JsonReader.Options = JsonReader.Options.of("Planes", "Bonos")
private val moshi: Moshi = Moshi.Builder().build()
private val mobilePlanAdapter: JsonAdapter<MobilePlan> = moshi.adapter(MobilePlan::class.java)
private val mobileBonusAdapter: JsonAdapter<MobileBonus> = moshi.adapter(MobileBonus::class.java)
override fun fromJson(reader: JsonReader): Lists {
val plans = mutableListOf<MobilePlan>()
val bonuses = mutableListOf<MobileBonus>()

reader.beginObject()
while (reader.hasNext()) {
when (reader.selectName(options)) {
0 -> {
reader.beginObject()
while (reader.hasNext()) {
reader.skipName()
val plan = mobilePlanAdapter.fromJson(reader)
plan?.let { plans.add(it) }
}
reader.endObject()
}

1 -> {
reader.beginObject()
while (reader.hasNext()) {
reader.skipName()
val bonus = mobileBonusAdapter.fromJson(reader)
bonus?.let { bonuses.add(it) }
}
reader.endObject()
}
else -> reader.skipValue()
}
}
reader.endObject()
return Lists(plans, bonuses)
}

override fun toJson(p0: JsonWriter, p1: Lists?) {
throw UnsupportedOperationException("toJson not supported")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.github.suitetecsa.sdk.nauta.model

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class MailProfile(
val id: String,
@Json(name = "Cuenta de correo") val emailAccount: String,
@Json(name = "Fecha de venta") val saleDate: String,
@Json(name = "Moneda") val currency: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package io.github.suitetecsa.sdk.nauta.model

import com.squareup.moshi.*

data class MailService(
@Json(name = "operaciones") val operations: List<Operation>,
@Json(name = "perfil") val profile: MailProfile,
@Json(name = "tipoProducto") val productType: String
)

class MailServiceAdapter : JsonAdapter<MailService>() {
private val options: JsonReader.Options = JsonReader.Options.of("operaciones", "perfil", "tipoProducto")

// Este adaptador se utiliza para convertir cada valor del mapa de operaciones en un objeto Operation
private val moshi: Moshi = Moshi.Builder()
.add(Operation::class.java, OperationAdapter())
.build()
private val operationAdapter: JsonAdapter<Operation> = moshi.adapter(Operation::class.java)

override fun fromJson(reader: JsonReader): MailService {
var operations: List<Operation>? = null
var profile: MailProfile? = null
var productType: String? = null

reader.beginObject()
while (reader.hasNext()) {
when (reader.selectName(options)) {
0 -> { // "operaciones"
val operationsList = mutableListOf<Operation>()
reader.beginObject()
while (reader.hasNext()) {
reader.skipName() // Ignora el nombre de la clave, ya que no lo necesitamos para la lista
val operation = operationAdapter.fromJson(reader)
operation?.let { operationsList.add(it) }
}
reader.endObject()
operations = operationsList
}
1 -> { // "perfil"
profile = moshi.adapter(MailProfile::class.java).fromJson(reader)
}
2 -> { // "tipoProducto"
productType = reader.nextString()
}
else -> reader.skipValue()
}
}
reader.endObject()

if (operations != null && profile != null && productType != null) {
return MailService(
operations = operations,
profile = profile,
productType = productType
)
} else {
throw JsonDataException("Missing required fields")
}
}

override fun toJson(writer: JsonWriter, value: MailService?) {
throw UnsupportedOperationException("toJson not supported")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.github.suitetecsa.sdk.nauta.model

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class MobileBonus(
@Json(name = "Datos") val data: String,
@Json(name = "Fecha inicio") val startDate: String,
@Json(name = "tipo") val type: String,
@Json(name = "Vence") val expires: String,
)
Loading

0 comments on commit f322bb5

Please sign in to comment.