@@ -17,32 +17,115 @@ package com.vonage.client.kt
17
17
18
18
import com.vonage.client.account.*
19
19
20
+ /* *
21
+ * Implementation of the [Account API](https://developer.vonage.com/en/api/account).
22
+ *
23
+ * *Authentication method:* API key & secret.
24
+ */
20
25
class Account internal constructor(private val client : AccountClient ) {
21
26
27
+ /* *
28
+ * Obtains the current account remaining balance.
29
+ *
30
+ * @return A [BalanceResponse] object containing the current account balance.
31
+ * @throws [AccountResponseException] If the balance cannot be retrieved.
32
+ */
22
33
fun getBalance (): BalanceResponse = client.balance
23
34
35
+ /* *
36
+ * You can top up your account using this API when you have enabled auto-reload in the dashboard.
37
+ * The amount added by the top-up operation will be the same amount as was added in the payment when
38
+ * auto-reload was enabled. Your account balance is checked every 5-10 minutes and if it falls below the
39
+ * threshold and auto-reload is enabled, then it will be topped up automatically. Use this method if you
40
+ * need to top up at times when your credit may be exhausted more quickly than the auto-reload may occur.
41
+ *
42
+ * @param transactionId The top-up transaction ID.
43
+ *
44
+ * @throws [AccountResponseException] If the top-up operation fails.
45
+ */
24
46
fun topUp (transactionId : String ): Unit = client.topUp(transactionId)
25
47
48
+ /* *
49
+ * Updates the top-level account settings. Namely, the URLs for incoming SMS and delivery receipts.
50
+ *
51
+ * @param incomingSmsUrl The URL to which incoming SMS messages are sent when using SMS API.
52
+ * @param deliverReceiptUrl The URL to which delivery receipts are sent when using SMS API.
53
+ *
54
+ * @return The updated account settings.
55
+ *
56
+ * @throws [AccountResponseException] If the account settings could not be updated.
57
+ */
26
58
fun updateSettings (incomingSmsUrl : String? = null, deliverReceiptUrl : String? = null): SettingsResponse =
27
59
client.updateSettings(SettingsRequest (incomingSmsUrl, deliverReceiptUrl))
28
60
61
+ /* *
62
+ * Call this method to work with account secrets.
63
+ *
64
+ * @param apiKey (OPTIONAL) The account API key to manage secrets for. If not provided,
65
+ * the default API key (as supplied in the top-level [Vonage] client) will be used.
66
+ *
67
+ * @return A [Secrets] object with methods to interact with account secrets.
68
+ */
29
69
fun secrets (apiKey : String? = null): Secrets = Secrets (apiKey)
30
70
71
+ /* *
72
+ * Class for working with account secrets.
73
+ *
74
+ * @property apiKey The account API key to manage secrets for. If not provided,
75
+ * the default API key (as supplied in the top-level [Vonage] client) will be used.
76
+ */
31
77
inner class Secrets internal constructor(val apiKey : String? = null ) {
32
78
79
+ /* *
80
+ * Retrieves secrets for the account.
81
+ *
82
+ * @return A list of secrets details.
83
+ *
84
+ * @throws [AccountResponseException] If the secrets cannot be retrieved.
85
+ */
33
86
fun list (): List <SecretResponse > = (
34
87
if (apiKey == null ) client.listSecrets()
35
88
else client.listSecrets(apiKey)
36
89
).secrets
37
90
91
+ /* *
92
+ * Creates a new secret for the account.
93
+ *
94
+ * @param secret The secret value to associate with the API key, which must follow these rules:
95
+ * - Minimum 8 characters
96
+ * - Maximum 25 characters
97
+ * - Minimum 1 lower case character
98
+ * - Minimum 1 upper case character
99
+ * - Minimum 1 digit
100
+ *
101
+ * @return The created secret's metadata.
102
+ *
103
+ * @throws [AccountResponseException] If the secret cannot be created.
104
+ */
38
105
fun create (secret : String ): SecretResponse =
39
106
if (apiKey == null ) client.createSecret(secret)
40
107
else client.createSecret(apiKey, secret)
41
108
109
+ /* *
110
+ * Retrieves a secret by its ID.
111
+ *
112
+ * @param secretId ID of the secret to retrieve.
113
+ *
114
+ * @return The secret's metadata.
115
+ *
116
+ * @throws [AccountResponseException] If the secret cannot be retrieved.
117
+ */
42
118
fun get (secretId : String ): SecretResponse =
43
119
if (apiKey == null ) client.getSecret(secretId)
44
120
else client.getSecret(apiKey, secretId)
45
121
122
+ /* *
123
+ * Deletes a secret by its ID.
124
+ *
125
+ * @param secretId ID of the secret to delete.
126
+ *
127
+ * @throws [AccountResponseException] If the secret cannot be deleted.
128
+ */
46
129
fun delete (secretId : String ): Unit =
47
130
if (apiKey == null ) client.revokeSecret(secretId)
48
131
else client.revokeSecret(apiKey, secretId)
0 commit comments