Skip to content

Commit

Permalink
Merge branch 'feature/attachments'
Browse files Browse the repository at this point in the history
  • Loading branch information
BoD committed Jun 12, 2021
2 parents a031f3e + f161159 commit 408b003
Show file tree
Hide file tree
Showing 28 changed files with 625 additions and 342 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## 2.5.0 (2021-05-23)
## 2.5.0 (2021-06-12)

- Support for Attachment APIs

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ repositories {
```groovy
dependencies {
/* ... */
implementation 'org.jraf:klibqonto:2.4.0'
implementation 'org.jraf:klibqonto:2.5.0'
}
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ allprojects {
}

group = "org.jraf"
version = "2.4.0"
version = "2.5.0"

// Show a report in the log when running tests
tasks.withType<Test> {
Expand Down
8 changes: 4 additions & 4 deletions buildSrc/src/main/kotlin/Globals.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
object Versions {
// Misc and plugins
const val GRADLE = "7.0.2"
const val KOTLIN = "1.5.0"
const val BEN_MANES_VERSIONS_PLUGIN = "0.38.0"
const val KOTLIN = "1.5.10"
const val BEN_MANES_VERSIONS_PLUGIN = "0.39.0"
const val ANDROID_GRADLE_PLUGIN = "4.2.1"
const val DOKKA_PLUGIN = "1.4.32"

// Lib dependencies
const val KOTLIN_SERIALIZATION = "1.5.0"
const val KTOR = "1.5.4"
const val KOTLIN_SERIALIZATION = KOTLIN
const val KTOR = "1.6.0"
const val COROUTINES = "1.5.0"
const val SLF4J = "1.7.30"

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx4g
org.gradle.jvmargs=-Xmx4g --add-opens=java.base/java.io=ALL-UNNAMED

# Use the daemon
org.gradle.daemon=true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* This source is part of the
* _____ ___ ____
* __ / / _ \/ _ | / __/___ _______ _
* / // / , _/ __ |/ _/_/ _ \/ __/ _ `/
* \___/_/|_/_/ |_/_/ (_)___/_/ \_, /
* /___/
* repository.
*
* Copyright (C) 2021-present Benoit 'BoD' Lubek ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.jraf.klibqonto.model.attachments.file

import org.jraf.klibqonto.model.attachments.AttachmentByteInput
import java.io.File

actual class FileAttachmentByteInput actual constructor(filePath: String) : AttachmentByteInput {
private val inputStream by lazy { File(filePath).inputStream() }

override fun read(byteArray: ByteArray): Int {
return inputStream.read(byteArray, 0, byteArray.size)
}

override fun close() {
inputStream.close()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ package org.jraf.klibqonto.client

import org.jraf.klibqonto.internal.client.QontoClientImpl
import org.jraf.klibqonto.model.attachments.Attachment
import org.jraf.klibqonto.model.attachments.AttachmentByteInput
import org.jraf.klibqonto.model.attachments.AttachmentType
import org.jraf.klibqonto.model.dates.DateRange
import org.jraf.klibqonto.model.labels.Label
import org.jraf.klibqonto.model.memberships.Membership
Expand Down Expand Up @@ -54,11 +56,7 @@ interface QontoClient {
*/
fun getLoginUri(
oAuthCredentials: OAuthCredentials,
scopes: List<OAuthScope> = listOf(
OAuthScope.OFFLINE_ACCESS,
OAuthScope.ORGANIZATION_READ,
OAuthScope.OPENID,
),
scopes: List<OAuthScope> = OAuthScope.values().toList(),
uniqueState: String,
): String

Expand Down Expand Up @@ -240,6 +238,38 @@ interface QontoClient {
* See also [the API documentation](https://api-doc.qonto.com/docs/business-api/reference/openapi_v2.yml/paths/~1v2~1transactions~1%7Btransaction_id%7D~1attachments/get)
*/
suspend fun getAttachmentList(transactionInternalId: String): List<Attachment>

/**
* Add an attachment to a transaction.
*
* @param transactionInternalId The internal id of the Transaction - e.g. `4c306508-dac9-410b-9937-e87b02462e42`
* @param type The image type of the attachment (currently only png, jpeg, and pdf are supported)
* @param input The byte data of the attachment.
*
* Note: the given input won't be closed by this method.
*
* See also [the API documentation](https://api-doc.qonto.com/docs/business-api/reference/openapi_v2.yml/paths/~1v2~1transactions~1%7Btransaction_id%7D~1attachments/post)
*/
suspend fun addAttachment(transactionInternalId: String, type: AttachmentType, input: AttachmentByteInput)

/**
* Remove an attachment from a transaction
*
* @param transactionInternalId The internal id of the Transaction - e.g. `4c306508-dac9-410b-9937-e87b02462e42`
* @param attachmentId The id of the attachment to remove - e.g. `4c306508-dac9-410b-9937-e87b02462e42`
*
* See also [the API documentation](https://api-doc.qonto.com/docs/business-api/reference/openapi_v2.yml/paths/~1v2~1transactions~1%7Btransaction_id%7D~1attachments~1%7Bid%7D/delete)
*/
suspend fun removeAttachment(transactionInternalId: String, attachmentId: String)

/**
* Remove all attachments from a transaction.
*
* @param transactionInternalId The internal id of the Transaction - e.g. `4c306508-dac9-410b-9937-e87b02462e42`
*
* See also [the API documentation](https://api-doc.qonto.com/docs/business-api/reference/openapi_v2.yml/paths/~1v2~1transactions~1%7Btransaction_id%7D~1attachments/delete)
*/
suspend fun removeAllAttachments(transactionInternalId: String)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ package org.jraf.klibqonto.client.blocking
import org.jraf.klibqonto.client.QontoClient
import org.jraf.klibqonto.internal.client.blocking.BlockingQontoClientImpl
import org.jraf.klibqonto.model.attachments.Attachment
import org.jraf.klibqonto.model.attachments.AttachmentByteInput
import org.jraf.klibqonto.model.attachments.AttachmentType
import org.jraf.klibqonto.model.dates.DateRange
import org.jraf.klibqonto.model.labels.Label
import org.jraf.klibqonto.model.memberships.Membership
Expand Down Expand Up @@ -61,11 +63,7 @@ interface BlockingQontoClient {
*/
fun getLoginUri(
oAuthCredentials: OAuthCredentials,
scopes: List<OAuthScope> = listOf(
OAuthScope.OFFLINE_ACCESS,
OAuthScope.ORGANIZATION_READ,
OAuthScope.OPENID,
),
scopes: List<OAuthScope> = OAuthScope.values().toList(),
uniqueState: String,
): String

Expand Down Expand Up @@ -158,6 +156,21 @@ interface BlockingQontoClient {
* See [QontoClient.Attachments.getAttachmentList].
*/
fun getAttachmentList(transactionInternalId: String): List<Attachment>

/**
* See [QontoClient.Attachments.addAttachment].
*/
fun addAttachment(transactionInternalId: String, type: AttachmentType, input: AttachmentByteInput)

/**
* See [QontoClient.Attachments.removeAttachment].
*/
fun removeAttachment(transactionInternalId: String, attachmentId: String)

/**
* See [QontoClient.Attachments.removeAllAttachments].
*/
fun removeAllAttachments(transactionInternalId: String)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ package org.jraf.klibqonto.client.callback
import org.jraf.klibqonto.client.QontoClient
import org.jraf.klibqonto.internal.client.callback.CallbackQontoClientImpl
import org.jraf.klibqonto.model.attachments.Attachment
import org.jraf.klibqonto.model.attachments.AttachmentByteInput
import org.jraf.klibqonto.model.attachments.AttachmentType
import org.jraf.klibqonto.model.dates.DateRange
import org.jraf.klibqonto.model.labels.Label
import org.jraf.klibqonto.model.memberships.Membership
Expand Down Expand Up @@ -62,11 +64,7 @@ interface CallbackQontoClient {
*/
fun getLoginUri(
oAuthCredentials: OAuthCredentials,
scopes: List<OAuthScope> = listOf(
OAuthScope.OFFLINE_ACCESS,
OAuthScope.ORGANIZATION_READ,
OAuthScope.OPENID,
),
scopes: List<OAuthScope> = OAuthScope.values().toList(),
uniqueState: String,
): String

Expand Down Expand Up @@ -172,6 +170,26 @@ interface CallbackQontoClient {
transactionInternalId: String,
onResult: (Result<List<Attachment>>) -> Unit,
)

/**
* See [QontoClient.Attachments.addAttachment].
*/
fun addAttachment(
transactionInternalId: String,
type: AttachmentType,
input: AttachmentByteInput,
onResult: (Result<Unit>) -> Unit,
)

/**
* See [QontoClient.Attachments.removeAttachment].
*/
fun removeAttachment(transactionInternalId: String, attachmentId: String, onResult: (Result<Unit>) -> Unit)

/**
* See [QontoClient.Attachments.removeAllAttachments].
*/
fun removeAllAttachments(transactionInternalId: String, onResult: (Result<Unit>) -> Unit)
}


Expand Down
Loading

0 comments on commit 408b003

Please sign in to comment.