Skip to content

Commit

Permalink
[fix] issue #45 - make the group_urlname configurable
Browse files Browse the repository at this point in the history
- abstracted the AbstractService::__constructor()
- abstracted common methods: AbstractService::getApi(), AbstractService::getCache()
- no changes to .gitignore

Conflicts: src/AmsterdamPHP/Bundle/MeetupBundle/Service/EventService.php
  • Loading branch information
madmanmax committed Nov 22, 2014
2 parents e8ff233 + cc74a7f commit 75bf9b0
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 126 deletions.
1 change: 1 addition & 0 deletions app/config/parameters.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ parameters:

meetup_key:
akismet_key:
group_urlname:
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@ services:
arguments:
client: @dms_meetup_api.key_client
cache: @snc_redis.cache
group: %group_urlname%

meetup.sponsors:
class: %meetup.sponsors.class%
arguments:
client: @dms_meetup_api.key_client
cache: @snc_redis.cache
group: %group_urlname%

meetup.events:
class: %meetup.events.class%
arguments:
client: @dms_meetup_api.key_client
cache: @snc_redis.cache
group: %group_urlname%

meetup.twig.photos:
class: %meetup.twig.photos.class%
Expand Down
51 changes: 51 additions & 0 deletions src/AmsterdamPHP/Bundle/MeetupBundle/Service/AbstractService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace AmsterdamPHP\Bundle\MeetupBundle\Service;

use DMS\Service\Meetup\AbstractMeetupClient;
use Predis\Client;

class AbstractService {
/**
* @var \DMS\Service\Meetup\AbstractMeetupClient
*/
protected $api;

/**
* @var Client
*/
protected $cache;

/**
* @var string
*/
protected $group;

/**
* @param AbstractMeetupClient $api
* @param \Predis\Client $cache
* @param string $group path to group on meetup.com
*/
public function __construct(AbstractMeetupClient $api, Client $cache, $group)
{
$this->api = $api;
$this->cache = $cache;
$this->group = $group;
}

/**
* @return \DMS\Service\Meetup\AbstractMeetupClient
*/
public function getApi()
{
return $this->api;
}

/**
* @return \Predis\Client
*/
public function getCache()
{
return $this->cache;
}
}
46 changes: 3 additions & 43 deletions src/AmsterdamPHP/Bundle/MeetupBundle/Service/EventService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,11 @@

namespace AmsterdamPHP\Bundle\MeetupBundle\Service;

use DMS\Service\Meetup\AbstractMeetupClient;
use DMS\Service\Meetup\Response\MultiResultResponse;
use Doctrine\Common\Collections\ArrayCollection;
use Guzzle\Http\Exception\BadResponseException;
use Predis\Client;

class EventService
class EventService extends AbstractService
{
/**
* @var \DMS\Service\Meetup\AbstractMeetupClient
*/
protected $api;

/**
* @var Client
*/
protected $cache;

/**
* @param AbstractMeetupClient $api
* @param \Predis\Client $cache
*/
public function __construct(AbstractMeetupClient $api, Client $cache)
{
$this->api = $api;
$this->cache = $cache;
}

/**
* Gets an array of all User Group Photos
*
Expand All @@ -53,7 +30,7 @@ public function getUpcomingEvents($onlyMonthlyMeeting = false)
//Get Upcoming events
$events = $this->api->getEvents(
[
'group_urlname' => 'amsterdamphp',
'group_urlname' => $this->group,
'status' => 'upcoming',
'text_format' => 'plain'
]
Expand Down Expand Up @@ -137,7 +114,7 @@ public function getPastEvents($onlyMonthlyMeeting = false)
//Get Upcoming events
$events = $this->api->getEvents(
[
'group_urlname' => 'amsterdamphp',
'group_urlname' => $this->group,
'status' => 'past',
'text_format' => 'plain',
'desc' => 'true'
Expand All @@ -153,21 +130,4 @@ public function getPastEvents($onlyMonthlyMeeting = false)

return $events;
}

/**
* @return \DMS\Service\Meetup\AbstractMeetupClient
*/
public function getApi()
{
return $this->api;
}

/**
* @return \Predis\Client
*/
public function getCache()
{
return $this->cache;
}

}
48 changes: 6 additions & 42 deletions src/AmsterdamPHP/Bundle/MeetupBundle/Service/PhotoService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,8 @@

namespace AmsterdamPHP\Bundle\MeetupBundle\Service;

use DMS\Service\Meetup\AbstractMeetupClient;
use Predis\Client;

class PhotoService
class PhotoService extends AbstractService
{
/**
* @var \DMS\Service\Meetup\AbstractMeetupClient
*/
protected $api;

/**
* @var Client
*/
protected $cache;

/**
* @param AbstractMeetupClient $api
* @param \Predis\Client $cache
*/
public function __construct(AbstractMeetupClient $api, Client $cache)
{
$this->api = $api;
$this->cache = $cache;
}

/**
* Gets a random number of photos
* 1
Expand Down Expand Up @@ -111,7 +88,11 @@ public function getAllPhotos()
while(!isset($metadata['total_count']) || $metadata['total_count'] > count($allPhotos)) {

//Iterate getting all photos
$photos = $this->api->getPhotos(array('group_urlname' => 'amsterdamphp'));
$photos = $this->api->getPhotos(
[
'group_urlname' => $this->group,
]
);

$allPhotos = array_merge($allPhotos, $photos->getData());
$metadata = $photos->getMetadata();
Expand All @@ -123,21 +104,4 @@ public function getAllPhotos()

return $allPhotos;
}

/**
* @return \DMS\Service\Meetup\AbstractMeetupClient
*/
public function getApi()
{
return $this->api;
}

/**
* @return \Predis\Client
*/
public function getCache()
{
return $this->cache;
}

}
43 changes: 2 additions & 41 deletions src/AmsterdamPHP/Bundle/MeetupBundle/Service/SponsorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,8 @@

namespace AmsterdamPHP\Bundle\MeetupBundle\Service;

use DMS\Service\Meetup\AbstractMeetupClient;
use Predis\Client;

class SponsorService
class SponsorService extends AbstractService
{
/**
* @var \DMS\Service\Meetup\AbstractMeetupClient
*/
protected $api;

/**
* @var Client
*/
protected $cache;

/**
* @param AbstractMeetupClient $api
* @param \Predis\Client $cache
*/
public function __construct(AbstractMeetupClient $api, Client $cache)
{
$this->api = $api;
$this->cache = $cache;
}

/**
* Gets a random number of sponsors
*
Expand Down Expand Up @@ -60,7 +37,7 @@ public function getAllSponsors()
//Get Upcoming events
$groupsInfo = $this->api->getGroups(
[
'group_urlname' => 'amsterdamphp',
'group_urlname' => $this->group,
'fields' => 'sponsors',
'only' => 'sponsors',
]
Expand All @@ -77,20 +54,4 @@ public function getAllSponsors()

return $sponsors;
}

/**
* @return \DMS\Service\Meetup\AbstractMeetupClient
*/
public function getApi()
{
return $this->api;
}

/**
* @return \Predis\Client
*/
public function getCache()
{
return $this->cache;
}
}

0 comments on commit 75bf9b0

Please sign in to comment.