Skip to content

Commit

Permalink
Merge pull request #37 from rdohms/parity-august-16
Browse files Browse the repository at this point in the history
Updating to API as of August 2016
  • Loading branch information
rdohms authored Aug 14, 2016
2 parents 346daa8 + d903225 commit 847f058
Show file tree
Hide file tree
Showing 33 changed files with 322 additions and 254 deletions.
5 changes: 0 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ php:
- 5.5
- 5.6
- 7.0
- hhvm

matrix:
allow_failures:
- php: hhvm

before_script:
- composer selfupdate
Expand Down
31 changes: 15 additions & 16 deletions src/DMS/Service/Meetup/AbstractMeetupClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@
namespace DMS\Service\Meetup;

use DMS\Service\Meetup\Plugin\RateLimitPlugin;
use DMS\Service\Meetup\Response\MultiResultResponse;
use DMS\Service\Meetup\Response\SingleResultResponse;
use Guzzle\Common\Collection;
use Guzzle\Service\Client;
use Guzzle\Service\Description\Operation;
use Guzzle\Service\Description\ServiceDescription;
use DMS\Service\Meetup\Response\SingleResultResponse;
use DMS\Service\Meetup\Response\MultiResultResponse;

/**
* Class AbstractMeetupClient
* Class AbstractMeetupClient.
*
* This is the foundation for the clients that implement proper Authentication methods.
*
* @package DMS\Service\Meetup
*
* @method SingleResultResponse createBatch(array $args = array())
* @method SingleResultResponse createEvent(array $args = array())
Expand Down Expand Up @@ -145,7 +144,7 @@
abstract class AbstractMeetupClient extends Client
{
/**
* Constructor
* Constructor.
*
* {@inheritdoc}
*/
Expand All @@ -155,7 +154,7 @@ public function __construct($baseUrl = '', $config = null)
}

/**
* Returns the default values for incoming configuration parameters
* Returns the default values for incoming configuration parameters.
*
* @return array
*/
Expand All @@ -165,7 +164,7 @@ public static function getDefaultParameters()
}

/**
* Defines the configuration parameters that are required for client
* Defines the configuration parameters that are required for client.
*
* @return array
*/
Expand All @@ -175,20 +174,21 @@ public static function getRequiredParameters()
}

/**
* Builds array of configurations into final config
* Builds array of configurations into final config.
*
* @param array $config
*
* @return Collection
*/
public static function buildConfig($config = array())
{
$default = static::getDefaultParameters();
$default = static::getDefaultParameters();
$required = static::getRequiredParameters();
$config = Collection::fromConfig($config, $default, $required);

$standardHeaders = array(
'Accept-Charset' => 'utf-8',
'Accept' => 'application/json',
'Accept' => 'application/json',
);

$requestOptions = array(
Expand All @@ -201,16 +201,16 @@ public static function buildConfig($config = array())
}

/**
* Loads API method definitions
* Loads API method definitions.
*
* @param \Guzzle\Service\Client $client
*/
public static function loadDefinitions(Client $client)
{
$serviceDescriptions = ServiceDescription::factory(__DIR__ . '/Resources/config/meetup.json');
$serviceDescriptions = ServiceDescription::factory(__DIR__.'/Resources/config/meetup.json');

foreach ($serviceDescriptions->getOperations() as $operation) {
/** @var $operation Operation */
/* @var $operation Operation */
$operation->setClass('DMS\Service\Meetup\Command\MeetupCommand');
}

Expand All @@ -227,18 +227,17 @@ public static function toggleRateLimitingPlugin(Client $client, $config)
return;
}

$rateFactor = (array_key_exists('rate_limit_factor', $config))? $config['rate_limit_factor'] : null;
$rateFactor = (array_key_exists('rate_limit_factor', $config)) ? $config['rate_limit_factor'] : null;
$client->addSubscriber(new RateLimitPlugin($rateFactor));
}

/**
* Shortcut for executing Commands in the Definitions.
*
* @param string $method
* @param array $args
* @param array $args
*
* @return mixed|void
*
*/
public function __call($method, $args)
{
Expand Down
6 changes: 2 additions & 4 deletions src/DMS/Service/Meetup/Command/MeetupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
use Guzzle\Service\Command\ResponseParserInterface;

/**
* Class MeetupCommand
* Class MeetupCommand.
*
* Custom Command Class that allows us to parse into
* custom Responses
*
* @package DMS\Service\Meetup\Command
*/
class MeetupCommand extends OperationCommand
{
Expand All @@ -22,7 +20,7 @@ class MeetupCommand extends OperationCommand
*/
public function getResponseParser()
{
if ( ! $this->responseParser) {
if (!$this->responseParser) {
$this->responseParser = MeetupResponseParser::getInstance();
}

Expand Down
19 changes: 12 additions & 7 deletions src/DMS/Service/Meetup/Command/MeetupResponseParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
class MeetupResponseParser extends DefaultResponseParser
{
/**
* Get a cached instance of the default response parser
* Get a cached instance of the default response parser.
*
* @return self
* @codeCoverageIgnore
*/
public static function getInstance()
{
if (!self::$instance) {
self::$instance = new self;
self::$instance = new self();
}

return self::$instance;
Expand All @@ -28,20 +29,21 @@ public static function getInstance()
* {@inheritdoc}
*
* @param CommandInterface $command
*
* @return array|MultiResultResponse|SingleResultResponse|Response|mixed
*/
public function parse(CommandInterface $command)
{
$response = $command->getRequest()->getResponse();

if ($response === null) {
return null;
return;
}

$responseArray = $this->parseResponseIntoArray($response);

// If there is no Body, just return the Response
if (! $response->getBody()) {
if (!$response->getBody()) {
return $response;
}

Expand All @@ -54,9 +56,10 @@ public function parse(CommandInterface $command)
}

/**
* Create a Multi-Response Object
* Create a Multi-Response Object.
*
* @param Response $response
*
* @return \DMS\Service\Meetup\Response\MultiResultResponse
*/
protected function createMultiResultResponse($response)
Expand All @@ -67,9 +70,10 @@ protected function createMultiResultResponse($response)
}

/**
* Create a Single-Response Object
* Create a Single-Response Object.
*
* @param Response $response
*
* @return \DMS\Service\Meetup\Response\SingleResultResponse
*/
protected function createSingleResultResponse($response)
Expand All @@ -80,9 +84,10 @@ protected function createSingleResultResponse($response)
}

/**
* Parses response into an array
* Parses response into an array.
*
* @param Response $response
*
* @return array
*/
protected function parseResponseIntoArray($response)
Expand Down
6 changes: 3 additions & 3 deletions src/DMS/Service/Meetup/MeetupKeyAuthClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
use DMS\Service\Meetup\Plugin\KeyAuthPlugin;

/**
* Meetup.com API Client based on simple key authentication
* Meetup.com API Client based on simple key authentication.
*
* Docs: API key as a parameter -- for server-side apps acting on behalf of a single user.
*
* @link http://www.meetup.com/meetup_api/auth/
* @package DMS\Service\Meetup
*/
class MeetupKeyAuthClient extends AbstractMeetupClient
{
Expand Down Expand Up @@ -38,9 +37,10 @@ public static function getRequiredParameters()
}

/**
* Factory Method to build new Client
* Factory Method to build new Client.
*
* @param array $config
*
* @return MeetupKeyAuthClient
*/
public static function factory($config = array())
Expand Down
10 changes: 5 additions & 5 deletions src/DMS/Service/Meetup/MeetupOAuthClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
use Guzzle\Plugin\Oauth\OauthPlugin;

/**
* Meetup.com API Client based on OAuth 1.0
* Meetup.com API Client based on OAuth 1.0.
*
* Docs: OAuth 1.0a signed requests -- for apps that carry out actions for many Meetup users.
*
* @link http://www.meetup.com/meetup_api/auth/
* @package DMS\Service\Meetup
*/
class MeetupOAuthClient extends AbstractMeetupClient
{
Expand All @@ -37,14 +36,15 @@ public static function getRequiredParameters()
return array(
'consumer_key',
'consumer_secret',
'base_url'
'base_url',
);
}

/**
* Factory Method to build new Client
* Factory Method to build new Client.
*
* @param array $config
*
* @return MeetupOAuthClient
*/
public static function factory($config = array())
Expand All @@ -59,7 +59,7 @@ public static function factory($config = array())
'consumer_key' => $configuration->get('consumer_key'),
'consumer_secret' => $configuration->get('consumer_secret'),
'token' => $configuration->get('token'),
'token_secret' => $configuration->get('token_secret')
'token_secret' => $configuration->get('token_secret'),
)
)
);
Expand Down
14 changes: 6 additions & 8 deletions src/DMS/Service/Meetup/Plugin/KeyAuthPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
* Class KeyAuthPlugin
* Class KeyAuthPlugin.
*
* This Guzzle plugin implements Key based authorization that is supported by the Meetup.com API
*
* @package DMS\Service\Meetup\Plugin
*/
class KeyAuthPlugin implements EventSubscriberInterface
{
protected $key;

/**
* Constructor
* Constructor.
*
* @param $key
*/
Expand Down Expand Up @@ -50,14 +48,15 @@ public function __construct($key)
public static function getSubscribedEvents()
{
return array(
'request.before_send' => array('onRequestBeforeSend', -1000)
'request.before_send' => array('onRequestBeforeSend', -1000),
);
}

/**
* Request before-send event handler
* Request before-send event handler.
*
* @param Event $event Event received
*
* @return array
*/
public function onRequestBeforeSend(Event $event)
Expand All @@ -66,11 +65,10 @@ public function onRequestBeforeSend(Event $event)
$request = $event['request'];

$this->signRequest($request);
return;
}

/**
* Adds "key" parameters as a Query Parameter
* Adds "key" parameters as a Query Parameter.
*
* @param Request $request
*/
Expand Down
Loading

0 comments on commit 847f058

Please sign in to comment.