|  | 
|  | 1 | +# MagicBellClient Swift SDK 0.1.0 | 
|  | 2 | + | 
|  | 3 | +Welcome to the MagicBellClient SDK documentation. This guide will help you get started with integrating and using the MagicBellClient SDK in your project. | 
|  | 4 | + | 
|  | 5 | +## About the API | 
|  | 6 | + | 
|  | 7 | +OpenAPI 3.0.3 Specification for MagicBell API. | 
|  | 8 | + | 
|  | 9 | +## Table of Contents | 
|  | 10 | + | 
|  | 11 | +- [MagicBellClient Swift SDK 0.1.0](#magicbellclient-swift-sdk-010) | 
|  | 12 | +  - [About the API](#about-the-api) | 
|  | 13 | +  - [Table of Contents](#table-of-contents) | 
|  | 14 | +- [Setup \& Configuration](#setup--configuration) | 
|  | 15 | +  - [Supported Language Versions](#supported-language-versions) | 
|  | 16 | +  - [Installation](#installation) | 
|  | 17 | +    - [CocoaPods](#cocoapods) | 
|  | 18 | +    - [Swift Package Manager](#swift-package-manager) | 
|  | 19 | +  - [Authentication](#authentication) | 
|  | 20 | +    - [Access Token Authentication](#access-token-authentication) | 
|  | 21 | +      - [Setting the Access Token](#setting-the-access-token) | 
|  | 22 | +- [Sample Usage](#sample-usage) | 
|  | 23 | +  - [License](#license) | 
|  | 24 | + | 
|  | 25 | +# Setup & Configuration | 
|  | 26 | + | 
|  | 27 | +## Supported Language Versions | 
|  | 28 | + | 
|  | 29 | +This SDK is compatible with the following versions: | 
|  | 30 | + | 
|  | 31 | +- iOS 13.0+, macOS 15.0+, tvOS 13.0+, watchOS 6.0+, visionOS 1.0+ | 
|  | 32 | +- Swift 6.0+ | 
|  | 33 | +- Xcode 16+ | 
|  | 34 | + | 
|  | 35 | +## Installation | 
|  | 36 | + | 
|  | 37 | + | 
|  | 38 | + | 
|  | 39 | +### CocoaPods | 
|  | 40 | + | 
|  | 41 | +If you use [CocoaPods](https://cocoapods.org), place the following within your `Podfile`: | 
|  | 42 | + | 
|  | 43 | +```ruby | 
|  | 44 | +pod 'MagicBellClient', '>=0.1.0' | 
|  | 45 | +``` | 
|  | 46 | + | 
|  | 47 | +**IMPORTANT**: Make sure you specify `use_frameworks!` in your `Podfile`. | 
|  | 48 | + | 
|  | 49 | +Then, run `pod install`. | 
|  | 50 | + | 
|  | 51 | +### Swift Package Manager | 
|  | 52 | + | 
|  | 53 | +To install MagicBell using [Swift Package Manager](https://www.swift.org/package-manager/), add the dependency as follows to your project: | 
|  | 54 | + | 
|  | 55 | +```swift | 
|  | 56 | +dependencies: [ | 
|  | 57 | +    .package(url: "https://github.com/magicbell/magicbell-swift-client", .upToNextMajor(from: "0.1.0")) | 
|  | 58 | +] | 
|  | 59 | +``` | 
|  | 60 | + | 
|  | 61 | +## Authentication | 
|  | 62 | + | 
|  | 63 | +### Access Token Authentication | 
|  | 64 | + | 
|  | 65 | +The MagicBell API uses an Access Token for authentication. | 
|  | 66 | + | 
|  | 67 | +This token must be provided to authenticate your requests to the API. | 
|  | 68 | + | 
|  | 69 | +#### Setting the Access Token | 
|  | 70 | + | 
|  | 71 | +When you initialize the SDK, you can set the access token via the `AuthenticationMiddleware`: | 
|  | 72 | + | 
|  | 73 | +```swift | 
|  | 74 | +let authMiddleware = AuthenticationMiddleware(jwtToken: token) | 
|  | 75 | + | 
|  | 76 | +let client = MagicBellClient.Client( | 
|  | 77 | +            serverURL: try Servers.Server1.url(), | 
|  | 78 | +            configuration: .init(dateTranscoder: .iso8601WithFractionalSeconds), | 
|  | 79 | +            transport: URLSessionTransport(), | 
|  | 80 | +            middlewares: [authMiddleware]) | 
|  | 81 | +``` | 
|  | 82 | + | 
|  | 83 | +If you need to set or update the access token after initializing the SDK you can create a new Client instance. | 
|  | 84 | + | 
|  | 85 | +# Sample Usage | 
|  | 86 | + | 
|  | 87 | +Below is a comprehensive example demonstrating how to authenticate and call a simple endpoint: | 
|  | 88 | + | 
|  | 89 | +```swift | 
|  | 90 | +import Foundation | 
|  | 91 | +import MagicBellClient | 
|  | 92 | +import OpenAPIURLSession | 
|  | 93 | + | 
|  | 94 | +let token = "YOUR_ACCESS_TOKEN" | 
|  | 95 | + | 
|  | 96 | +@main | 
|  | 97 | +struct MainApp { | 
|  | 98 | +    static func main() async throws { | 
|  | 99 | + | 
|  | 100 | +        let client = MagicBellClient.Client( | 
|  | 101 | +            serverURL: try Servers.Server1.url(), | 
|  | 102 | +            configuration: .init(dateTranscoder: .iso8601WithFractionalSeconds), | 
|  | 103 | +            transport: URLSessionTransport(), | 
|  | 104 | +            middlewares: [AuthenticationMiddleware(jwtToken: token)]) | 
|  | 105 | + | 
|  | 106 | +        let response = try await client.get_mobile_push_apns_tokens(.init()) | 
|  | 107 | + | 
|  | 108 | +        switch response { | 
|  | 109 | +        case .ok(let okResponse): | 
|  | 110 | +            let json = try okResponse.body.json | 
|  | 111 | +            let tokens = json.data | 
|  | 112 | + | 
|  | 113 | +            print("Found \(tokens?.count ?? 0) tokens") | 
|  | 114 | +            tokens?.forEach({ token in | 
|  | 115 | +                print("- token: \(token.data.device_token)") | 
|  | 116 | +            }) | 
|  | 117 | + | 
|  | 118 | +        case .undocumented(let statusCode, _): | 
|  | 119 | +            print("Undocumented status code: \(statusCode)") | 
|  | 120 | +        } | 
|  | 121 | +    } | 
|  | 122 | +} | 
|  | 123 | +``` | 
|  | 124 | + | 
|  | 125 | +## License | 
|  | 126 | + | 
|  | 127 | +This SDK is licensed under the MIT License. | 
|  | 128 | + | 
|  | 129 | +See the [LICENSE](LICENSE) file for more details. | 
0 commit comments