SPB Git

Repository Public

V3Endpoints.swift 9.8 KB 211 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : Lou-Ka iOS9// File             : LouKa/Core/API/V3Endpoints.swift10// Description      : points d'accès typés de l'API v3 (`/api/v3`) : recherche11//                    par curseur, carte par emprise, estimation, comparables,12//                    coût réel, marché, indice, quartiers, immeubles, rapports13//                    PDF.14// Module           : LouKa15// Repository       : https://git.spboucher.ai/lou-ka-ios-v316// Project Website  : https://www.lou-ka.com17// Created          : 2026-11-2818// Last Modified    : 2026-11-2819//20// =============================================================================21// AUTHOR & PROFESSIONAL AFFILIATION22// =============================================================================23//24// Author           : Simon-Pierre Boucher25// Position         : Professor of Finance26// Institution      : Université du Québec en Outaouais (UQO)27// Department       : Département des sciences administratives28// Organization     : SP Boucher29//30// Website          : https://spboucher.ai31// Git              : https://git.spboucher.ai32//33// =============================================================================34// OFFICIAL CONTACT DIRECTORY35// =============================================================================36//37// General          : info@spboucher.ai38// Professional     : contact@spboucher.ai39// Direct           : simon@spboucher.ai40// Research         : research@spboucher.ai41// Development      : dev@spboucher.ai42// Support          : support@spboucher.ai43// Security/Admin   : admin@spboucher.ai44// Notifications    : notifications@spboucher.ai45//46// Preferred Contact: support@spboucher.ai47//48// =============================================================================49// COPYRIGHT & INTELLECTUAL PROPERTY50// =============================================================================51//52// Copyright (c) 202653// Simon-Pierre Boucher54//55// All rights reserved where applicable.56//57// This file is governed by the applicable project license,58// copyright notices, institutional agreements and relevant law.59//60// Unless expressly authorized by the applicable license or61// rights holder, copying, redistribution, sublicensing,62// publication and commercial exploitation are not permitted.63//64// Existing third-party rights and notices remain unaffected.65//66// =============================================================================67// CONFIDENTIALITY & SECURITY68// =============================================================================69//70// Classification   : Public71// Distribution     : Public repository; use is governed by the project license72// Security Contact : admin@spboucher.ai73//74// Access to this source does not independently grant permission75// to redistribute or disclose confidential materials.76//77// Do not embed credentials, private keys, access tokens,78// certificates or confidential personal information.79//80// =============================================================================81// LICENSE & MAINTENANCE82// =============================================================================83//84// License          : None specified (no license file in this repository)85// Maintainer       : Simon-Pierre Boucher86// Technical Contact: dev@spboucher.ai87//88// =============================================================================89// END OF SP BOUCHER SOURCE HEADER90// =============================================================================9192import Foundation9394extension APIClient {95    func v3Version() async throws -> VersionInfo { try await get("api/v3/version") }9697    // MARK: Recherche9899    /// Page de résultats. `cursor` : curseur opaque de la page précédente (nil pour la première).100    func search(_ filters: SearchFilters, sort: SearchSort = .pertinence, bbox: String? = nil,101                cursor: String? = nil, limit: Int = 24) async throws -> SearchPage {102        var q = filters.query103        // « Plus proches » n'a de sens qu'avec un point de référence104        q["sort"] = (sort == .distance && filters.near == nil ? SearchSort.pertinence : sort).apiValue105        q["bbox"] = bbox106        q["cursor"] = cursor107        q["limit"] = String(limit)108        return try await get("api/v3/search", query: q)109    }110111    /// Points (moins de 4 000 annonces dans l'emprise) ou regroupements calculés par le serveur.112    func searchMap(_ filters: SearchFilters, bbox: String?, zoom: Double) async throws -> MapPayload {113        var q = filters.query114        q["bbox"] = bbox115        q["zoom"] = String(format: "%.2f", min(22, max(0, zoom)))116        return try await get("api/v3/search/map", query: q)117    }118119    func searchFacets(_ filters: SearchFilters) async throws -> SearchFacets {120        try await get("api/v3/search/facets", query: filters.query)121    }122123    /// Interprète une phrase libre côté serveur, sans lancer la recherche.124    func parse(phrase: String) async throws -> ParsedPhrase {125        try await get("api/v3/search/parse", query: ["nl": String(phrase.prefix(400))])126    }127128    // MARK: Lieux129130    func suggestPlaces(_ q: String, limit: Int = 8) async throws -> [Place] {131        try await get("api/v3/geo/suggest", query: ["q": String(q.prefix(80)), "limit": String(limit)], as: PlaceList.self).items132    }133134    func places(kind: String = "municipalite", parent: String? = nil, minListings: Int = 1) async throws -> [Place] {135        try await get("api/v3/geo/places", query: ["kind": kind, "parent": parent, "min_listings": String(minListings)], as: PlaceList.self).items136    }137138    // MARK: Fiche139140    func listingV3(_ uid: String) async throws -> Listing { try await get("api/v3/listings/\(enc(uid))") }141    func valuation(_ uid: String) async throws -> Valuation { try await get("api/v3/valuation/\(enc(uid))") }142    func valuationModel() async throws -> ValuationModelCard { try await get("api/v3/valuation-model") }143    func comparables(_ uid: String, k: Int = 6) async throws -> Comparables {144        try await get("api/v3/comparables/\(enc(uid))", query: ["k": String(k)])145    }146    func trueCost(_ uid: String, assumptions: CostAssumptions = CostAssumptions()) async throws -> TrueCost {147        try await get("api/v3/truecost/\(enc(uid))", query: assumptions.query)148    }149    func trueCost(uids: [String], assumptions: CostAssumptions = CostAssumptions()) async throws -> TrueCostComparison {150        var q = assumptions.query151        q["uids"] = uids.prefix(8).joined(separator: ",")152        return try await get("api/v3/truecost", query: q)153    }154    func links(_ uid: String) async throws -> ListingLinks { try await get("api/v3/listings-links/\(enc(uid))") }155    func building(_ id: String) async throws -> BuildingPassport { try await get("api/v3/buildings/\(enc(id))") }156157    // MARK: Rapports PDF158159    func reportURL(listing uid: String, assumptions: CostAssumptions = CostAssumptions()) async -> URL? {160        await url("api/v3/reports/listing/\(enc(uid))", query: assumptions.query)161    }162    func reportURL(comparison uids: [String], assumptions: CostAssumptions = CostAssumptions()) async -> URL? {163        var q = assumptions.query164        q["uids"] = uids.prefix(8).joined(separator: ",")165        return await url("api/v3/reports/comparison", query: q)166    }167    func reportURL(market place: Place?) async -> URL? {168        await url("api/v3/reports/market", query: ["place": place?.slug, "kind": place?.kind])169    }170171    // MARK: Marché172173    private func placeQuery(_ place: Place?, rooms: Int?) -> [String: String?] {174        ["place": place?.kind == "province" ? nil : place?.slug, "kind": place?.kind == "province" ? nil : place?.kind,175         "rooms": rooms.map(String.init)]176    }177178    func market(place: Place? = nil, rooms: Int? = nil) async throws -> MarketPortrait {179        try await get("api/v3/market", query: placeQuery(place, rooms: rooms))180    }181    func marketSeries(place: Place? = nil, rooms: Int? = nil, indicator: String = "rent_median", freq: String = "W") async throws -> MarketSeries {182        var q = placeQuery(place, rooms: rooms)183        q["indicator"] = indicator; q["freq"] = freq184        return try await get("api/v3/market/series", query: q)185    }186    func marketIndex(place: Place? = nil, rooms: Int? = nil) async throws -> IndexSeries {187        try await get("api/v3/indices", query: placeQuery(place, rooms: rooms))188    }189    func marketDistribution(place: Place? = nil, rooms: Int? = nil) async throws -> MarketDistribution {190        try await get("api/v3/market/distribution", query: placeQuery(place, rooms: rooms))191    }192    func marketMovers(n: Int = 8) async throws -> MarketMovers {193        try await get("api/v3/market/movers", query: ["n": String(n)])194    }195196    // MARK: Quartiers197198    /// `weights` : pondérations personnelles (« walk:3,transit:5 ») ; le tri par score les applique telles quelles.199    func neighborhoods(city: String?, sort: String = "annonces", weights: [String: Double]? = nil, limit: Int = 80) async throws -> NeighborhoodList {200        try await get("api/v3/neighborhoods", query: ["city": city, "sort": sort, "weights": APIClient.weightsParam(weights), "limit": String(limit)])201    }202    func neighborhood(slug: String, city: String?, weights: [String: Double]? = nil) async throws -> NeighborhoodPortrait {203        try await get("api/v3/neighborhoods/\(enc(slug))", query: ["city": city, "weights": APIClient.weightsParam(weights)])204    }205206    static func weightsParam(_ w: [String: Double]?) -> String? {207        guard let w, !w.isEmpty, w != ScoreSet.defaultWeights else { return nil }208        return w.keys.sorted().map { "\($0):\(String(format: "%.2f", w[$0] ?? 0))" }.joined(separator: ",")209    }210}211
Files main
Menu

Theme