Skip to content

Commit b32ea90

Browse files
Sort API Routes code
1 parent b8ff8a1 commit b32ea90

File tree

2 files changed

+155
-66
lines changed

2 files changed

+155
-66
lines changed

app/src/main/java/com/infomaniak/mail/data/api/ApiRepository.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ object ApiRepository : ApiRepositoryCore() {
106106
}
107107

108108
fun getMailboxes(okHttpClient: OkHttpClient? = null): ApiResponse<List<Mailbox>> {
109-
return callApi(ApiRoutes.mailbox(), GET, okHttpClient = okHttpClient ?: HttpClient.okHttpClient)
109+
return callApi(ApiRoutes.mailboxes(), GET, okHttpClient = okHttpClient ?: HttpClient.okHttpClient)
110110
}
111111

112112
fun addNewMailbox(mailAddress: String, password: String): ApiResponse<MailboxLinkedResult> {
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Infomaniak Mail - Android
3-
* Copyright (C) 2022-2023 Infomaniak Network SA
3+
* Copyright (C) 2022-2024 Infomaniak Network SA
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -24,99 +24,133 @@ import com.infomaniak.mail.utils.Utils
2424

2525
object ApiRoutes {
2626

27-
fun resource(resource: String) = "$MAIL_API$resource"
28-
29-
fun ping() = "$MAIL_API/api/ping-with-auth"
30-
31-
fun addressBooks() = "$MAIL_API/api/pim/addressbook"
32-
33-
fun contact() = "$MAIL_API/api/pim/contact"
34-
35-
fun contacts() = "${contact()}/all?with=emails,details,others,contacted_times&filters=has_email"
36-
37-
fun mailbox() = "$MAIL_API/api/mailbox?with=unseen,aliases,external_mail_flag_enabled"
38-
39-
fun permissions(linkId: Int, hostingId: Int): String {
40-
return "$MAIL_API/api/mailbox/permissions?user_mailbox_id=$linkId&product_id=$hostingId"
27+
//region API V1
28+
fun getCredentialsPassword(): String {
29+
return "$INFOMANIAK_API_V1/profile/password"
4130
}
4231

43-
private fun ai(): String = "$MAIL_API/api/ai"
32+
private fun mailboxV1(mailboxHostingId: Int, mailboxName: String): String {
33+
return "$INFOMANIAK_API_V1/mail_hostings/$mailboxHostingId/mailboxes/$mailboxName"
34+
}
4435

45-
fun featureFlag(featureName: String, currentMailboxUuid: String): String {
46-
return "$MAIL_API/api/feature-flag/check/$featureName${mailboxUuidParameter(currentMailboxUuid)}"
36+
fun backups(mailboxHostingId: Int, mailboxName: String): String {
37+
return "${mailboxV1(mailboxHostingId, mailboxName)}/backups"
4738
}
4839

49-
private fun apiMailbox(mailboxHostingId: Int, mailboxName: String): String {
50-
return "$INFOMANIAK_API_V1/mail_hostings/$mailboxHostingId/mailboxes/$mailboxName"
40+
fun requestMailboxPassword(mailboxHostingId: Int, mailboxName: String): String {
41+
return "${mailboxV1(mailboxHostingId, mailboxName)}/ask_password"
5142
}
5243

53-
fun signatures(mailboxHostingId: Int, mailboxName: String) = "${apiMailbox(mailboxHostingId, mailboxName)}/signatures"
44+
fun signatures(mailboxHostingId: Int, mailboxName: String): String {
45+
return "${mailboxV1(mailboxHostingId, mailboxName)}/signatures"
46+
}
5447

5548
fun signature(mailboxHostingId: Int, mailboxName: String, signatureId: Int): String {
5649
return "${signatures(mailboxHostingId, mailboxName)}/$signatureId"
5750
}
51+
//endregion
5852

59-
fun manageMailboxes() = "$MAIL_API/api/securedProxy/profile/workspace/mailbox"
60-
61-
fun manageMailbox(mailboxId: Int) = "${manageMailboxes()}/$mailboxId"
53+
//region Personal Information Manager
54+
private fun pim(): String {
55+
return "$MAIL_API/api/pim"
56+
}
6257

63-
fun updateMailboxPassword(mailboxId: Int): String {
64-
return "$MAIL_API/api/securedProxy/cache/invalidation/profile/workspace/mailbox/$mailboxId/update_password"
58+
fun addressBooks(): String {
59+
return "${pim()}/addressbook"
6560
}
6661

67-
fun requestMailboxPassword(mailboxHostingId: Int, mailboxName: String): String {
68-
return "${apiMailbox(mailboxHostingId, mailboxName)}/ask_password"
62+
fun contact(): String {
63+
return "${pim()}/contact"
6964
}
7065

71-
fun backups(mailboxHostingId: Int, mailboxName: String) = "${apiMailbox(mailboxHostingId, mailboxName)}/backups"
66+
fun contacts(): String {
67+
return "${contact()}/all?with=emails,details,others,contacted_times&filters=has_email"
68+
}
69+
//endregion
7270

73-
fun folders(mailboxUuid: String) = "$MAIL_API/api/mail/$mailboxUuid/folder"
71+
//region Secured Proxy
72+
private fun securedProxy(): String {
73+
return "$MAIL_API/api/securedProxy"
74+
}
7475

75-
private fun folder(mailboxUuid: String, folderId: String) = "${folders(mailboxUuid)}/$folderId"
76+
fun updateMailboxPassword(mailboxId: Int): String {
77+
return "${securedProxy()}/cache/invalidation/profile/workspace/mailbox/$mailboxId/update_password"
78+
}
7679

77-
fun flushFolder(mailboxUuid: String, folderId: String) = "${folder(mailboxUuid, folderId)}/flush"
80+
fun manageMailboxes(): String {
81+
return "${securedProxy()}/profile/workspace/mailbox"
82+
}
7883

79-
fun quotas(mailboxHostingId: Int, mailboxName: String): String =
80-
"$MAIL_API/api/mailbox/quotas?mailbox=$mailboxName&product_id=$mailboxHostingId"
84+
fun manageMailbox(mailboxId: Int): String {
85+
return "${manageMailboxes()}/$mailboxId"
86+
}
87+
//endregion
8188

82-
private fun messages(mailboxUuid: String) = "$MAIL_API/api/mail/$mailboxUuid/message"
89+
//region Mailbox
90+
private fun mailbox(): String {
91+
return "$MAIL_API/api/mailbox"
92+
}
8393

84-
private fun message(mailboxUuid: String, folderId: String, shortUid: Int): String {
85-
return "${folder(mailboxUuid, folderId)}/message/$shortUid"
94+
fun mailboxes(): String {
95+
return "${mailbox()}?with=aliases,unseen"
8696
}
8797

88-
fun moveMessages(mailboxUuid: String) = "${messages(mailboxUuid)}/move"
98+
fun permissions(linkId: Int, mailboxHostingId: Int): String {
99+
return "${mailbox()}/permissions?user_mailbox_id=$linkId&product_id=$mailboxHostingId"
100+
}
89101

90-
fun deleteMessages(mailboxUuid: String) = "${messages(mailboxUuid)}/delete"
102+
fun quotas(mailboxHostingId: Int, mailboxName: String): String {
103+
return "${mailbox()}/quotas?mailbox=$mailboxName&product_id=$mailboxHostingId"
104+
}
105+
//endregion
91106

92-
fun messagesSeen(mailboxUuid: String) = "${messages(mailboxUuid)}/seen"
107+
//region Folder
108+
private fun mailMailbox(mailboxUuid: String): String {
109+
return "$MAIL_API/api/mail/$mailboxUuid"
110+
}
93111

94-
fun messagesUnseen(mailboxUuid: String) = "${messages(mailboxUuid)}/unseen"
112+
fun folders(mailboxUuid: String): String {
113+
return "${mailMailbox(mailboxUuid)}/folder"
114+
}
95115

96-
fun starMessages(mailboxUuid: String, star: Boolean): String = "${messages(mailboxUuid)}/${if (star) "star" else "unstar"}"
116+
private fun folder(mailboxUuid: String, folderId: String): String {
117+
return "${folders(mailboxUuid)}/$folderId"
118+
}
97119

98-
fun draft(mailboxUuid: String) = "$MAIL_API/api/mail/$mailboxUuid/draft"
120+
fun flushFolder(mailboxUuid: String, folderId: String): String {
121+
return "${folder(mailboxUuid, folderId)}/flush"
122+
}
99123

100-
fun draft(mailboxUuid: String, remoteDraftUuid: String) = "${draft(mailboxUuid)}/$remoteDraftUuid"
124+
fun search(mailboxUuid: String, folderId: String, filters: String): String {
125+
return "${folder(mailboxUuid, folderId)}/message?thread=on&offset=0&$filters"
126+
}
127+
//region Folder
101128

102-
fun createAttachment(mailboxUuid: String) = "${draft(mailboxUuid)}/attachment"
129+
//region Messages from Folder/Message
130+
private fun message(mailboxUuid: String, folderId: String, shortUid: Int): String {
131+
return "${folder(mailboxUuid, folderId)}/message/$shortUid"
132+
}
103133

104134
fun downloadAttachments(mailboxUuid: String, folderId: String, shortUid: Int): String {
105135
return "${message(mailboxUuid, folderId, shortUid)}/attachmentsArchive"
106136
}
107137

108-
fun attachmentToForward(mailboxUuid: String) = "${draft(mailboxUuid)}/attachmentsToForward"
109-
110-
fun search(mailboxUuid: String, folderId: String, filters: String): String {
111-
return "${folder(mailboxUuid, folderId)}/message?thread=on&offset=0&$filters"
138+
fun blockUser(mailboxUuid: String, folderId: String, shortUid: Int): String {
139+
return "${message(mailboxUuid, folderId, shortUid)}/blacklist"
112140
}
113141

114142
fun reportPhishing(mailboxUuid: String, folderId: String, shortUid: Int): String {
115143
return "${message(mailboxUuid, folderId, shortUid)}/report"
116144
}
145+
//endregion
117146

118-
fun blockUser(mailboxUuid: String, folderId: String, shortUid: Int): String {
119-
return "${message(mailboxUuid, folderId, shortUid)}/blacklist"
147+
// Message from Folder/Mobile
148+
private fun getMessages(mailboxUuid: String, folderId: String): String {
149+
return "${folder(mailboxUuid, folderId)}/mobile"
150+
}
151+
152+
fun getMessagesUidsDelta(mailboxUuid: String, folderId: String, cursor: String): String {
153+
return "${getMessages(mailboxUuid, folderId)}/activities?signature=$cursor"
120154
}
121155

122156
fun getMessagesUids(mailboxUuid: String, folderId: String, info: PaginationInfo?): String {
@@ -127,31 +161,86 @@ object ApiRoutes {
127161
return "${endpoint}${messages}${offset}${direction}"
128162
}
129163

130-
fun getMessagesUidsDelta(mailboxUuid: String, folderId: String, cursor: String): String {
131-
return "${getMessages(mailboxUuid, folderId)}/activities?signature=${cursor}"
132-
}
133-
134164
fun getMessagesByUids(mailboxUuid: String, folderId: String, uids: List<Int>): String {
135165
return "${getMessages(mailboxUuid, folderId)}/messages?uids=${uids.joinToString(",")}"
136166
}
167+
//endregion
137168

138-
private fun mailboxUuidParameter(currentMailboxUuid: String) = "?mailbox_uuid=$currentMailboxUuid"
169+
//region Message from Mailbox
170+
private fun messages(mailboxUuid: String): String {
171+
return "${mailMailbox(mailboxUuid)}/message"
172+
}
139173

140-
fun aiConversation(currentMailboxUuid: String): String {
141-
return "${ai()}${mailboxUuidParameter(currentMailboxUuid)}"
174+
fun deleteMessages(mailboxUuid: String): String {
175+
return "${messages(mailboxUuid)}/delete"
142176
}
143177

144-
fun aiShortcutWithContext(contextId: String, action: String, currentMailboxEmail: String): String {
145-
return "${ai()}/mobile/$contextId/$action${mailboxUuidParameter(currentMailboxEmail)}"
178+
fun moveMessages(mailboxUuid: String): String {
179+
return "${messages(mailboxUuid)}/move"
146180
}
147181

148-
fun aiShortcutNoContext(action: String, currentMailboxEmail: String): String {
149-
return "${ai()}/mobile/$action${mailboxUuidParameter(currentMailboxEmail)}"
182+
fun messagesSeen(mailboxUuid: String): String {
183+
return "${messages(mailboxUuid)}/seen"
150184
}
151185

152-
private fun getMessages(mailboxUuid: String, folderId: String): String {
153-
return "$MAIL_API/api/mail/${mailboxUuid}/folder/${folderId}/mobile"
186+
fun messagesUnseen(mailboxUuid: String): String {
187+
return "${messages(mailboxUuid)}/unseen"
188+
}
189+
190+
fun starMessages(mailboxUuid: String, star: Boolean): String {
191+
return "${messages(mailboxUuid)}/${if (star) "star" else "unstar"}"
192+
}
193+
//endregion
194+
195+
//region Draft from Mailbox
196+
fun draft(mailboxUuid: String): String {
197+
return "${mailMailbox(mailboxUuid)}/draft"
198+
}
199+
200+
fun draft(mailboxUuid: String, remoteDraftUuid: String): String {
201+
return "${draft(mailboxUuid)}/$remoteDraftUuid"
154202
}
155203

156-
fun getCredentialsPassword(): String = "$INFOMANIAK_API_V1/profile/password"
204+
fun createAttachment(mailboxUuid: String): String {
205+
return "${draft(mailboxUuid)}/attachment"
206+
}
207+
208+
fun attachmentToForward(mailboxUuid: String): String {
209+
return "${draft(mailboxUuid)}/attachmentsToForward"
210+
}
211+
//endregion
212+
213+
//region AI
214+
private fun ai(): String {
215+
return "$MAIL_API/api/ai"
216+
}
217+
218+
fun aiConversation(mailboxUuid: String): String {
219+
return "${ai()}${mailboxUuidParameter(mailboxUuid)}"
220+
}
221+
222+
fun aiShortcutWithContext(contextId: String, action: String, mailboxUuid: String): String {
223+
return "${ai()}/mobile/$contextId/${action}${mailboxUuidParameter(mailboxUuid)}"
224+
}
225+
226+
fun aiShortcutNoContext(action: String, mailboxUuid: String): String {
227+
return "${ai()}/mobile/${action}${mailboxUuidParameter(mailboxUuid)}"
228+
}
229+
//endregion
230+
231+
private fun mailboxUuidParameter(mailboxUuid: String): String {
232+
return "?mailbox_uuid=$mailboxUuid"
233+
}
234+
235+
fun featureFlag(featureName: String, mailboxUuid: String): String {
236+
return "$MAIL_API/api/feature-flag/check/${featureName}${mailboxUuidParameter(mailboxUuid)}"
237+
}
238+
239+
fun ping(): String {
240+
return "$MAIL_API/api/ping-with-auth"
241+
}
242+
243+
fun resource(resource: String): String {
244+
return "${MAIL_API}${resource}"
245+
}
157246
}

0 commit comments

Comments
 (0)