mirror of
https://github.com/dyrkin/luxmed-bot.git
synced 2025-12-31 10:07:21 +01:00
Added ability to change trm of existing reservation
This commit is contained in:
@@ -1,73 +0,0 @@
|
||||
|
||||
package com.lbs.api
|
||||
|
||||
import java.time.ZonedDateTime
|
||||
|
||||
import com.lbs.api.json.model._
|
||||
import scalaj.http.HttpResponse
|
||||
|
||||
import scala.concurrent.{ExecutionContext, Future}
|
||||
import scala.language.implicitConversions
|
||||
|
||||
|
||||
object LuxmedApiAsync {
|
||||
|
||||
private val syncApi = LuxmedApi
|
||||
|
||||
def login(username: String, password: String, clientId: String = "iPhone")(implicit ec: ExecutionContext): Future[LoginResponse] = {
|
||||
async(syncApi.login(username, password, clientId))
|
||||
}
|
||||
|
||||
def refreshToken(refreshToken: String, clientId: String = "iPhone")(implicit ec: ExecutionContext): Future[LoginResponse] = {
|
||||
async(syncApi.refreshToken(refreshToken, clientId))
|
||||
}
|
||||
|
||||
def reservedVisits(accessToken: String, tokenType: String, fromDate: ZonedDateTime = ZonedDateTime.now(),
|
||||
toDate: ZonedDateTime = ZonedDateTime.now().plusMonths(3))(implicit ec: ExecutionContext): Future[ReservedVisitsResponse] = {
|
||||
async(syncApi.reservedVisits(accessToken, tokenType, fromDate, toDate))
|
||||
}
|
||||
|
||||
def visitsHistory(accessToken: String, tokenType: String, fromDate: ZonedDateTime = ZonedDateTime.now().minusYears(1),
|
||||
toDate: ZonedDateTime, page: Int = 1, pageSize: Int = 100)(implicit ec: ExecutionContext): Future[VisitsHistoryResponse] = {
|
||||
async(syncApi.visitsHistory(accessToken, tokenType, fromDate, toDate, page, pageSize))
|
||||
}
|
||||
|
||||
def reservationFilter(accessToken: String, tokenType: String, fromDate: ZonedDateTime = ZonedDateTime.now(),
|
||||
toDate: Option[ZonedDateTime] = None, cityId: Option[Long] = None,
|
||||
serviceId: Option[Long] = None)(implicit ec: ExecutionContext): Future[ReservationFilterResponse] = {
|
||||
async(syncApi.reservationFilter(accessToken, tokenType, fromDate, toDate, cityId, serviceId))
|
||||
}
|
||||
|
||||
def availableTerms(accessToken: String, tokenType: String, payerId: Long, cityId: Long, clinicId: Option[Long], serviceId: Long, doctorId: Option[Long],
|
||||
fromDate: ZonedDateTime = ZonedDateTime.now(), toDate: Option[ZonedDateTime] = None, timeOfDay: Int = 0,
|
||||
languageId: Long = 10, findFirstFreeTerm: Boolean = true)(implicit ec: ExecutionContext): Future[AvailableTermsResponse] = {
|
||||
async(syncApi.availableTerms(accessToken, tokenType, cityId, payerId, clinicId, serviceId, doctorId, fromDate, toDate, timeOfDay, languageId, findFirstFreeTerm))
|
||||
}
|
||||
|
||||
def temporaryReservation(accessToken: String, tokenType: String, temporaryReservationRequest: TemporaryReservationRequest)(implicit ec: ExecutionContext): Future[TemporaryReservationResponse] = {
|
||||
async(syncApi.temporaryReservation(accessToken, tokenType, temporaryReservationRequest))
|
||||
}
|
||||
|
||||
def deleteTemporaryReservation(accessToken: String, tokenType: String, temporaryReservationId: Long)(implicit ec: ExecutionContext): Future[HttpResponse[String]] = {
|
||||
async(syncApi.deleteTemporaryReservation(accessToken, tokenType, temporaryReservationId))
|
||||
}
|
||||
|
||||
def valuations(accessToken: String, tokenType: String, valuationsRequest: ValuationsRequest)(implicit ec: ExecutionContext): Future[ValuationsResponse] = {
|
||||
async(syncApi.valuations(accessToken, tokenType, valuationsRequest))
|
||||
}
|
||||
|
||||
def reservation(accessToken: String, tokenType: String, reservationRequest: ReservationRequest)(implicit ec: ExecutionContext): Future[ReservationResponse] = {
|
||||
async(syncApi.reservation(accessToken, tokenType, reservationRequest))
|
||||
}
|
||||
|
||||
def deleteReservation(accessToken: String, tokenType: String, reservationId: Long)(implicit ec: ExecutionContext): Future[HttpResponse[String]] = {
|
||||
async(syncApi.deleteReservation(accessToken, tokenType, reservationId))
|
||||
}
|
||||
|
||||
private def async[T](f: => Either[Throwable, T])(implicit ec: ExecutionContext) = {
|
||||
Future(f).flatMap {
|
||||
case Right(r) => Future.successful(r)
|
||||
case Left(ex) => Future.failed(ex)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
package com.lbs.api.exception
|
||||
|
||||
class GenericException(code: Int, status: String, message: String) extends ApiException(message) {
|
||||
class GenericException(val code: Int, val status: String, val message: String) extends ApiException(message) {
|
||||
override def toString: String = s"Code: $code, status: $status, message: $message"
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
|
||||
package com.lbs.api.exception
|
||||
|
||||
class ServiceIsAlreadyBookedException extends ApiException("Service is already booked")
|
||||
class ServiceIsAlreadyBookedException extends ApiException("You have already booked this service")
|
||||
|
||||
@@ -56,18 +56,19 @@ package object http extends Logger {
|
||||
}
|
||||
|
||||
private def luxmedErrorToApiException[T <: LuxmedBaseError](ler: HttpResponse[T]): ApiException = {
|
||||
ler.body match {
|
||||
val genericException = ler.body match {
|
||||
case e: LuxmedCompositeError =>
|
||||
new GenericException(ler.code, ler.statusLine, e.errors.map(_.message).mkString("; "))
|
||||
case e: LuxmedError =>
|
||||
val errorMessage = e.message.toLowerCase
|
||||
if (errorMessage.contains("invalid login or password"))
|
||||
new InvalidLoginOrPasswordException
|
||||
else if (errorMessage.contains("have already booked this service"))
|
||||
new ServiceIsAlreadyBookedException
|
||||
else
|
||||
new GenericException(ler.code, ler.statusLine, e.message)
|
||||
new GenericException(ler.code, ler.statusLine, e.message)
|
||||
}
|
||||
|
||||
val errorMessage = genericException.message.toLowerCase
|
||||
if (errorMessage.contains("invalid login or password"))
|
||||
new InvalidLoginOrPasswordException
|
||||
else if (errorMessage.contains("already booked this service"))
|
||||
new ServiceIsAlreadyBookedException
|
||||
else genericException
|
||||
}
|
||||
|
||||
private def extractLuxmedError(httpResponse: Try[HttpResponse[String]]) = {
|
||||
|
||||
Reference in New Issue
Block a user