/** * Handles getting and loading the content */ public function handle(ConfigurationRepositoryInterface $configuration) { // First get the location and split it into city & state list($city, $state) = explode(',', $configuration->value('daviesgeek.extension.weather_widget::location', $this->widget->getId())); // Trim both and slug-ify the city $state = trim($state); $request_city = str_replace(" ", "_", trim($city)); // Retrieve the API key $key = $configuration->value('daviesgeek.extension.weather_widget::api_key', $this->widget->getId()); // Build the URL $url = 'http://api.wunderground.com/api/' . $key . '/conditions/q/' . $state . '/' . $request_city . '.json'; // Create a new \GuzzleHttp\Client $client = new Client(); // Make the request $res = $client->request('GET', $url); // Set the content to the twig template with the decoded JSON as the data $this->widget->setContent(view('daviesgeek.extension.weather_widget::template', json_decode($res->getBody(), true))); }
/** * Handle the widget data. */ public function handle(\SimplePie $rss, Repository $cache, ConfigurationRepositoryInterface $configuration) { $items = $cache->remember(__METHOD__, 30, function () use($rss, $configuration) { // Let Laravel cache everything. $rss->enable_cache(false); // Hard-code this for now. $rss->set_feed_url($configuration->value('anomaly.extension.xml_feed_widget::url', $this->widget->getId(), 'http://www.pyrocms.com/posts/rss.xml')); // Make the request. $rss->init(); return $rss->get_items(0, 5); }); // Load the items to the widget's view data. $this->widget->addData('items', $items); }