Pexels API client library for the Swift programming language.

Overview

GitHub Workflow Status GitHub Twitter: @lukeeep_

Pexels-Swift

Pexels.com API client library for the Swift programming language.

Banner

Overview

This Swift Package is a wrapper for Pexels API to get access to the entire photo library of Pexels within your Swift app.

It is mandatory to get an API Key.

Installation (SPM)

dependencies: [
  .package(url: "https://github.com/lukepistrol/Pexels-Swift.git", from: "0.1.0")
],

Documentation

See the full documentation here or build it locally using ⇧⌃⌘D in Xcode once you added Pexels-Swift to your project.

Usage

import PexelsSwift

// access the singleton instance
let pexels = PexelsSwift.shared

// set your API key
pexels.setup(apiKey: "YOUR_API_KEY", logLevel: .debug)

// fetch images metadata using async/await
let result = await pexels.getCuratedPhotos()

switch result {
case .failure(let error):
    print(error.description)
case .success(let (data, paging, response)):
    // access photos
    // data -> [PSPhoto]
    // paging -> PSPagingInfo
    // response -> HTTPURLResponse
}

// fetch images metadata using completion handlers
pexels.getCuratedPhotos() { result in
    switch result {
    case .failure(let error):
        print(error.description)
    case .success(let (data, paging, response)):
        // access photos
        // data -> [PSPhoto]
        // paging -> PSPagingInfo
        // response -> HTTPURLResponse
    }
}

Demo Project

I've built a simple iOS app - PexelsBrowser - using this library and SwiftUI.

Buy Me A Coffee

You might also like...
A Swift library for Discord REST/Gateway API in all platforms.

swift-discord main develop A Swift library for Discord API. Package Products Discord, alias library that contains DiscordREST, DiscordGateway. Discord

Cross-platform Swift library for accessing the public GitHub API.

GoatHerb GoatHerb is a cross-platform Swift library for accessing the GitHub API. Features General Compatible with swift-log. Full concurrency (async/

🐦 An asynchronous Twitter library based on the Twitter v2 API

Twift Twift is an asynchronous Swift library for the Twitter v2 API. No external dependencies Only one callback-based method (requestUserCredentials)

The template for Delta Client plugins.

Delta Plugin Template This repository is a template for Delta Client plugins. To create a plugin, create a repo from this template repo and then repla

A simple Hacker News mobile client

A simple Hacker News mobile client. Overview This app was built with the Hacker News API This is one of my first apps outside of a tut

 An ultra-lightweight native Discord client for vintage and modern Mac OS
An ultra-lightweight native Discord client for vintage and modern Mac OS

Discord Lite An ultra-lightweight native Discord client for vintage and modern Mac OS Minimum System Requirements Mac OS X version 10.4 (Tiger) PowerP

hackfoldr client for iOS

hackfoldr-iOS This is a simple iOS client for hackfoldr Why? Hackfoldr on mobile is simply not good enough on iOS. Use CocoaPods developer CocoaPods i

A Hacker News client written in React Native
A Hacker News client written in React Native

React Native Hacker News A modern cross-platform HackerNews client built on React Native Features The app currently has the following functionality: H

Beam: the open source Reddit client for iOS
Beam: the open source Reddit client for iOS

Beam for Reddit An open source Reddit client for iOS. Introduction Hi, we're Awkward. In 2014, we started working on a Reddit client called Beam. In t

Comments
  • refactor: added HTTPURLResponse to returned result tuple

    refactor: added HTTPURLResponse to returned result tuple

    Before

    let result = await pexels.getCuratedPhotos()
    
    switch result {
    case .failure(let error):
        print(error.description)
    case .success(let (data, paging)):
        // access photos
        // data -> [PSPhoto]
        // paging -> PSPagingInfo
    }
    

    After

    let result = await pexels.getCuratedPhotos()
    
    switch result {
    case .failure(let error):
        print(error.description)
    case .success(let (data, paging, response)):
        // access photos
        // data -> [PSPhoto]
        // paging -> PSPagingInfo
        // response -> HTTPURLResponse
    }
    
    enhancement 
    opened by lukepistrol 0
Releases(0.9.4)
  • 0.9.4(Oct 5, 2022)

  • 0.9.3(Jun 22, 2022)

    0.9.3

    • added support for tvOS and watchOS

    0.9.2

    • fixed per_page coding key typo. Thanks to @SugiKent

    0.9.1

    • added rate limit tracking. See Rate Limits for more information.

    0.9.0

    Breaking Changes:

    • added HTTPURLResponse to results tuple:
    let result = await pexels.getCuratedPhotos()
    
    switch result {
    case .failure(let error):
        print(error.description)
    case .success(let (data, paging, response)):
        // access photos
        // data -> [PSPhoto]
        // paging -> PSPagingInfo
        // response -> HTTPURLResponse
    }
    
    Source code(tar.gz)
    Source code(zip)
  • 0.9.2(May 29, 2022)

    0.9.2

    • fixed per_page coding key typo. Thanks to @SugiKent

    0.9.1

    • added rate limit tracking. See Rate Limits for more information.

    0.9.0

    Breaking Changes:

    • added HTTPURLResponse to results tuple:
    let result = await pexels.getCuratedPhotos()
    
    switch result {
    case .failure(let error):
        print(error.description)
    case .success(let (data, paging, response)):
        // access photos
        // data -> [PSPhoto]
        // paging -> PSPagingInfo
        // response -> HTTPURLResponse
    }
    
    Source code(tar.gz)
    Source code(zip)
  • 0.9.1(May 23, 2022)

    0.9.1

    • added rate limit tracking. See Rate Limits for more information.

    0.9.0

    Breaking Changes:

    • added HTTPURLResponse to results tuple:
    let result = await pexels.getCuratedPhotos()
    
    switch result {
    case .failure(let error):
        print(error.description)
    case .success(let (data, paging, response)):
        // access photos
        // data -> [PSPhoto]
        // paging -> PSPagingInfo
        // response -> HTTPURLResponse
    }
    
    Source code(tar.gz)
    Source code(zip)
  • 0.9.0(May 23, 2022)

    Breaking Changes:

    • added HTTPURLResponse to results tuple:
    let result = await pexels.getCuratedPhotos()
    
    switch result {
    case .failure(let error):
        print(error.description)
    case .success(let (data, paging, response)):
        // access photos
        // data -> [PSPhoto]
        // paging -> PSPagingInfo
        // response -> HTTPURLResponse
    }
    
    Source code(tar.gz)
    Source code(zip)
  • 0.8.2(May 20, 2022)

    0.8.2

    0.8.1

    0.8.0

    Breaking Changes:

    • added PSMetaData to results for queries that use paging (page, next page, previous page,…)
    let result = await pexels.getCuratedPhotos()
    
    switch result {
    case .failure(let error):
        print(error.description)
    case .success(let (photos, metadata)):
        // access photos and metadata
    }
    
    Source code(tar.gz)
    Source code(zip)
  • 0.8.1(May 19, 2022)

    0.8.1

    0.8.0

    Breaking Changes:

    • added PSMetaData to results for queries that use paging (page, next page, previous page,…)
    let result = await pexels.getCuratedPhotos()
    
    switch result {
    case .failure(let error):
        print(error.description)
    case .success(let (photos, metadata)):
        // access photos and metadata
    }
    
    Source code(tar.gz)
    Source code(zip)
  • 0.8.0(May 19, 2022)

    Breaking Changes:

    • added PSMetaData to results for queries that use paging (page, next page, previous page,…)
    let result = await pexels.getCuratedPhotos()
    
    switch result {
    case .failure(let error):
        print(error.description)
    case .success(let (photos, metadata)):
        // access photos and metadata
    }
    
    Source code(tar.gz)
    Source code(zip)
  • 0.7.4(May 19, 2022)

    0.7.4

    • added PSLogger.log(_ message:) method
    • updated documentation

    Previous Changes

    0.7.3

    • updated documentation

    0.7.2

    • added backwards compatibility for iOS 13.0 and macOS 10.15

    0.7.1

    • updated DocC documentation

    0.7.0

    Breaking Changes:

    • renamed external parameter: result: to count: in searchVideos()

    New Features:

    • added localization: parameter to searchPhotos() and searchVideos()

    Internal Changes:

    • enhanced API endpoint URL generation
    • moved parameter string literals to QueryParameter enum
    • updated folder structure
    • added shadow types CategoryID, ErrorDescription
    • updated documentation
    Source code(tar.gz)
    Source code(zip)
  • 0.7.3(May 19, 2022)

    0.7.3

    • updated documentation

    0.7.2

    • added backwards compatibility for iOS 13.0 and macOS 10.15

    0.7.1

    • updated DocC documentation

    0.7.0

    Breaking Changes:

    • renamed external parameter: result: to count: in searchVideos()

    New Features:

    • added localization: parameter to searchPhotos() and searchVideos()

    Internal Changes:

    • enhanced API endpoint URL generation
    • moved parameter string literals to QueryParameter enum
    • updated folder structure
    • added shadow types CategoryID, ErrorDescription
    • updated documentation
    Source code(tar.gz)
    Source code(zip)
  • 0.7.2(May 16, 2022)

    0.7.2

    • added backwards compatibility for iOS 13.0 and macOS 10.15

    0.7.1

    • updated DocC documentation

    0.7.0

    Breaking Changes:

    • renamed external parameter: result: to count: in searchVideos()

    New Features:

    • added localization: parameter to searchPhotos() and searchVideos()

    Internal Changes:

    • enhanced API endpoint URL generation
    • moved parameter string literals to QueryParameter enum
    • updated folder structure
    • added shadow types CategoryID, ErrorDescription
    • updated documentation
    Source code(tar.gz)
    Source code(zip)
  • 0.7.1(May 16, 2022)

    0.7.1

    • updated DocC documentation

    0.7.0

    Breaking Changes:

    • renamed external parameter: result: to count: in searchVideos()

    New Features:

    • added localization: parameter to searchPhotos() and searchVideos()

    Internal Changes:

    • enhanced API endpoint URL generation
    • moved parameter string literals to QueryParameter enum
    • updated folder structure
    • added shadow types CategoryID, ErrorDescription
    • updated documentation
    Source code(tar.gz)
    Source code(zip)
  • 0.7.0(May 16, 2022)

    Breaking Changes:

    • renamed external parameter: result: to count: in searchVideos()

    New Features:

    • added localization: parameter to searchPhotos() and searchVideos()

    Internal Changes:

    • enhanced API endpoint URL generation
    • moved parameter string literals to QueryParameter enum
    • updated folder structure
    • added shadow types CategoryID, ErrorDescription
    • updated documentation
    Source code(tar.gz)
    Source code(zip)
  • 0.6.0(May 16, 2022)

    New Features:

    • added closure versions of get methods:
    // fetch images metadata using completion handlers
    pexels.getCuratedPhotos() { result in
        switch result {
        case .failure(let error):
            print(error.description)
        case .success(let photos):
            // access photos
        }
    }
    

    Internal Changes:

    • moved methods for Photos, Videos, Collections to their own separate files
    • disabled logging in tests
    • updated docs
    Source code(tar.gz)
    Source code(zip)
  • 0.5.0(May 15, 2022)

    Breaking Changes:

    • renamed setAPIKey(_:) to setup(apiKey:logLevel:)
    // access the singleton instance
    let pexels = PexelsSwift.shared
    
    // set your API key
    pexels.setup(apiKey: "YOUR_API_KEY", logLevel: .debug)
    

    New Features:

    • added PSLogger for logging events to the console on runtime.
    • see Ratelimit statistics in logs.
    • see fetched data as JSON in logs.
    • see errors in logs.

    Internal Changes:

    • refactored fetch methods
    Source code(tar.gz)
    Source code(zip)
  • 0.4.1(May 14, 2022)

    0.4.1

    • updated docs

    0.4.0

    Breaking Changes:

    • renamed PSCollectionCategory to PSCollection
    • renamed getCategories() to getCollections()
    • results now get returned in a Result<T, Error> format:
    let result = await pexels.getCuratedPhotos()
    
    switch result {
    case .failure(let error):
        // handle error
    case .success(let photos):
        // access photos
    }
    

    Internal changes:

    • using async/await syntax for URLSession instead of Combine
    • renamed enum PSURL to API
    Source code(tar.gz)
    Source code(zip)
  • 0.4.0(May 14, 2022)

    Breaking Changes:

    • renamed PSCollectionCategory to PSCollection
    • renamed getCategories() to getCollections()
    • results now get returned in a Result<T, Error> format:
    let result = await pexels.getCuratedPhotos()
    
    switch result {
    case .failure(let error):
        // handle error
    case .success(let photos):
        // access photos
    }
    

    Internal changes:

    • using async/await syntax for URLSession instead of Combine
    • renamed enum PSURL to API
    Source code(tar.gz)
    Source code(zip)
  • 0.3.0(May 13, 2022)

  • 0.2.2(May 13, 2022)

  • 0.2.1(May 13, 2022)

  • 0.2.0(May 13, 2022)

Owner
Lukas Pistrol
Swift frontend developer. Currently working on @CodeEditApp
Lukas Pistrol
Github iOS Client based on Github REST V3 API and GraphQL V4 API

ZLGithubClient Github iOS 客户端 by Existorlive Objective-c 2.0 Swift 5 Cocoapods 1.9.1 iOS >= 11.0 基于 Github REST V3 API 和 Github GraphQL V4 API 开发的iOS客

朱猛 55 Dec 29, 2022
The Outline Client is a cross-platform VPN or proxy client for Windows, macOS, iOS, Android, and ChromeOS

Outline Client The Outline Client is a cross-platform VPN or proxy client for Windows, macOS, iOS, Android, and ChromeOS. The Outline Client is design

Jigsaw 7.3k Dec 31, 2022
A web API client in Swift built using Async/Await

Web API Client A modern web API client in Swift built using Async/Await and Actors. let client = APIClient(host: "api.github.com") // Using the clien

Alexander Grebenyuk 741 Dec 30, 2022
An IPFS client/api Swift Package, with the ability to add and pin any data on iOS/iPadOS/macOS

An IPFS client/api Swift Package, with the ability to add and pin any data on iOS/iPadOS/macOS. Originally bundled with GraniteUI, pulled out for independant use by any party.

Kala 4 Dec 8, 2022
Swift Programming Basics - Collections, Variables & Constants

Dicee What I learned in this module How to clone an existing Xcode project from GitHub. Create an app with behaviour and functionality. Create links b

null 0 Jan 9, 2022
IMBeeHive is a kind of modular programming method

概述 IMBeeHive是用于iOS的App模块化编程的框架实现方案,本项目主要借鉴了阿里巴巴BeeHive,在此基础上通过逆向了一些大厂的APP使得功能更加强大完善。同时现在也在寻找一起开发这个框架的开发者,如果您对此感兴趣,请联系我的微信:alvinkk01. 背景 随着公司业务的不断发展,项目

null 6 Dec 14, 2021
Sonic language: Heavily inspired by Swift, but compiles to C so you can use it anywhere.

Sonic Sonic programming language: Heavily inspired by Swift, but compiles to C so you can use it anywhere. Brought to you by Chris Hulbert and Andres

Sonic Language 27 Apr 8, 2022
The most powerful Event-Driven Observer Pattern solution the Swift language has ever seen!

Event-Driven Swift Decoupling of discrete units of code contributes massively to the long-term maintainability of your project(s). While Observer Patt

Flowduino 4 Nov 14, 2022
Ulangi is a language flashcards app with spaced repetition system and more.

Ulangi Open-source language learning tools Introduction Ulangi makes it easy for you to manage and create flash cards to learn languages. It comes wit

Ulangi 384 Jan 3, 2023
Keybase Go Library, Client, Service, OS X, iOS, Android, Electron

Keybase Hi, and welcome to the Keybase client repo. All our client apps (macOS, Windows, Linux, iOS, and Android) are being actively developed in this

Keybase 8.3k Dec 31, 2022