/** * @return array|\DMS\Service\Meetup\Response\MultiResultResponse|mixed|null */ public function getRsvpListForNextEvent() { $cache = $this->cache->getItem(__METHOD__); if (!$cache->isMiss()) { return $cache->get(); } $rsvpList = $this->client->getRsvps(array('group_urlname' => self::GROUP_URLNAME, 'event_id' => $this->getNextEvent()['id'])); if ($rsvpList->isError()) { throw new \RuntimeException($rsvpList->getMessage()); } $rsvpList = $rsvpList->getData(); $cache->set($rsvpList, self::FIVE_MINUTES); return $rsvpList; }
public function getNextEvent() { $cache = $this->cache->getItem(__METHOD__); if (!$cache->isMiss()) { return $cache->get(); } $events = $this->client->getEvents(array('group_urlname' => self::GROUP_URLNAME)); if ($events->isError()) { throw new \RuntimeException($events->getMessage()); } $event = $events->getData()[0]; $cache->set($event, self::FIVE_MINUTES); return $event; }
/** * Get a new instance of a Key Auth Client for Meetup API * @param bool $forceNew * @return MeetupKeyAuthClient */ public function getKeyAuthClient($forceNew = false) { if (!isset($this->instances[self::CLIENT_KEY]) || $forceNew) { $this->instances[self::CLIENT_KEY] = MeetupKeyAuthClient::factory($this->config); } return $this->instances[self::CLIENT_KEY]; }
/** * {@inheritdoc} */ public function getEvents($url) { $events = []; $groupUrlName = $this->extractGroupNameFromUrl($url); if (empty($groupUrlName)) { return $events; } $response = $this->client->getEvents(['group_urlname' => $groupUrlName]); foreach ($response->getData() as $event) { $date = date('Y-m-d', $event['time'] / 1000); $venue = null; if (isset($event['venue']) && isset($event['venue']['name']) && isset($event['venue']['city'])) { $venue = $event['venue']['name'] . ', ' . $event['venue']['city']; } $events[] = new Event($event['name'], $date, $event['event_url'], $venue); } return $events; }
protected function setUp() { parent::setUp(); $configFile = __DIR__ . '/../../api_key.ini'; if (!file_exists($configFile)) { $this->markTestSkipped('Functional Tests require an Oauth Key'); } $config = parse_ini_file($configFile); $this->keyClient = MeetupKeyAuthClient::factory(array('key' => $config['key'])); }
/** * @return array */ public function getVenues() { $result = $this->client->getVenues(['group_urlname' => $this->config->groupUrlName])->getData(); $venues = []; foreach ($result as $venue) { $venueInfo = Venue::create(['id' => $venue['id'], 'name' => $venue['name'], 'address' => $venue['address_1']]); $venues[$venueInfo->getId()] = $venueInfo; } return $venues; }
/** * {@inheritdoc} */ public function register(Application $app) { $app['meetup.api_key'] = ''; $app['meetup.client'] = $app->share(function ($app) { return MeetupKeyAuthClient::factory(['key' => $app['meetup.api_key'], 'sign' => true]); }); $app['meetup.service'] = $app->share(function ($app) { return new Meetup($app['meetup.client']); }); }
public function getServiceConfig() { return array('factories' => array('DMSClient' => function ($sm) { $settings = array('key' => $sm->get('config')['meetup']['api_key']); return MeetupKeyAuthClient::factory($settings); }, 'DMSClientAdapter' => function ($sm) { $adaptee = $sm->get('DMSClient'); return new DMSClientAdapter($adaptee); }, 'HrPhpMeetupClient' => function ($sm) { $adapter = $sm->get('DMSClientAdapter'); $service = new Client(); $service->setAdapter($adapter); return $service; })); }
use DMS\Service\Meetup\MeetupKeyAuthClient; use Predis\Client; use Raffle\MeetupOauthHandler; use Silex\Application; use Silex\Provider\TwigServiceProvider; use Silex\Provider\UrlGeneratorServiceProvider; use Silex\Provider\ValidatorServiceProvider; use Symfony\Component\Yaml\Yaml; use Raffle\MeetupService; use Raffle\RandomService; $app = new Application(); $app['config'] = Yaml::parse(__DIR__ . '/../config/parameters.yml'); $app->register(new UrlGeneratorServiceProvider()); $app->register(new ValidatorServiceProvider()); // Twig Configuration $app->register(new TwigServiceProvider(), array('twig.path' => array(__DIR__ . '/../templates'), 'twig.options' => array('cache' => __DIR__ . '/../cache'))); $app['twig'] = $app->share($app->extend('twig', function ($twig) { return $twig; })); $app->register(new Silex\Provider\UrlGeneratorServiceProvider()); // Session $app->register(new Silex\Provider\SessionServiceProvider()); // Meetup Oauth Handler $app['meetup_oauth_handler'] = new MeetupOauthHandler($app); // Meetup service $config = array('key' => $app['config']['meetup_api_key']); $app['meetup'] = new MeetupService(MeetupKeyAuthClient::factory($config), $app['config']['meetup_group'], new Client()); // Random service $app['random'] = new RandomService(); return $app;
public function __construct() { $this->client = MeetupKeyAuthClient::factory(['key' => $this->key]); }
public function meetupPull() { // nwdug group id = 4396922 // Get the Meetup API Key. $mymodule_config = \Drupal::config('meetup_pull.settings'); $key = $mymodule_config->get('api_key'); // If no API key is present then return an error. if ($key == '') { return 'API Key is empty.'; } // Get the Meetup client. $client = MeetupKeyAuthClient::factory(array('key' => $key)); // Get all the (future) events for the group. $events = $client->getEvents(array('group_urlname' => 'nwdrupal', 'page' => 10)); // Initialise event counts. $count_existing = 0; $count_new = 0; foreach ($events as $event) { // Extract the meetup. $meetup_event_id = $event['id']; // Set default FALSE status for venues. $venue = FALSE; if (isset($event['venue'])) { // If the Venue has been set then $venue = $event['venue']; $tids = \Drupal::entityQuery('taxonomy_term') ->condition('name', $venue['name'], '=') ->condition('vid', 'venue') ->execute(); if (count($tids) > 0) { $venue = array_pop($tids); } } // Extract RSVP Count. $rsvp = $event['yes_rsvp_count']; // Extract date/time $date = $event['time']; // Extract URL of event. $event_url = $event['event_url']; $dateTime = new \DateTime(); $dateTime->setTimestamp(substr($date, 0, -3)); // Time format in MySQL is '2015-11-12T18:00:00'. $date = $dateTime->format('Y-m-d\TH:i:00'); $path_components = array( 'year' => $dateTime->format('Y'), 'month' => $dateTime->format('m'), 'day' => $dateTime->format('d') ); $event_title = $event['name']; $event_body = array( 'value' => $event['description'], 'format' => filter_default_format(), ); // Search the a node with the same meetup event ID already in the system. $nids = \Drupal::entityQuery('node') ->condition('type', 'event') ->condition('field_event_meetup_id', $meetup_event_id, '=') ->execute(); if (count($nids) > 0) { // Event exists, update it. $count_existing++; $nid = array_pop($nids); // Load the found event node. $node = \Drupal::entityManager()->getStorage('node')->load($nid); // Apply all of the settings we extracted from the Meetup API and save the node. $node->field_event_rsvps = $rsvp; $node->title = $event_title; $node->body = $event_body; $node->field_event_date = $date; $node->field_event_url = $event_url; if ($venue !== FALSE) { $node->field_event_venue = $venue; } $node->save(); $node_alias = '/event/' . $path_components['year'] . '/' . $path_components['month'] . '/' . $path_components['day'] . '/' . $this->slug($event_title); \Drupal::service('path.alias_storage')->save('/'.$node->urlInfo()->getInternalPath(), $node_alias, $node->language()->getId()); } else { // Event doesn't exist, create it. $count_new++; // Set all of the settings we extracted from the Meetup API and create the node. $new_node = array( 'type' => 'event', 'title' => $event_title, 'body' => $event_body, 'field_event_date' => $date, 'field_event_rsvps' => $rsvp, 'field_event_meetup_id' => $meetup_event_id, 'field_event_url' => $event_url ); if ($venue !== FALSE) { $new_node['field_event_venue'] = $venue; } $node = Node::create($new_node); $node->save(); $node_alias = '/event/' . $path_components['year'] . '/' . $path_components['month'] . '/' . $path_components['day'] . '/' . $this->slug($event_title); \Drupal::service('path.alias_storage')->save('/'.$node->urlInfo()->getInternalPath(), $node_alias, $node->language()->getId()); } } return 'Meetup events pulled and updated. ' . $count_new . ' new events and ' . $count_existing . ' existing event processed.<br>' . ($count_existing + $count_new) . ' events procssed in totoal.'; }
protected function buildClient() { $config = array('key' => 'mykey'); $client = MeetupKeyAuthClient::factory($config); return $client; }
return new PHPMinds\Config\JoindinConfig(['apiKey' => $joindin['key'], 'baseUrl' => $joindin['baseUrl'], 'frontendBaseUrl' => $joindin['frontendBaseUrl'], 'callback' => $joindin['callback'], 'username' => $joindin['username']]); }; $container['meetup.event'] = function ($c) { return new \PHPMinds\Model\MeetupEvent($c->get('meetup.config')); }; $container['joindin.event'] = function ($c) { return new \PHPMinds\Model\JoindinEvent($c->get('joindin.config'), $c->get('PHPMinds\\Repository\\FileRepository')); }; $container['parsedown'] = function ($c) { return new Parsedown(); }; $container['service.joindin'] = function ($c) { return new \PHPMinds\Service\JoindinService($c->get('http.client'), $c->get('joindin.event')); }; $container['service.meetup'] = function ($c) { return new \PHPMinds\Service\MeetupService(\DMS\Service\Meetup\MeetupKeyAuthClient::factory(['key' => $c->get('meetup.config')->apiKey, 'base_url' => $c->get('meetup.config')->baseUrl, 'group_urlname' => $c->get('meetup.config')->groupUrlName, 'publish_status' => $c->get('meetup.config')->publishStatus]), $c->get('meetup.event'), $c->get('meetup.config')); }; $container['PHPMinds\\Service\\ContentService'] = function ($c) { $content = $c->get('settings')['content-folder']; return new \PHPMinds\Service\ContentService($c->get('parsedown'), $content['location']); }; $container['PHPMinds\\Service\\EventsService'] = function ($c) { return new \PHPMinds\Service\EventsService($c->get('service.meetup'), $c->get('service.joindin'), $c->get('PHPMinds\\Model\\Event\\EventManager')); }; $container['http.client'] = function ($c) { return new \GuzzleHttp\Client(); }; $container['Slim\\HttpCache\\CacheProvider'] = function () { return new \Slim\HttpCache\CacheProvider(); }; $container['PHPMinds\\Model\\Db'] = function ($c) {
use Symfony\Component\Yaml\Yaml; use Neoxygen\NeoClient\ClientBuilder; $skipSchemaSetup = false; $dropDbOnInit = false; if (!isset($argv[1]) || empty($argv[1])) { throw new \InvalidArgumentException('You need to pass the event ID as argument : php import.php 12345678'); } if (isset($argv[2]) && true == (bool) $argv[2]) { $skipSchemaSetup = true; } if (isset($argv[3]) && (bool) $argv[3] == true) { $dropDbOnInit = true; } $eventId = (int) $argv[1]; $config = YAML::parse(file_get_contents(__DIR__ . '/config.yml')); $meetupClient = MeetupKeyAuthClient::factory(array('key' => $config['meetup_api_key'])); $neoClient = ClientBuilder::create()->addConnection('default', $config['neo4j_scheme'], $config['neo4j_host'], $config['neo4j_port'], true, $config['neo4j_user'], $config['neo4j_password'])->setAutoFormatResponse(true)->build(); // Creating Schema Indexes And Constraints if (!$skipSchemaSetup) { $neoClient->createUniqueConstraint('Event', 'id'); $neoClient->createUniqueConstraint('Member', 'id'); $neoClient->createUniqueConstraint('Topic', 'id'); $neoClient->createUniqueConstraint('Country', 'code'); $neoClient->createIndex('City', 'name'); echo 'Schema created' . "\n"; } else { echo 'Skipping Schema Creation' . "\n"; } if ($dropDbOnInit) { echo 'Dropping DB' . "\n"; $neoClient->sendCypherQuery('MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE r,n');
/** * Execute the console command. * * @return mixed */ public function handle() { // \DB::listen(function($sql, $bindings, $time) { // var_dump($sql); // var_dump($bindings); // var_dump($time); // }); if ($this->option('debug')) { $this->info('Running in debug mode, no API calls or DB writes'); } // Get Events if (!$this->option('debug')) { $client = MeetupKeyAuthClient::factory(array('key' => env('meetup_api'))); $events = $client->getEvents(['group_urlname' => 'memphis-technology-user-groups']); } if ($this->option('debug')) { // no Api calls, fake the response $response = $this->memvent->getSampleEvents(); $events_array = json_decode($response, true); $events = $events_array['results']; } $this->output->progressStart(count($events)); foreach ($events as $event) { $group = $this->matchGroup($event); $meetup = []; $meetup['name'] = $event['name']; $meetup['event_id'] = $event['id']; $meetup['time'] = $event['time']; $meetup['status'] = $event['status']; $meetup['event_url'] = $event['event_url']; $meetup['created'] = $event['created']; if (is_object($group)) { $meetup['group_id'] = $group->id; } if ($this->findEvent($event['created'], $event['id'])) { $this->info('Updating: ' . $meetup['name']); $meetup['id'] = $this->findEvent($event['created'], $event['id'])->id; // find meetup in our db $meet_up = $this->memvent->find($meetup['id']); // Update values $meet_up->name = $meetup['name']; $meet_up->event_id = $meetup['event_id']; $meet_up->time = $meetup['time']; $meet_up->status = $meetup['status']; $meet_up->event_url = $meetup['event_url']; $meet_up->created = $meetup['created']; if (is_object($group)) { $meet_up->group_id = $group->id; } if (!$this->option('debug')) { $meet_up->save(); } if ($this->option('debug')) { $this->info('Should have updated: ' . $meetup['name']); } } else { $this->info('Creating: ' . $meetup['name']); if (!$this->option('debug')) { $this->memvent->create($meetup); } if ($this->option('debug')) { $this->info('Should have created: ' . $meetup['name']); } } $this->output->progressAdvance(); } $this->info('All Done!'); }