承接 getsendstack/laravel-sendstack 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

getsendstack/laravel-sendstack

最新稳定版本:1.0.0

Composer 安装命令:

composer require getsendstack/laravel-sendstack

包简介

A Laravel Package to work with the SendStack API

README 文档

README

Latest Version on Packagist Test Suite Total Downloads

Installation

You can install the package via composer:

composer require getsendstack/laravel-sendstack

You can publish the config file with:

php artisan vendor:publish --tag="sendstack-config"

Set up

To start using this package, you need to add environment variables for:

  • SENDSTACK_URL - Optional, not really needed as this has a default
  • SENDSTACK_TOKEN - You can generate this from your getSendStack account.

The package will pick these up in its configuration and use these when it resolves an instance of the Client.

Usage

This package can be used by injecting the SendStack\Laravel\Http\Client into a method to instantiate the client:

declare(strict_types=1);

use App\Models\Subscriber;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use SendStack\Laravel\Contracts\ClientContract;

namespace App\Jobs\SendStack;

class SyncSubscribers implements ShouldQueue
{
    use Queueable;
    use Dispatchable;
    use SerializesModels;
    use InteractsWithQueue;
    
    public function handle(ClientContract $client): void
    {
        foreach ($client->subscribers()->all() as $subscriber) {
            Subscriber::query()->updateOrCreate(
                attributes: ['email' => $subscriber->email],
                values: $subscriber->toArray(),
            );
        }
    }
}

Alternatively you can use the Facade to help you:

declare(strict_types=1);

use App\Models\Subscriber;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use SendStack\Laravel\Facades\SendStack;

namespace App\Jobs\SendStack;

class SyncSubscribers implements ShouldQueue
{
    use Queueable;
    use Dispatchable;
    use SerializesModels;
    use InteractsWithQueue;
    
    public function handle(): void
    {
        foreach (SendStack::subscribers()->all() as $subscriber) {
            Subscriber::query()->updateOrCreate(
                attributes: ['email' => $subscriber->email],
                values: $subscriber->toArray(),
            );
        }
    }
}

Getting a list of Subscribers

use SendStack\Laravel\Contracts\ClientContract;
use SendStack\Laravel\Facades\SendStack;

/**
 * Without a Facade
 */
$client = app()->make(
    abstract: ClientContract::class,
);

$client->subscribers()->all();

/**
 * Using the Facade
 */
SendStack::subscribers()->all();

Getting a single Subscriber

use SendStack\Laravel\Contracts\ClientContract;
use SendStack\Laravel\Facades\SendStack;

/**
 * Without a Facade
 */
$client = app()->make(
    abstract: ClientContract::class,
);

$client->subscribers()->get(
    query: '1234-1234-1234-1234' // This can be either the subscribers UUID or their Email Address
);

/**
 * Using the Facade
 */
SendStack::subscribers()->get(
    query: '1234-1234-1234-1234', // This can be either the subscribers UUID or their Email Address
);

Creating a new Subscriber

use SendStack\Laravel\Contracts\ClientContract;
use SendStack\Laravel\Facades\SendStack;
use SendStack\Laravel\Http\Requests\SubscriberRequest;

/**
 * Without a Facade
 */
$client = app()->make(
    abstract: ClientContract::class,
);

$client->subscribers()->create(
    request: new SubscriberRequest(
        email: 'contact@getsendstack.com', // Required
        firstName: 'Send', // Optional
        lastName: 'Stack', // Optional
        tags: [
            'Client',
            'Awesome',
        ], // Optional
        optIn: true, // Optional
    ),
);

/**
 * Using the Facade
 */
SendStack::subscribers()->create(
    request: new SubscriberRequest(
        email: 'contact@getsendstack.com', // Required
        firstName: 'Send', // Optional
        lastName: 'Stack', // Optional
        tags: [
            'Client',
            'Awesome',
        ], // Optional
        optIn: true, // Optional
    ),
);

Update a Subscriber

use SendStack\Laravel\Contracts\ClientContract;
use SendStack\Laravel\Facades\SendStack;
use SendStack\Laravel\Http\Requests\SubscriberRequest;

/**
 * Without a Facade
 */
$client = app()->make(
    abstract: ClientContract::class,
);

$client->subscribers()->update(
    uuid: '1234-1234-1234-1234',
    request: new SubscriberRequest(
        email: 'contact@getsendstack.com', // Required
        firstName: 'Send', // Optional
        lastName: 'Stack', // Optional
        tags: [
            'Client',
            'Awesome',
        ], // Optional
        optIn: true, // Optional
    ),
);

/**
 * Using the Facade
 */
SendStack::subscribers()->update(
    uuid: '1234-1234-1234-1234',
    request: new SubscriberRequest(
        email: 'contact@getsendstack.com', // Required
        firstName: 'Send', // Optional
        lastName: 'Stack', // Optional
        tags: [
            'Client',
            'Awesome',
        ], // Optional
        optIn: true, // Optional
    ),
);

Deleting a Subscriber

use SendStack\Laravel\Contracts\ClientContract;
use SendStack\Laravel\Facades\SendStack;

/**
 * Without a Facade
 */
$client = app()->make(
    abstract: ClientContract::class,
);

$client->subscribers()->delete(
    uuid: '1234-1234-1234-1234'
);

/**
 * Using the Facade
 */
SendStack::subscribers()->delete(
    uuid: '1234-1234-1234-1234',
);

Attaching a Tag to a Subscriber

use SendStack\Laravel\Contracts\ClientContract;
use SendStack\Laravel\Facades\SendStack;

/**
 * Without a Facade
 */
$client = app()->make(
    abstract: ClientContract::class,
);

$client->subscribers()->attachTag(
    uuid: '1234-1234-1234-1234',
    tag: 'Early Access',
);

/**
 * Using the Facade
 */
SendStack::subscribers()->attachTag(
    uuid: '1234-1234-1234-1234',
    tag: 'Early Access',
);

Removing a Tag from a Subscriber

use SendStack\Laravel\Contracts\ClientContract;
use SendStack\Laravel\Facades\SendStack;

/**
 * Without a Facade
 */
$client = app()->make(
    abstract: ClientContract::class,
);

$client->subscribers()->removeTag(
    uuid: '1234-1234-1234-1234',
    tag: 'Early Access',
);

/**
 * Using the Facade
 */
SendStack::subscribers()->removeTag(
    uuid: '1234-1234-1234-1234',
    tag: 'Early Access',
);

Checking if an email address is an Active Subscriber

use SendStack\Laravel\Contracts\ClientContract;
use SendStack\Laravel\Facades\SendStack;

/**
 * Without a Facade
 */
$client = app()->make(
    abstract: ClientContract::class,
);

$client->isActiveSubscriber(
    email: 'taylor@laravel.com',
);

/**
 * Using the Facade
 */
SendStack::isActiveSubscriber(
    email: 'taylor@laravel.com',
);

Getting all Tags

use SendStack\Laravel\Contracts\ClientContract;
use SendStack\Laravel\Facades\SendStack;

/**
 * Without a Facade
 */
$client = app()->make(
    abstract: ClientContract::class,
);

$client->tags()->all();

/**
 * Using the Facade
 */
SendStack::tags()->all();

Creating a new Tag

use SendStack\Laravel\Contracts\ClientContract;
use SendStack\Laravel\Facades\SendStack;
use SendStack\Laravel\Http\Requests\TagRequest;

/**
 * Without a Facade
 */
$client = app()->make(
    abstract: ClientContract::class,
);

$client->tags()->create(
    request: new TagRequest(
        name: 'Test', // Required
        allowFormSubscription: true, // Optional
    ),
);

/**
 * Using the Facade
 */
SendStack::tags()->create(
    request: new TagRequest(
        name: 'Test', // Required
        allowFormSubscription: true, // Optional
    ),
);

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 423
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 11
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 11
  • Watchers: 3
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-08-19