|
| 1 | + <div align="center"> |
| 2 | + <img |
| 3 | + src="https://raw.githubusercontent.com/recombee/.github/refs/heads/main/assets/mark.svg" |
| 4 | + width="64px" |
| 5 | + align="center" |
| 6 | + alt="Recombee" |
| 7 | + /> |
| 8 | + <br /> |
| 9 | + <h1>Recombee Swift API Client</h1> |
| 10 | +</div> |
| 11 | + |
| 12 | +<p align="center"> |
| 13 | +<a href="https://swiftpackageindex.com/recombee/swift-api-client" rel="nofollow"><img src="https://img.shields.io/badge/SwiftPM-Compatible-brightgreen.svg" alt="SwiftPM"></a> |
| 14 | +<a href="https://opensource.org/licenses/MIT" rel="nofollow"><img src="https://img.shields.io/github/license/recombee/swift-api-client" alt="License"></a> |
| 15 | +</p> |
| 16 | + |
| 17 | +<div align="center"> |
| 18 | + <a href="https://docs.recombee.com/swift_client">Documentation</a> |
| 19 | + <span> • </span> |
| 20 | + <a href="https://github.com/recombee/swift-api-client/issues/new">Issues</a> |
| 21 | + <span> • </span> |
| 22 | + < a href= "mailto:[email protected]">Support</ a> |
| 23 | + <br /> |
| 24 | +</div> |
| 25 | + |
| 26 | +## ✨ Features |
| 27 | + |
| 28 | +- Thin Swift wrapper around the Recombee API |
| 29 | +- Supports following endpoints: [Interactions](https://docs.recombee.com/api#user-item-interactions), [Recommendations](https://docs.recombee.com/api#recommendations), [Search](https://docs.recombee.com/api#search), and more |
| 30 | +- Fully async/await enabled for modern iOS development |
| 31 | +- Typed request/response interfaces with JSON decoding helpers |
| 32 | + |
| 33 | +## 🚀 Getting Started |
| 34 | + |
| 35 | +Add the dependency to your Xcode project using **Swift Package Manager**: |
| 36 | + |
| 37 | +1. In Xcode, go to `File → Add Packages` |
| 38 | +2. Enter the repository URL: |
| 39 | + |
| 40 | +``` |
| 41 | +https://github.com/recombee/swift-api-client |
| 42 | +``` |
| 43 | + |
| 44 | +3. Choose the latest version and confirm |
| 45 | + |
| 46 | +Alternatively, in `Package.swift`: |
| 47 | + |
| 48 | +```swift |
| 49 | +.package(url: "https://github.com/recombee/swift-api-client", from: "5.0.0") |
| 50 | +``` |
| 51 | + |
| 52 | +Then add to your target dependencies: |
| 53 | + |
| 54 | +```swift |
| 55 | +.target( |
| 56 | + name: "MyApp", |
| 57 | + dependencies: ["RecombeeClient"] |
| 58 | +) |
| 59 | +``` |
| 60 | + |
| 61 | +## 🏗️ Example |
| 62 | + |
| 63 | +You can send user-item interactions and receive recommendations like this: |
| 64 | + |
| 65 | +```swift |
| 66 | +import RecombeeClient |
| 67 | + |
| 68 | +// Initialize the API client with the ID of your database and the associated PUBLIC token |
| 69 | +let client = RecombeeClient( |
| 70 | + databaseId: "your-database-id", |
| 71 | + publicToken: "...db-public-token...", |
| 72 | + region: .euWest // the region of your database |
| 73 | +) |
| 74 | + |
| 75 | +do { |
| 76 | + // Send interactions |
| 77 | + try await client.send( |
| 78 | + AddDetailView( |
| 79 | + userId: "user-4395", |
| 80 | + itemId: "item-129", |
| 81 | + recommId: "23eaa09b-0e24-4487-ba9c-8e255feb01bb" |
| 82 | + ) |
| 83 | + ) |
| 84 | + |
| 85 | + // Request recommendations |
| 86 | + let response = try await client.send( |
| 87 | + RecommendItemsToUser( |
| 88 | + userId: "user-x", |
| 89 | + count: 10, |
| 90 | + scenario: "homepage-top-for-you", |
| 91 | + returnProperties: true, |
| 92 | + includedProperties: ["title"] |
| 93 | + ) |
| 94 | + ) |
| 95 | + |
| 96 | + // `recommId` needs to be sent with interactions based on recommendations |
| 97 | + print("recommId: \(response.recommId)") |
| 98 | + |
| 99 | + // The `recomms` object contains the `id` (and `values` if `returnProperties` is true) |
| 100 | + for item in response.recomms { |
| 101 | + let title = item.values?["title"] as? String ?? "(unknown)" |
| 102 | + print("ID: \(item.id), Title: \(title)") |
| 103 | + } |
| 104 | + |
| 105 | +} catch let error as ClientError { |
| 106 | + print("ClientError: \(error.errorDescription ?? "Unknown error")") |
| 107 | + // Ideally, provide a fallback if an error occurs... |
| 108 | +} catch { |
| 109 | + print("Unexpected error: \(error.localizedDescription)") |
| 110 | +} |
| 111 | +``` |
| 112 | + |
| 113 | +## 📝 Documentation |
| 114 | + |
| 115 | +Discover the full [Swift API Client documentation](https://docs.recombee.com/swift_client) for comprehensive guides and examples. |
| 116 | + |
| 117 | +For a complete breakdown of all endpoints and their responses, check out our [API Reference](https://docs.recombee.com/api). |
| 118 | + |
| 119 | +## 🤝 Contributing |
| 120 | + |
| 121 | +We welcome all contributions—whether it’s fixing a bug, improving documentation, or suggesting a new feature. |
| 122 | + |
| 123 | +To contribute, simply fork the repository, make your changes, and submit a pull request. Be sure to provide a clear description of your changes. |
| 124 | + |
| 125 | +Thanks for helping make this project better! |
| 126 | + |
| 127 | +## 🔧 Troubleshooting |
| 128 | + |
| 129 | +Are you having issues? We recommend checking [our documentation](https://docs.recombee.com/swift_client) to see if it contains a possible solution. |
| 130 | + |
| 131 | +If you want to reach out, you can either [open a GitHub issue ](https://github.com/recombee/swift-api-client/issues/new) or send an email to [email protected]. |
| 132 | + |
| 133 | + |
| 134 | +We're happy to help! |
| 135 | + |
| 136 | +## 📄 License |
| 137 | + |
| 138 | +The Recombee Swift API Client is provided under the [MIT License](https://opensource.org/licenses/MIT). |
0 commit comments