SmsHubAPI is a Swift library that provides an easy-to-use interface for interacting with the SmsHub API. With this library, you can access various SmsHub services, such as getting your account balance, purchasing a phone number, setting and retrieving the status of an activation, and more.
- Swift concurrency support with async/await
- Simple, protocol-based API
- Lightweight and modular
- iOS 15.0+
- Swift 5.6+
Add the library to your project using Swift Package Manager:
- Open your project in Xcode.
- Go to File > Swift Packages > Add Package Dependency.
- Enter the repository URL
https://github.com/DeveloperZelentsov/SMSHubAPI
for the SmsHubAPI library and click Next. - Choose the latest available version and click Next.
- Select the target where you want to use SmsHubAPI and click Finish.
First, import the SmsHubAPI library in your Swift file:
import SmsHubAPI
To start using the library, create an instance of SmsHubAPI with your API key:
let smsHubAPI = SmsHubAPI(apiKey: "your_api_key_here")
Now, you can call the methods provided by the SmsHubAPI protocol:
do {
let balance = try await smsHubAPI.getBalance()
print("Account balance: \(balance)")
} catch {
print("Error: \(error)")
}
let getNumber = GetNumberRequest(service: .nextdoor, country: .usa)
do {
let (id, phone) = try await smsHubAPI.purchasePhoneNumber(by: getNumber)
print("Purchased phone number: \(phone) with ID: \(id)")
} catch {
print("Error: \(error)")
}
The waitForCode
method can be used to conveniently retrieve the SMS verification code for an activation. This method will repeatedly check the activation status until the code is received or the specified number of attempts is exhausted.
do {
let activationId = 12345
let code = try await smsHubAPI.waitForCode(id: activationId, attempts: 20, setStatusAfterCompletion: true)
print("Received code: \(code)")
} catch {
print("Error: \(error)")
}
do {
let response = try await smsHubAPI.setStatus(id: activationId, status: .smsSent)
print("Status set response: \(response)")
} catch {
print("Error: \(error)")
}
do {
let (status, code) = try await smsHubAPI.getStatus(id: activationId)
print("Activation status: \(status)")
if let code = code {
print("Activation code: \(code)")
}
} catch {
print("Error: \(error)")
}
For more information on the available methods and their parameters, refer to the ISmsHubAPI protocol and the library's source code.
This project is released under the MIT License.