Skip to content

Commit

Permalink
added videos endpoints, documentation, refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
lukepistrol committed May 13, 2022
1 parent ef6180e commit 6f9a700
Show file tree
Hide file tree
Showing 10 changed files with 407 additions and 63 deletions.
1 change: 1 addition & 0 deletions Sources/PexelsSwift/Documentation.docc/Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ let results = await pexels.getCuratedPhotos()
### Structures

- ``PexelsSwift/PSPhoto``
- ``PexelsSwift/PSVideo``
- ``PexelsSwift/PSCollectionCategory``
9 changes: 8 additions & 1 deletion Sources/PexelsSwift/Documentation.docc/PexelsSwift.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ pexels.setAPIKey("YOUR_SECRET_API_KEY")
### Photos

- ``getPhoto(by:)``
- ``getPhotos(search:page:count:)``
- ``getPhotos(for:page:count:)``
- ``getCuratedPhotos(page:count:)``
- ``searchPhotos(_:orientation:size:color:page:count:)``

### Videos

- ``getVideo(by:)``
- ``getVideos(for:page:count:)``
- ``getPopularVideos(minimumWidth:minimumHeight:minimumDuration:maximumDuration:page:count:)``
- ``searchVideos(_:orientation:size:page:results:)``
109 changes: 109 additions & 0 deletions Sources/PexelsSwift/PSVideo.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
//
// File.swift
//
//
// Created by Lukas Pistrol on 13.05.22.
//

import Foundation

/// A structure representing a Video and its metadata.
public struct PSVideo: Identifiable, Codable, Equatable {

enum CodingKeys: String, CodingKey {
case id, width, height, url, image, duration, user
case videoFiles = "video_files"
case videoPictures = "video_pictures"
}

/// The ID of the video.
public var id: Int

/// The real width of the video in pixels.
public var width: Int

/// The real height of the video in pixels.
public var height: Int

/// The Pexels URL where the video is located.
public var url: String

/// URL to a screenshot of the video.
public var image: String

/// The duration of the video in seconds.
public var duration: Int

/// The videographer who shot the video.
public var user: Videographer

/// An array of different sized versions of the video.
public var videoFiles: Array<File>

/// An array of preview pictures of the video.
public var videoPictures: Array<Preview>

/// A structure representing a videographer
public struct Videographer: Identifiable, Codable, Equatable {

/// The ID of the videographer.
public var id: Int

/// The name of the videographer.
public var name: String

/// The URL of the videographer's Pexels profile.
public var url: String
}

/// A structure representing a video file and its metadata.
public struct File: Identifiable, Codable, Equatable {
enum CodingKeys: String, CodingKey {
case id, width, height, link, quality
case fileType = "file_type"
}

/// The ID of the ``PSVideo/File``.
public var id: Int

/// The quality of the ``PSVideo/File``.
public var quality: Quality

/// The video format.
public var fileType: String

/// The width in pixels.
public var width: Int?

/// The height in pixels
public var height: Int?

/// A link to where the ``PSVideo/File`` is hosted.
public var link: String

/// A collection of possible video qualities `[hd, sd, hls]`.
public enum Quality: String, Codable {
case hd, sd, hls
}
}

/// A structure representing a preview picture of a video.
public struct Preview: Identifiable, Codable, Equatable {
enum CodingKeys: String, CodingKey {
case id
case link = "picture"
case index = "nr"
}

/// The ID of the ``PSVideo/Preview``.
public var id: Int

/// A link to the preview image.
public var link: String

/// The index in the array.
public var index: Int
}


}
15 changes: 15 additions & 0 deletions Sources/PexelsSwift/PexelsSwift+Extensions/PexelsSwift+Color.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// File.swift
//
//
// Created by Lukas Pistrol on 13.05.22.
//

import Foundation

public extension PexelsSwift {
/// Colors for ``PSPhoto`` search queries
enum PSColor: String {
case red, orange, yellow, green, turquoise, blue, violet, pink, brown, black, gray, white
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// File.swift
//
//
// Created by Lukas Pistrol on 13.05.22.
//

import Foundation

public extension PexelsSwift {
/// Supported orientations for search queries.
enum PSOrientation: String {
case landscape, portrait, square
}

/// Supported sizes for search queries.
enum PSSize: String {
case large, medium, small
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ import Foundation

internal extension PexelsSwift {
enum PSURL {
static let search: String = "https://api.pexels.com/v1/search"
static let curated: String = "https://api.pexels.com/v1/curated"
static let searchPhotos: String = "https://api.pexels.com/v1/search"
static let curatedPhotos: String = "https://api.pexels.com/v1/curated"
static let collections: String = "https://api.pexels.com/v1/collections"
static let photoByID: String = "https://api.pexels.com/v1/photos"
static let videoByID: String = "https://api.pexels.com/videos/videos"
static let popularVideos: String = "https://api.pexels.com/videos/popular"
static let searchVideos: String = "https://api.pexels.com/videos/search"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@
import Foundation

extension PexelsSwift {
struct ContentResults: Codable {
struct ContentResults<T: Codable>: Codable {
enum CodingKeys: String, CodingKey {
case photos, media, page
case photos, media, videos, page
case perPage = "per_page"
case totalResults = "total_results"
case previousPage = "prev_page"
case nextPage = "next_page"
}
var photos: Array<PSPhoto>? // When searching, or featured
var media: Array<PSPhoto>? // When fetching from collections
var media: Array<T>? // When fetching from collections
var videos: Array<PSVideo>? // When fetching videos
var page: Int
var perPage: Int
var totalResults: Int
Expand Down
18 changes: 0 additions & 18 deletions Sources/PexelsSwift/PexelsSwift+Extensions/PexelsSwift+URL.swift

This file was deleted.

Loading

0 comments on commit 6f9a700

Please sign in to comment.