Skip to content

Instantly share code, notes, and snippets.

View stefanozanella's full-sized avatar

Stefano Zanella stefanozanella

View GitHub Profile
@stefanozanella
stefanozanella / example.kt
Created August 13, 2023 15:42
Kotlin grass missing field parsing error
import com.github.doyaaaaaken.kotlincsv.dsl.csvReader
import io.blackmo18.kotlin.grass.dsl.grass
val csv = """
firstName,lastName,email
John,Doe,john.doe@gmail.com
""".trimIndent()
data class Contact(
val firstName: String?,
@Bean
fun authorizedClientManager(
clientRegistrationRepository: ClientRegistrationRepository,
authorizedClientService: OAuth2AuthorizedClientService,
) =
AuthorizedClientServiceOAuth2AuthorizedClientManager(
clientRegistrationRepository,
authorizedClientService,
).apply {
setAuthorizedClientProvider(
@Bean
fun authorizedClientManager(
clientRegistrationRepository: ClientRegistrationRepository,
authorizedClientService: OAuth2AuthorizedClientService,
) =
AuthorizedClientServiceOAuth2AuthorizedClientManager(
clientRegistrationRepository,
authorizedClientService,
).apply {
setAuthorizedClientProvider(
@Bean
fun webClient(authorizedClientManager: OAuth2AuthorizedClientManager): WebClient =
WebClient
.builder()
.apply(
ServletOAuth2AuthorizedClientExchangeFilterFunction(
authorizedClientManager
).oauth2Configuration()
)
.build()
client
// ...
.attributes(
ServerOAuth2AuthorizedClientExchangeFilterFunction
.oauth2AuthorizedClient(
authorizedClientService.loadAuthorizedClient("hubspot", event["portalId"])
)
)
.retrieve()
.bodyToMono<String>()
dependencies {
// ...
implementation("org.springframework.boot:spring-boot-starter-jdbc")
implementation("org.flywaydb:flyway-core") // Optional, but highly recommended
implementation("org.postgresql:postgresql") // Add the driver for your favourite database here
}
@RestController
class WebhooksController {
// ...
@Autowired
private lateinit var authorizedClientService: OAuth2AuthorizedClientService
@PostMapping("/webhooks/hubspot")
fun hubspot(@RequestBody events: List<Map<String, String>>) {
events
@RestController
class WebhooksController {
@Autowired
private lateinit var client: WebClient
@PostMapping("/webhooks/hubspot")
fun hubspot(@RequestBody events: List<Map<String, String>>) {
events
.map { event ->
client
dependencies {
// ...
implementation("org.springframework.boot:spring-boot-starter-webflux")
// ...
}
@Bean
fun oauth2Configuration(http: HttpSecurity): SecurityFilterChain =
http
.oauth2Client()
// ...
.and().and()
.csrf().disable()
.build()