-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Upgrade Gradle from 7.2 to 7.6 * Light implementation of deals API * Changed package version to 1.3.0
- Loading branch information
Jiří Svěcený
authored
Apr 14, 2023
1 parent
5220786
commit fca34d1
Showing
8 changed files
with
118 additions
and
3 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
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
13 changes: 13 additions & 0 deletions
13
hubspot/src/main/kotlin/org/boomevents/hubspot/domain/deals/Deal.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,13 @@ | ||
package org.boomevents.hubspot.domain.deals | ||
|
||
import org.boomevents.hubspot.domain.DataEntity | ||
import java.math.BigInteger | ||
import java.time.LocalDateTime | ||
|
||
class Deal( | ||
override val id: BigInteger, | ||
override val properties: Map<String, Any>, | ||
override val createdAt: LocalDateTime, | ||
override val updatedAt: LocalDateTime, | ||
override val archived: Boolean | ||
) : DataEntity |
81 changes: 81 additions & 0 deletions
81
hubspot/src/main/kotlin/org/boomevents/hubspot/domain/deals/DealClient.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,81 @@ | ||
package org.boomevents.hubspot.domain.deals | ||
|
||
import org.boomevents.hubspot.model.http.RequestMethod | ||
import org.boomevents.hubspot.model.http.Requester | ||
import org.boomevents.hubspot.Client | ||
import org.boomevents.hubspot.ClientRequestCatalog | ||
import org.boomevents.hubspot.domain.deals.exceptions.DealsNotFoundException | ||
import org.boomevents.hubspot.model.http.exceptions.HttpRequestException | ||
import org.boomevents.hubspot.model.mapper.Mapper | ||
import java.math.BigInteger | ||
|
||
class DealClient(private val hubSpotClient: Client) { | ||
|
||
fun <P> createDeal(request: DealRequest<P>): Deal { | ||
val response = Requester.requestJson(hubSpotClient, RequestMethod.POST, ClientRequestCatalog.V3.DEALS, emptyMap(), request) | ||
|
||
if (response.isSuccess) { | ||
return Mapper.mapToObject(response.body) | ||
} else { | ||
throw RuntimeException(response.statusText) | ||
} | ||
} | ||
|
||
|
||
@Throws( | ||
DealsNotFoundException::class, | ||
HttpRequestException::class | ||
) | ||
fun findDeal(dealId: BigInteger): Deal { | ||
val requestUrl = ClientRequestCatalog.V3.DEALS_DETAIL.replace( | ||
"{dealId}", dealId.toString() | ||
) | ||
|
||
val response = Requester.requestJson(hubSpotClient, RequestMethod.GET, requestUrl) | ||
|
||
if (response.isSuccess) { | ||
return Mapper.mapToObject(response.body) | ||
} else { | ||
when (response.status) { | ||
404 -> throw DealsNotFoundException(dealId) | ||
else -> throw HttpRequestException(response.status, response.statusText) | ||
} | ||
} | ||
} | ||
|
||
|
||
fun <P> changeDeal(dealId: BigInteger, request: DealRequest<P>): Deal { | ||
val requestUrl = ClientRequestCatalog.V3.DEALS_DETAIL.replace( | ||
"{dealId}", dealId.toString() | ||
) | ||
|
||
val response = Requester.requestJson(hubSpotClient, RequestMethod.PATCH, requestUrl, emptyMap(), request) | ||
|
||
if (response.isSuccess) { | ||
return Mapper.mapToObject(response.body) | ||
} else { | ||
when (response.status) { | ||
404 -> throw DealsNotFoundException(dealId) | ||
else -> throw HttpRequestException(response.status, response.statusText) | ||
} | ||
} | ||
} | ||
|
||
@Throws( | ||
HttpRequestException::class | ||
) | ||
fun removeDeal(dealId: BigInteger) { | ||
val requestUrl = ClientRequestCatalog.V3.DEALS_DETAIL.replace( | ||
"{dealId}", dealId.toString() | ||
) | ||
|
||
// Unknown deal returns HTTP code 204 | ||
val response = Requester.requestVoid(hubSpotClient, RequestMethod.DELETE, requestUrl) | ||
|
||
if (!response.isSuccess) { | ||
when (response.status) { | ||
else -> throw HttpRequestException(response.status, response.statusText) | ||
} | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
hubspot/src/main/kotlin/org/boomevents/hubspot/domain/deals/DealRequest.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,5 @@ | ||
package org.boomevents.hubspot.domain.deals | ||
|
||
data class DealRequest<P>( | ||
val properties: P | ||
) |
5 changes: 5 additions & 0 deletions
5
hubspot/src/main/kotlin/org/boomevents/hubspot/domain/deals/exceptions/DealException.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,5 @@ | ||
package org.boomevents.hubspot.domain.deals.exceptions | ||
|
||
import org.boomevents.hubspot.exceptions.HubSpotException | ||
|
||
abstract class DealException(override val message: String) : HubSpotException(message) |
8 changes: 8 additions & 0 deletions
8
.../src/main/kotlin/org/boomevents/hubspot/domain/deals/exceptions/DealsNotFoundException.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,8 @@ | ||
package org.boomevents.hubspot.domain.deals.exceptions | ||
|
||
import java.math.BigInteger | ||
|
||
class DealsNotFoundException( | ||
dealId: BigInteger, | ||
override val message: String = "Deals '$dealId' was not found." | ||
) : DealException(message) |