This repository has been archived by the owner on Jul 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from suitetecsa/feature/add-new-portal-nauta-su…
…pport Feature/add new portal nauta support
- Loading branch information
Showing
32 changed files
with
920 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
39
src/main/kotlin/io/github/suitetecsa/sdk/nauta/PortalClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
59
src/main/kotlin/io/github/suitetecsa/sdk/nauta/model/Client.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/kotlin/io/github/suitetecsa/sdk/nauta/model/FixedTelephony.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/kotlin/io/github/suitetecsa/sdk/nauta/model/FixedTelephonyLists.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/io/github/suitetecsa/sdk/nauta/model/FixedTelephonyProfile.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
54
src/main/kotlin/io/github/suitetecsa/sdk/nauta/model/Lists.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/kotlin/io/github/suitetecsa/sdk/nauta/model/MailProfile.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
64 changes: 64 additions & 0 deletions
64
src/main/kotlin/io/github/suitetecsa/sdk/nauta/model/MailService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/kotlin/io/github/suitetecsa/sdk/nauta/model/MobileBonus.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
Oops, something went wrong.