Skip to content

Commit

Permalink
Merge pull request #120 from Infomaniak/profile
Browse files Browse the repository at this point in the history
feat: No avatar default added
  • Loading branch information
Ambrdctr committed Apr 4, 2024
2 parents 84a64a7 + 3b37688 commit 2fd0658
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Sources/InfomaniakCore/Account/User/UserProfile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public class UserProfile: Codable, InfomaniakUser {
firstName = try container.decode(String.self, forKey: .firstname)
lastName = try container.decode(String.self, forKey: .lastname)
email = try container.decode(String.self, forKey: .email)
avatar = try container.decodeIfPresent(String.self, forKey: .avatar) ?? ""
avatar = try container.decodeIfPresent(String.self, forKey: .avatar)
login = try container.decode(String.self, forKey: .login)
sessions = []
preferences = UserPreferences()
Expand Down
4 changes: 2 additions & 2 deletions Sources/InfomaniakCore/Networking/ApiFetcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ open class ApiFetcher {
try await perform(request: authenticatedRequest(.organisationAccounts))
}

public func userProfile() async throws -> UserProfile {
try await perform(request: authenticatedRequest(.profile))
public func userProfile(ignoreDefaultAvatar: Bool = false) async throws -> UserProfile {
try await perform(request: authenticatedRequest(.profile(ignoreDefaultAvatar: ignoreDefaultAvatar)))
}
}

Expand Down
17 changes: 12 additions & 5 deletions Sources/InfomaniakCore/Networking/Endpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public struct Endpoint {
self.path = path
self.queryItems = queryItems
}

public init(host: String,
path: String,
queryItems: [URLQueryItem]? = nil) {
Expand All @@ -81,6 +81,10 @@ public struct Endpoint {
public func appending(path: String, queryItems: [URLQueryItem]? = nil) -> Endpoint {
return Endpoint(host: host, path: self.path + path, queryItems: queryItems)
}

public static func noAvatarDefault(_ value: Bool = true) -> URLQueryItem {
return URLQueryItem(name: "no_avatar_default", value: value ? "1" : "0")
}
}

// MARK: - Endpoints
Expand All @@ -94,14 +98,17 @@ public extension Endpoint {
return Endpoint(path: "/2")
}

static var profile: Endpoint {
return .baseV2.appending(path: "/profile", queryItems: [URLQueryItem(name: "with", value: "emails,phones")])
}

static var organisationAccounts: Endpoint {
return .baseV1.appending(path: "/account", queryItems: [
URLQueryItem(name: "with", value: "logo"),
URLQueryItem(name: "order_by", value: "name")
])
}

static func profile(ignoreDefaultAvatar: Bool) -> Endpoint {
return .baseV2.appending(path: "/profile", queryItems: [
noAvatarDefault(ignoreDefaultAvatar),
URLQueryItem(name: "with", value: "emails,phones")
])
}
}

0 comments on commit 2fd0658

Please sign in to comment.