batch

package module
v0.0.0-...-06d02e5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2018 License: MIT Imports: 5 Imported by: 0

README

Go Report Card GoDoc license

Go Batch

This is a simple API client to send push notifications using Batch.

Installation

go get github.com/mamal72/go-batch
# or use dep, glide, vgo or whatever you like

Usage

package main

import "github.com/mamal72/go-batch"

func main() {
    client := batch.NewClient("YOUR_BATCH_REST_API_KEY", "YOUR_BATCH_API_KEY_FOR_YOUR_APP")
    payload := batch.TransactionalPushPayload{
        GroupID: "SOME_GROUP_ID",
        Recipients: batch.TransactionalPushRecipient{
            CustomIDs: []string{"1", "2"},
            // blah blah blah
        },
        Message: batch.TransactionalPushMessage{
            Title: "Greeting",
            Body:  "Hello dear user!",
        },
        // blah blah blah
    }

    response, err := client.TransactionalSend(payload)
    // handle error or get and store token from response
}

Ideas || Issues

Just fill an issue and describe it. I'll check it ASAP!

Contribution

You can fork the repository, improve or fix some part of it and then send the pull requests back if you want to see them here. I really appreciate that. ❤

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIClient

type APIClient struct {
	RESTAPIKey  string
	BatchAPIKey string
}

APIClient is the main struct for handling all batch API calls

func NewClient

func NewClient(restAPIKey, batchAPIKey string) APIClient

NewClient returns a new instance of batch api client

func (*APIClient) TransactionalSend

func (b *APIClient) TransactionalSend(payload TransactionalPushPayload) (TransactionalPushResponse, error)

TransactionalSend sends a transactional push notification and returns token in case of success See https://batch.com/doc/api/transactional.html

type TransactionalPushMessage

type TransactionalPushMessage struct {
	Title string `json:"title,omitempty"`
	Body  string `json:"body"`
}

TransactionalPushMessage is a struct containing message title and body See https://batch.com/doc/api/transactional.html#_post-data

type TransactionalPushPayload

type TransactionalPushPayload struct {
	GroupID    string                     `json:"group_id"`
	Labels     []string                   `json:"labels,omitempty"`
	Priority   TransactionalPushPriority  `json:"priority,omitempty"`
	Recipients TransactionalPushRecipient `json:"recipients"`
	Message    TransactionalPushMessage   `json:"message"`
	Deeplink   string                     `json:"deeplink,omitempty"`
}

TransactionalPushPayload TBA See https://batch.com/doc/api/transactional.html#_post-data

type TransactionalPushPriority

type TransactionalPushPriority string

TransactionalPushPriority is a string aliased type for transtional push notifications priority See https://batch.com/doc/api/transactional.html#_post-data

const HighPriority TransactionalPushPriority = "high"

HighPriority is high transactional push priority constant

const NormalPriority TransactionalPushPriority = "normal"

NormalPriority is normal transactional push priority constant

type TransactionalPushRecipient

type TransactionalPushRecipient struct {
	Tokens     []string `json:"tokens,omitempty"`
	CustomIDs  []string `json:"custom_ids,omitempty"`
	InstallIDs []string `json:"install_ids,omitempty"`
}

TransactionalPushRecipient is a sturct containing tokens, custom ids and install ids of recipients See https://batch.com/doc/api/transactional.html#_post-data

type TransactionalPushResponse

type TransactionalPushResponse struct {
	Token string `json:"token"`
}

TransactionalPushResponse is the response type of transactional push notifications See https://batch.com/doc/api/transactional.html#_responses

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL