From ef6180e61722cd829f43ae95a7936d0be8efd7da Mon Sep 17 00:00:00 2001 From: Lukas Pistrol Date: Fri, 13 May 2022 12:23:55 +0200 Subject: [PATCH] updated documentation --- .../Documentation.docc/Documentation.md | 2 +- .../PexelsSwift/PSCollectionCategory.swift | 15 ++++++- Sources/PexelsSwift/PSPhoto.swift | 45 ++++++++++++++++++- .../PexelsSwift+Results.swift | 2 +- Sources/PexelsSwift/PexelsSwift.swift | 2 +- 5 files changed, 61 insertions(+), 5 deletions(-) diff --git a/Sources/PexelsSwift/Documentation.docc/Documentation.md b/Sources/PexelsSwift/Documentation.docc/Documentation.md index da18c5ff..3ba701a9 100644 --- a/Sources/PexelsSwift/Documentation.docc/Documentation.md +++ b/Sources/PexelsSwift/Documentation.docc/Documentation.md @@ -40,4 +40,4 @@ let results = await pexels.getCuratedPhotos() ### Structures - ``PexelsSwift/PSPhoto`` -- ``PexelsSwift/CollectionCategory`` +- ``PexelsSwift/PSCollectionCategory`` diff --git a/Sources/PexelsSwift/PSCollectionCategory.swift b/Sources/PexelsSwift/PSCollectionCategory.swift index e937a2a5..6dd2e49d 100644 --- a/Sources/PexelsSwift/PSCollectionCategory.swift +++ b/Sources/PexelsSwift/PSCollectionCategory.swift @@ -8,7 +8,7 @@ import Foundation /// A structure representing a Collection Category and its metadata. -public struct CollectionCategory: Identifiable, Codable, Equatable { +public struct PSCollectionCategory: Identifiable, Codable, Equatable { enum CodingKeys: String, CodingKey { case id, title, description @@ -18,12 +18,25 @@ public struct CollectionCategory: Identifiable, Codable, Equatable { case videosCount = "videos_count" } + /// The ID of the collection. public var id: String + + /// The name of the collection. public var title: String + + /// The description of the collection. public var description: String + + /// A flag indicating whether or not the collection is marked as private. public var isPrivate: Bool + + /// The total number of media included in this collection. public var mediaCount: Int + + /// The total number of photos included in this collection. public var photosCount: Int + + /// The total number of videos included in this collection. public var videosCount: Int } diff --git a/Sources/PexelsSwift/PSPhoto.swift b/Sources/PexelsSwift/PSPhoto.swift index 0034f4d7..e19fd02b 100644 --- a/Sources/PexelsSwift/PSPhoto.swift +++ b/Sources/PexelsSwift/PSPhoto.swift @@ -19,19 +19,62 @@ public struct PSPhoto: Identifiable, Codable, Equatable { case averageColor = "avg_color" } + /// The id of the photo. public var id: Int + + /// The real width of the photo in pixels. public var width: Int + + /// The real height of the photo in pixels public var height: Int + + /// The Pexels URL where the photo is located. public var url: String + + /// The name of the photographer who took the photo. public var photographer: String + + /// The URL of the photographer's Pexels profile. public var photographerURL: String + + /// The ID of the photographer. public var photographerID: Int + + /// The average color of the photo. Useful for a placeholder while the image loads. public var averageColor: String + + /// A collection of URLs of different image sizes that can be used to display this ``PSPhoto``. public var source: Dictionary + + /// Text description of the photo for use in the `alt` attribute (HTML). public var alternateDescription: String + /// Keys for different image sizes that can be used to display this ``PSPhoto`` public enum Size: String { - case original, large2x, large, medium, small, portrait, landscape, tiny + + /// The image without any size changes. It will be the same as the ``PSPhoto/width`` and ``PSPhoto/height`` attributes. + case original + + /// the image resized to `940px X 650px @2x` + case large2x + + /// the image resized to `940px X 650px` + case large + + /// The image scaled proportionally so that it's new height is `350px` + case medium + + /// The image scaled proportionally so that it's new height is `130px` + case small + + /// The image cropped to `800px X 1200px` + case portrait + + /// The image cropped to `1200px X 627px` + case landscape + + /// The image cropped to `280px X 200px` + case tiny } } diff --git a/Sources/PexelsSwift/PexelsSwift+Extensions/PexelsSwift+Results.swift b/Sources/PexelsSwift/PexelsSwift+Extensions/PexelsSwift+Results.swift index 3fbad555..84add487 100644 --- a/Sources/PexelsSwift/PexelsSwift+Extensions/PexelsSwift+Results.swift +++ b/Sources/PexelsSwift/PexelsSwift+Extensions/PexelsSwift+Results.swift @@ -34,7 +34,7 @@ extension PexelsSwift { case nextPage = "next_page" } - var collections: Array + var collections: Array var page: Int var perPage: Int var totalResults: Int diff --git a/Sources/PexelsSwift/PexelsSwift.swift b/Sources/PexelsSwift/PexelsSwift.swift index e5b1cb81..0f05e00b 100644 --- a/Sources/PexelsSwift/PexelsSwift.swift +++ b/Sources/PexelsSwift/PexelsSwift.swift @@ -35,7 +35,7 @@ public class PexelsSwift { public func getCategories( page: Int = 1, count results: Int = 10 - ) async -> Array { + ) async -> Array { var req = URLRequest(url: URL(string: "https://api.pexels.com/v1/collections/featured?page=\(page)&per_page=\(results)")!) req.setValue(apiKey, forHTTPHeaderField: apiHeader)