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 #11 from suitetecsa/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
lesclaz authored May 30, 2023
2 parents aca6d0c + 3611c8f commit 8d8dbaa
Show file tree
Hide file tree
Showing 16 changed files with 134 additions and 153 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ Importal `NautaSession`, `JsoupConnectPortalCommunicator`, `JsoupConnectPortalSc
import cu.suitetecsa.sdk.nauta.framework.network.JsoupConnectPortalCommunicator
import cu.suitetecsa.sdk.nauta.framework.network.JsoupUserPortalCommunicator
import cu.suitetecsa.sdk.nauta.framework.network.DefaultNautaSession
import cu.suitetecsa.sdk.nauta.framekork.JsoupConnectPortalScraper
import cu.suitetecsa.sdk.nauta.framekork.JsoupUserPortalScrapper
import cu.suitetecsa.sdk.nauta.framekork.NautaApi
import cu.suitetecsa.sdk.nauta.framework.JsoupConnectPortalScraper
import cu.suitetecsa.sdk.nauta.framework.JsoupUserPortalScrapper
import cu.suitetecsa.sdk.nauta.framework.NautaApi
```

Crea las instancias necesarias o inyectalas
Expand Down
7 changes: 6 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = "cu.suitetecsa"
version = "0.2-alpha01"
version = "0.2-alpha02"

publishing {
publications { // Configure el paquete de salida publicado, un proyecto puede tener múltiples salidas, pero solo una es
Expand Down Expand Up @@ -34,6 +34,8 @@ dependencies {
testImplementation(kotlin("test"))
testImplementation("io.mockk:mockk:1.13.4")
testImplementation("com.google.code.gson:gson:2.10.1")
implementation(kotlin("stdlib-jdk8"))
testImplementation("junit:junit:4.13.1")
}

tasks.test {
Expand All @@ -43,3 +45,6 @@ tasks.test {
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
kotlin {
jvmToolchain(11)
}
57 changes: 55 additions & 2 deletions src/main/kotlin/cu/suitetecsa/sdk/nauta/core/ExtendsFuns.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ import org.jsoup.Jsoup
import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import org.jsoup.select.Elements
import java.text.NumberFormat
import java.text.ParseException
import java.text.SimpleDateFormat
import java.time.LocalTime
import java.time.format.DateTimeFormatter
import java.time.temporal.ChronoUnit
import java.util.*

internal fun Connection.Response.throwExceptionOnFailure(exc: Class<out Exception>, msg: String) {
val exceptionConstructor = exc.getDeclaredConstructor(String::class.java)
Expand Down Expand Up @@ -55,5 +62,51 @@ internal operator fun Elements.component6(): Element {
return this[5]
}

fun String.toSeconds() =
this.split(":").map { it.toInt() }.fold(0) { acc, value -> acc * 60 + value }.toLong()
fun String.toSeconds() = this.split(":").fold(0L) { acc, s -> acc * 60 + s.toLong() }

fun Long.toTimeString() = String.format("%02d:%02d:%02d", this / 3600, this % 3600 / 60, this % 60)

fun String.toDate(): Date = SimpleDateFormat("dd/MM/yyyy", Locale.getDefault()).apply { isLenient = false }.parse(this)

fun Date.toDateString(): String = SimpleDateFormat("dd/MM/yyyy", Locale.getDefault()).format(this)

fun String.toDateTime(): Date = try {
SimpleDateFormat("dd/MM/yyyy HH:mm:ss", Locale.getDefault()).parse(this)
} catch (e: Exception) {
Date(0)
}

fun Date.toDateTimeString(): String = SimpleDateFormat("dd/MM/yyyy HH:mm:ss", Locale.getDefault()).format(this)

fun String.toBytes(): Double {
val sizeUnit = this.split(" ").last()
val sizeValue = this.replace(" $sizeUnit", "").replace(" ", "")
return sizeValue.replace(",", ".").toDouble() * when (sizeUnit.uppercase(Locale.getDefault())) {
"KB" -> 1024
"MB" -> 1024 * 1024
"GB" -> 1024 * 1024 * 1024
else -> throw IllegalArgumentException("La unidad de tamaño no es válida")
}.toLong()
}

fun Long.toSizeString(): String {
val sizeUnits = arrayOf("bytes", "KB", "MB", "GB", "TB")
var sizeValue = this.toDouble()
var sizeUnitIndex = 0
while (sizeValue >= 1024 && sizeUnitIndex < sizeUnits.lastIndex) {
sizeValue /= 1024
sizeUnitIndex++
}
return "%.2f %s".format(sizeValue).replace(".", ",") + " " + sizeUnits[sizeUnitIndex]
}

fun String.toPriceFloat(): Float = this
.replace("$", "")
.replace(",", ".")
.replace(" CUP", "")
.replace(" ", "")
.toFloatOrNull() ?: throw IllegalArgumentException("El formato de la cadena no es correcto")

fun Float.toPriceString(): String = NumberFormat
.getCurrencyInstance(Locale.US)
.format(this)
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import java.util.Date
data class Connection(
val startSession: Date,
val endSession: Date,
val duration: Int,
val duration: Long,
val uploaded: Double,
val downloaded: Double,
val import: Float
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cu.suitetecsa.sdk.nauta.domain.model
data class ConnectionsSummary(
val count: Int,
val yearMonthSelected: String,
val totalTime: Int,
val totalTime: Long,
val totalImport: Float,
val uploaded: Double,
val downloaded: Double,
Expand Down
17 changes: 0 additions & 17 deletions src/main/kotlin/cu/suitetecsa/sdk/nauta/domain/util/PriceUtils.kt

This file was deleted.

25 changes: 0 additions & 25 deletions src/main/kotlin/cu/suitetecsa/sdk/nauta/domain/util/SizeUtils.kt

This file was deleted.

64 changes: 29 additions & 35 deletions src/main/kotlin/cu/suitetecsa/sdk/nauta/domain/util/StringUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,38 @@ package cu.suitetecsa.sdk.nauta.domain.util
import java.security.SecureRandom

/**
* Clase que genera contraseñas aleatorias de alta calidad.
* Genera una contraseña aleatoria de alta calidad.
*
* @param length La longitud de la contraseña a generar.
* @param includeLowercase Indica si se deben incluir letras minúsculas en la contraseña.
* @param includeUppercase Indica si se deben incluir letras mayúsculas en la contraseña.
* @param includeNumbers Indica si se deben incluir números en la contraseña.
* @param includeSymbols Indica si se deben incluir símbolos en la contraseña.
*
* @return La contraseña generada.
*/
class PasswordGenerator {
fun generatePassword(
length: Int,
includeLowercase: Boolean = true,
includeUppercase: Boolean = true,
includeNumbers: Boolean = true,
includeSymbols: Boolean = true
): String {
val random = SecureRandom()
val characters = mutableListOf<Char>()

/**
* Genera una contraseña aleatoria de alta calidad.
*
* @param length La longitud de la contraseña a generar.
* @param includeLowercase Indica si se deben incluir letras minúsculas en la contraseña.
* @param includeUppercase Indica si se deben incluir letras mayúsculas en la contraseña.
* @param includeNumbers Indica si se deben incluir números en la contraseña.
* @param includeSymbols Indica si se deben incluir símbolos en la contraseña.
*
* @return La contraseña generada.
*/
fun generatePassword(
length: Int,
includeLowercase: Boolean = true,
includeUppercase: Boolean = true,
includeNumbers: Boolean = true,
includeSymbols: Boolean = true
): String {
val random = SecureRandom()
val characters = mutableListOf<Char>()
// Agregar caracteres según las opciones de configuración
if (includeLowercase) characters.addAll(('a'..'z'))
if (includeUppercase) characters.addAll(('A'..'Z'))
if (includeNumbers)characters.addAll(('0'..'9'))
if (includeSymbols) characters.addAll("!@#\$%^&*()_-+={}[]\\|:;\"'<>,.?/".toList())

// Agregar caracteres según las opciones de configuración
if (includeLowercase) characters.addAll(('a'..'z'))
if (includeUppercase) characters.addAll(('A'..'Z'))
if (includeNumbers) characters.addAll(('0'..'9'))
if (includeSymbols) characters.addAll("!@#\$%^&*()_-+={}[]\\|:;\"'<>,.?/".toList())

// Generar la contraseña aleatoria
val password = buildString {
repeat(length) {
append(characters[random.nextInt(characters.size)])
}
// Generar la contraseña aleatoria
val password = buildString {
repeat(length) {
append(characters[random.nextInt(characters.size)])
}

return password
}

return password
}
23 changes: 0 additions & 23 deletions src/main/kotlin/cu/suitetecsa/sdk/nauta/domain/util/TimeUtils.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cu.suitetecsa.sdk.nauta.framekork
package cu.suitetecsa.sdk.nauta.framework

import cu.suitetecsa.sdk.nauta.framework.model.NautaConnectInformation
import cu.suitetecsa.sdk.nauta.framework.model.ResultType
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package cu.suitetecsa.sdk.nauta.framekork
package cu.suitetecsa.sdk.nauta.framework

import cu.suitetecsa.sdk.nauta.core.*
import cu.suitetecsa.sdk.nauta.core.connectDomain
import cu.suitetecsa.sdk.nauta.core.connectPortal
import cu.suitetecsa.sdk.nauta.core.throwExceptionOnFailure
import cu.suitetecsa.sdk.nauta.core.toSeconds
import cu.suitetecsa.sdk.nauta.framework.model.AccountInfo
import cu.suitetecsa.sdk.nauta.framework.model.LastConnection
import cu.suitetecsa.sdk.nauta.framework.model.NautaConnectInformation
Expand Down
Loading

0 comments on commit 8d8dbaa

Please sign in to comment.