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

Rd Station Bundle Laravel Package

baconmanager/rd-station-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require baconmanager/rd-station-bundle
    
  2. Register Bundle: Add to config/bundles.php (Symfony 4+) or AppKernel.php (Symfony 2/3):

    Bacon\Bundle\CoreBundle\BaconRDStationBundle::class => ['all' => true],
    
  3. Configure API Credentials: Add to config/packages/bacon_rd_station.yaml (Symfony 4+) or config.yml:

    bacon_rd_station:
        api:
            private_token: "%env(RD_STATION_PRIVATE_TOKEN)%"
            token: "%env(RD_STATION_TOKEN)%"
    

    Store tokens in .env for security.

  4. First Use Case: Inject the service and test a lead creation:

    use Bacon\Bundle\CoreBundle\Service\RDStationAPI;
    
    class LeadController extends AbstractController
    {
        public function createLead(RDStationAPI $rdStation): JsonResponse
        {
            $response = $rdStation->api('conversions', 'POST', [
                'email' => 'user@example.com',
                'nome'  => 'Test Lead'
            ]);
            return $this->json($response);
        }
    }
    

Implementation Patterns

Core Workflows

  1. Lead Management:

    • Create/Update Leads: Use api('conversions', 'POST/PUT', $leadData) for lead lifecycle management.
      $leadData = [
          'email' => 'user@example.com',
          'nome'  => 'John Doe',
          'phone' => '1234567890',
          'tags'  => ['prospect', 'high-value']
      ];
      $rdStation->api('conversions', 'POST', $leadData);
      
    • Fetch Leads: Use api('conversions', 'GET', ['email' => 'user@example.com']) for retrieval.
  2. Event Tracking:

    • Log events (e.g., page views, form submissions) via:
      $rdStation->api('events', 'POST', [
          'leadId' => 123,
          'event'  => 'page_view',
          'url'    => '/contact'
      ]);
      
  3. Batch Operations:

    • Use api('conversions', 'POST', $leadsArray) to send multiple leads in a single call (if supported by RD Station API).

Integration Tips

  • Dependency Injection: Prefer constructor injection for RDStationAPI in controllers/services:
    public function __construct(private RDStationAPI $rdStation) {}
    
  • Error Handling: Wrap API calls in try-catch blocks to handle RD Station API errors gracefully:
    try {
        $response = $rdStation->api('conversions', 'POST', $data);
    } catch (\Exception $e) {
        $this->addFlash('error', 'RD Station API Error: ' . $e->getMessage());
    }
    
  • Configuration: Extend config/packages/bacon_rd_station.yaml for environment-specific settings (e.g., sandbox vs. production tokens):
    bacon_rd_station:
        api:
            private_token: "%env(RD_STATION_SANDBOX_TOKEN)%"
            token: "%env(RD_STATION_SANDBOX_TOKEN)%"
            sandbox: true  # Add if the bundle supports sandbox mode
    

Gotchas and Tips

Pitfalls

  1. Token Security:

    • Never hardcode tokens in config files. Always use .env and %env().
    • Validate tokens post-deployment to avoid 401 errors:
      $rdStation->api('conversions', 'GET', ['email' => 'test@example.com']);
      
      Check for 401 Unauthorized responses.
  2. Rate Limiting:

    • RD Station API has rate limits. Implement exponential backoff for retries:
      $attempts = 0;
      $maxAttempts = 3;
      while ($attempts < $maxAttempts) {
          try {
              $response = $rdStation->api('conversions', 'POST', $data);
              break;
          } catch (\Exception $e) {
              $attempts++;
              if ($attempts === $maxAttempts) throw $e;
              sleep(2 ** $attempts); // Exponential backoff
          }
      }
      
  3. Data Validation:

    • RD Station API rejects malformed data. Validate inputs before sending:
      $requiredFields = ['email', 'nome'];
      foreach ($requiredFields as $field) {
          if (empty($data[$field])) {
              throw new \InvalidArgumentException("Missing required field: $field");
          }
      }
      
  4. Deprecation:

    • The bundle is Symfony 2/3-focused (no Symfony 4+ support). Test thoroughly if upgrading.

Debugging

  • Enable API Debugging: Add a debug flag to config/packages/bacon_rd_station.yaml:

    bacon_rd_station:
        debug: true
    

    Check logs for raw API responses (if the bundle supports it).

  • Common Errors:

    • 400 Bad Request: Validate payload structure (e.g., nome must be a string).
    • 404 Not Found: Verify endpoint (e.g., conversions vs. leads).
    • 500 Server Error: Contact RD Station support or check their status page.

Extension Points

  1. Custom Endpoints: Extend the bundle by creating a decorator service:

    # config/services.yaml
    Bacon\Bundle\CoreBundle\Service\RDStationAPI:
        decorates: 'bacon_rd_station.api'
        arguments: ['@bacon_rd_station.api.decorated']
    

    Implement custom logic in the decorator (e.g., logging, transformation).

  2. Event Listeners: Subscribe to bundle events (if available) to intercept API calls:

    // src/EventListener/RDStationListener.php
    public static function getSubscribedEvents()
    {
        return [
            'bacon_rd_station.api.call' => 'onApiCall',
        ];
    }
    
  3. Testing: Mock the RDStationAPI service in PHPUnit:

    $this->createMock(RDStationAPI::class)
         ->method('api')
         ->willReturn(['success' => true]);
    
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky