2017 © Pedro Peláez
 

symfony-bundle basecamp-bundle

Bundle around the Basecamp API client

image

netvlies/basecamp-bundle

Bundle around the Basecamp API client

  • Friday, June 14, 2013
  • by ricbra
  • Repository
  • 13 Watchers
  • 1 Stars
  • 40 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

NetvliesBasecampBundle

knpbundles.com, (*1)

Symfony2 bundle around the basecamp-php client. It provides an easy way to integrate the new Basecamp API in your project., (*2)

Installation

Use Composer to install the bundle:, (*3)

$ composer.phar require netvlies/basecamp-bundle

Enable the bunble in your kernel:, (*4)

// app/AppKernel.php
public function registerBundles()
{
    $bundles = array(
        // ...
        new Netvlies\Bundle\BasecampBundle\NetvliesBasecampBundle(),
    );
}

Configuration

This bundle supports authentication via HTTP authentication (easy and quick) or OAuth (a little bit more difficult)., (*5)

HTTP authentication

Below is an example of the minimal configuration using HTTP authentication. Only thing you need to do is supply your own credentials., (*6)

# app/config/config.yml
netvlies_basecamp:
    authentication: http
    app_name: My Funky Application
    app_contact: http://www.myfunkyapplication.com
    identification:
        user_id: 1234
        username: your@username.com
        password: secret

OAuth authentication

If you have a more advanced use case you probably want to use OAuth. To implement OAuth in your Symfony2 project we recommend the HWIOAuthBundle., (*7)

Create an OAuth credentials provider

First start by implementing the Netvlies\Bundle\BasecampBundle\OAuth\CredentialsProviderInterface. Below is an simple example assuming you store the OAuth data in your User entity:, (*8)


namespace Acme\Bundle\MainBundle\OAuth; use Netvlies\Bundle\BasecampBundle\OAuth\CredentialsProviderInterface; use Symfony\Component\Security\Core\SecurityContext; class BasecampCredentialsProvider implements CredentialsProviderInterface { protected $context; public function __construct(SecurityContext $context) { $this->context = $context; } public function getBasecampId() { if (! $this->context->isGranted('IS_AUTHENTICATED_FULLY')) { throw new \RuntimeException('Please login before using Basecamp'); } return $this->context->getToken()->getUser()->getBasecampId(); } public function getToken() { if (! $this->context->isGranted('IS_AUTHENTICATED_FULLY')) { throw new \RuntimeException('Please login before using Basecamp'); } return $this->context->getToken()->getUser()->getToken(); } }

Now register this as a service:, (*9)

services:
    acme.basecamp.oauth_credentials_provider:
        class: Acme\Bundle\MainBundle\OAuth\BasecampCredentialsProvider
        arguments: ["@security.context"]

Configure the bundle to use your provider

Finally supply the service id into the bundle configuration like this:, (*10)

netvlies_basecamp:
    authentication: oauth
    app_name: My Funky Application
    app_contact: http://www.myfunkyapplication.com
    oauth:
        credentials_provider: acme.basecamp.oauth_credentials_provider

Usage

You can now get the client from the container and use it:, (*11)

$client = $this->get('basecamp');
$project = $client->getProject(array(
    'projectId' => 1
));

The Versions

14/06 2013

dev-master

9999999-dev https://github.com/netvlies/NetvliesBasecampBundle

Bundle around the Basecamp API client

  Sources   Download

MIT

The Requires

 

by Richard van den Brand

api basecamp 37signals