Skip to content

vapor-community/gatewayapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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: ())
}

About

A Vapor provider for using GatewayAPI for sending SMS

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages