Skip to content

DeveloperZelentsov/SMSHubAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SmsHubAPI Swift Library

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.

Buy me a coffee

Features

  • Swift concurrency support with async/await
  • Simple, protocol-based API
  • Lightweight and modular

Requirements

  • iOS 15.0+
  • Swift 5.6+

Installation

Add the library to your project using Swift Package Manager:

  1. Open your project in Xcode.
  2. Go to File > Swift Packages > Add Package Dependency.
  3. Enter the repository URL https://github.com/DeveloperZelentsov/SMSHubAPI for the SmsHubAPI library and click Next.
  4. Choose the latest available version and click Next.
  5. Select the target where you want to use SmsHubAPI and click Finish.

Usage

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:

Get Account Balance

do {
    let balance = try await smsHubAPI.getBalance()
    print("Account balance: \(balance)")
} catch {
    print("Error: \(error)")
}

Purchase Phone Number

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)")
}

Wait for Code

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)")
}

Set Activation Status

do {
    let response = try await smsHubAPI.setStatus(id: activationId, status: .smsSent)
    print("Status set response: \(response)")
} catch {
    print("Error: \(error)")
}

Get Activation Status

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.

License

This project is released under the MIT License.