Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Drip Php Laravel Package

glorand/drip-php

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install via Composer:

    composer require glorand/drip-php
    
  2. Configure API Key: Add your Drip API key to .env:

    DRIP_API_KEY=your_api_key_here
    

    Or set it programmatically:

    $drip = new \Glorand\Drip\Client('your_api_key_here');
    
  3. First Use Case: Fetch a subscriber by email:

    $subscriber = $drip->subscribers()->getByEmail('user@example.com');
    

Where to Look First

  • Documentation: The README includes basic usage examples.
  • Source Code: The src directory outlines the API structure (e.g., Subscribers, Campaigns, Tags).
  • Tests: The tests folder demonstrates real-world usage patterns.

Implementation Patterns

Core Workflows

  1. Subscriber Management:

    • Create/Update:
      $subscriber = $drip->subscribers()->createOrUpdate([
          'email' => 'user@example.com',
          'tags'  => ['vip', 'newsletter'],
          'custom_fields' => ['plan' => 'premium']
      ]);
      
    • Bulk Operations:
      $drip->subscribers()->bulkCreate([
          ['email' => 'user1@example.com', 'tags' => ['tag1']],
          ['email' => 'user2@example.com', 'tags' => ['tag2']],
      ]);
      
  2. Campaigns:

    • Trigger a Campaign:
      $drip->campaigns()->trigger('welcome_email', ['user@example.com']);
      
    • List Campaigns:
      $campaigns = $drip->campaigns()->all();
      
  3. Tags and Segments:

    • Add/Remove Tags:
      $drip->subscribers()->addTags('user@example.com', ['new_tag']);
      $drip->subscribers()->removeTags('user@example.com', ['old_tag']);
      
    • List Subscribers by Tag:
      $subscribers = $drip->subscribers()->getByTag('vip');
      
  4. Webhooks:

    • Subscribe to Events:
      $drip->webhooks()->subscribe('https://your-app.com/drip/webhook', [
          'subscriber.created',
          'subscriber.updated'
      ]);
      

Integration Tips

  • Laravel Service Provider: Bind the client to the container for easy dependency injection:

    // app/Providers/AppServiceProvider.php
    public function register()
    {
        $this->app->singleton(\Glorand\Drip\Client::class, function ($app) {
            return new \Glorand\Drip\Client(config('services.drip.key'));
        });
    }
    

    Configure in config/services.php:

    'drip' => [
        'key' => env('DRIP_API_KEY'),
    ],
    
  • Queued Jobs: Offload Drip API calls to queues (e.g., Laravel Queues) to avoid timeouts:

    // app/Jobs/SyncDripSubscriber.php
    public function handle()
    {
        $drip = app(\Glorand\Drip\Client::class);
        $drip->subscribers()->createOrUpdate($this->subscriberData);
    }
    
  • Event Listeners: Sync Drip subscribers on user registration/login:

    // app/Listeners/SyncDripSubscriber.php
    public function handle(Registered $event)
    {
        $drip = app(\Glorand\Drip\Client::class);
        $drip->subscribers()->createOrUpdate([
            'email' => $event->user->email,
            'custom_fields' => ['user_id' => $event->user->id],
        ]);
    }
    

Gotchas and Tips

Pitfalls

  1. Deprecated API:

    • The package wraps Drip's REST API v2.0, which may have deprecated endpoints. Check Drip's API docs for breaking changes.
    • Example: Some endpoints (e.g., /subscribers/search) may require pagination handling manually.
  2. Rate Limiting:

    • Drip’s API has rate limits. Cache responses aggressively:
      $subscribers = Cache::remember("drip_subscribers_tag_{$tag}", now()->addHours(1), function () use ($drip, $tag) {
          return $drip->subscribers()->getByTag($tag);
      });
      
  3. Error Handling:

    • The package throws \Glorand\Drip\Exceptions\DripException for API errors. Catch and log them:
      try {
          $drip->subscribers()->createOrUpdate($data);
      } catch (\Glorand\Drip\Exceptions\DripException $e) {
          Log::error("Drip API error: " . $e->getMessage());
          // Retry or notify admin
      }
      
  4. Custom Fields:

    • Custom fields must be defined in Drip’s dashboard first. The package won’t create them dynamically.
  5. Webhook Verification:

    • Always verify webhook signatures to avoid spoofing:
      // In your webhook endpoint
      $signature = $_SERVER['HTTP_X_DRIP_SIGNATURE'];
      $payload = file_get_contents('php://input');
      if (!hash_equals($signature, hash_hmac('sha256', $payload, config('services.drip.webhook_secret')))) {
          abort(403, 'Invalid signature');
      }
      

Debugging Tips

  • Enable Debug Mode:

    $drip = new \Glorand\Drip\Client('your_api_key', [
        'debug' => true, // Logs all API requests/responses
    ]);
    

    Check logs for raw API calls/responses.

  • Mocking for Tests: Use Laravel’s HTTP client to mock Drip responses:

    // tests/Feature/DripTest.php
    public function test_subscriber_creation()
    {
        $mockResponse = ['email' => 'user@example.com', 'id' => 123];
        Http::fake([
            'api.getdrip.com/*' => Http::response($mockResponse, 200),
        ]);
    
        $subscriber = $drip->subscribers()->createOrUpdate(['email' => 'user@example.com']);
        $this->assertEquals(123, $subscriber['id']);
    }
    

Extension Points

  1. Custom Endpoints: The Client class extends GuzzleHttp\Client, so you can add custom endpoints:

    $drip->get('custom/endpoint', ['query' => ['param' => 'value']]);
    
  2. Middleware: Add request/response middleware for logging, retries, or transformations:

    $drip->getEmitter()->addSubscriber(new class implements SubscriberInterface {
        public function handle(Message $message, callable $next) {
            // Pre-process request
            $response = $next($message);
            // Post-process response
            return $response;
        }
    });
    
  3. Laravel Facades: Create a facade for cleaner syntax:

    // app/Facades/Drip.php
    class Drip extends Facade {
        protected static function getFacadeAccessor() { return 'drip'; }
    }
    

    Then use:

    Drip::subscribers()->getByEmail('user@example.com');
    
  4. Batch Processing: For large datasets, implement chunked processing:

    $subscribers = $drip->subscribers()->all(['limit' => 100]);
    foreach (array_chunk($subscribers, 50) as $chunk) {
        $drip->subscribers()->bulkUpdate($chunk, ['tags' => ['new_tag']]);
    }
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours