Swiftpack.co - Econa77/Pixela.swift as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by Econa77.
Econa77/Pixela.swift v1.2.0
Pixela API client for Swift
⭐️ 4
🕓 1 year ago
iOS macOS
.package(url: "https://github.com/Econa77/Pixela.swift.git", from: "v1.2.0")

Pixela.swift

Actions Status Release version License: MIT Version Platform Carthage compatible SPM supported

Pixela API client for Swift.

Requirements

  • Swift 5.0 or later
  • iOS 11.0 or later
  • macOS 10.12 or later

Getting started

Setting user configuration

To make a request other than the registration API, it is necessary to set configuration.

Pixela.shared.configuration = Configuration(username: "username", token: "secret-token")

User registration

Pixela.shared.createUser(token: "secret-token", username: "username", isAgreeTermsOfService: true, isNotMinor: true, thanksCode: "thanks-code") { result in
    switch result {
    case let .success(configuration):
        // Succeed new user registration
        Pixela.shared.configuration = configuration
    case let .failure(error)
        // Failed registration
    }
}

Other APIs

This library supports all Pixela API as of May 6, 2020. Check here for a list of Pixela APIs. (https://docs.pixe.la/)

Pixela.shared.configuration = Configuration(username: "username", token: "secret-token")
Pixela.shared.getGraphs { result in
    switch result {
    case let .success(graphs):
        print(graphs)
    case let .failure(error):
        print(error)
    }
}

Multi account handling

Instead of using a shared instance, can use a Pixela instance for multiple accounts by manage it yourself.

let user1 = Pixela(configuration: Configuration(username: "user1", token: "user1-secret-token"))

let user2 = Pixela(configuration: nil)
user2.configuration = Configuration(username: "user2", token: "user2-secret-token")

Enterprise support

Change APIConfiguration to connect to the Enterprise version of Pixela.

Pixela.shared.apiConfiguration = APIConfiguration(baseURL: URL(string: "https://custom.pixe.la")!)

let pixela = Pixela(configuration: Configuration(username: "user1", token: "user1-secret-token"))
pixela.apiConfiguration = APIConfiguration(baseURL: URL(string: "https://custom-domain-pixela.com")!)

Error cases

All errors in the library will return a PixelaError. PixelaError is the next 3 cases:

  • PixelaError.requestFailed: Error while creating URLRequest from Request. (some APIKit.SessionTaskError.requestError)
  • PixelaError.connectionFailed: Error of networking backend stack. (some APIKit.SessionTaskError.connectionError)
  • PixelaError.responseFailed(ResponseErrorReason): Error while handling response.

Contributing

  1. Fork it ( https://github.com/Econa77/Pixela.swift/fork )
  2. Update git submodule (carthage checkout --no-build --use-submodules or git submodule init && git submodule update)
  3. Create your feature branch (git checkout -b my-new-feature)
  4. Commit your changes (git commit -am 'Add some feature')
  5. Push to the branch (git push origin my-new-feature)
  6. Create a new Pull Request

GitHub

link
Stars: 4
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

v1.2.0
3 years ago

Breaking Changes

  • Renamed ErrorMessage to Message. ( #13 )

Enhancements

  • Supported for stopwatch request in Pixe.la v1.18.0. ( #13 )

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics