Swiftpack.co - Package - vapor-community/gatewayapi

GatewayAPI

Swift 5.2 Vapor 4

GatewayAPI is a Vapor helper for using GatewayAPIKit to send text messages (SMS) to mobile phones.

Installation

GatewayAPI is installed using Swift Package Manager, please modify your Package.swift to include the following code:

dependencies: [
    ...
    .package(url: "https://github.com/vapor-community/gatewayapi.git", from: "1.0.0-rc.1")
],
...
targets: [
    .target(
        name: ...
        dependencies: [
            ...
            .product(name: "GatewayAPI", package: "gatewayapi")
        ]
    )
]

Usage

Make you sure you create an account over at GatewayAPI

Configuration

In your configure.swift add one of the following configuration options:

import GatewayAPI

func configure(_ app: Application) throws {
    // Option 1: Use environment variable GATEWAYAPI_APIKEY
    app.gatewayAPI.configuration = .environment

    // Option 2: Manual config  
    app.gatewayAPI.configuration = .init(apiKey: "api_key")
}

Sending a SMS

You can use the API client either through Application or Request

Application

import GatewayAPI

func configure(_ app: Application) throws {
    app.gatewayAPI.configuration = .environment

    _ = app.gatewayAPI.client.send("Text message": to: ["4510203040"], from: "Mads")
}

Request (inside controller)

import GatewayAPI

func sendSMS(req: Request) throws -> EventLoopFuture<Void> {
    return req.gatewayAPI.send("Text message": to: ["4510203040"], from: "Mads").transform(to: ())
}

Github

link
Stars: 0

Used By

Total: 0

Releases

GatewayAPI - 1.0.0 RC 1 - 2020-03-19 16:59:03

Release candidate for Vapor 4 RC