Permalink
Browse files

Retrieve provider-specific settings in each call and use them in data…

…base query building.
  • Loading branch information...
1 parent 2eec4f0 commit 662650b4f4305da886994eb8b04e789b4b6cd474 @matthewpennell committed Oct 9, 2011
@@ -18,8 +18,8 @@ class Controller_Provider_Twitter extends Controller_Ruck {
public function action_refresh()
{
// Retrieve the last X tweets.
- // TODO: Parameterise the user-specific settings so they can be retrieved from a settings query.
- if ($xml = Curl::get('https://api.twitter.com/1/statuses/user_timeline.xml?include_entities=true&include_rts=true&screen_name=matthewpennell&trim_user=true&count=20'))
+ // TODO: Set the number of items to retrieve from each service in a central admin_settings table.
+ if ($xml = Curl::get('https://api.twitter.com/1/statuses/user_timeline.xml?include_entities=true&include_rts=' . ($this->settings['include_retweets'] == 1 ? 'true' : 'false') . '&screen_name=' . $this->settings['screen_name'] . '&trim_user=true&count=20'))
{
$twitter = @simplexml_load_string($xml);
@@ -47,7 +47,7 @@ public function action_refresh()
// If any new items were inserted, also store the raw data.
if ($count > 0)
{
- $this->model->insert_raw($xml);
+ $this->model->insert_raw($this->provider, $xml);
}
$out = sprintf(
@@ -7,6 +7,11 @@ class Controller_Ruck extends Controller {
public function before()
{
$this->model = Model::factory('Ruck');
+ $settings = $this->model->get_settings($this->provider);
+ if ($settings)
+ {
+ $this->settings = $settings;
+ }
}
/**
@@ -12,6 +12,24 @@ public function providers()
return $providers->as_array(NULL, 'provider');
}
+ /**
+ * If the provider has a set of settings, return it as an array for use in query building.
+ * @return
+ * @param $provider String
+ */
+ public function get_settings($provider)
+ {
+ if (DB::query(Database::SELECT, "SELECT COUNT(*) AS count FROM information_schema.tables WHERE table_schema = 'ruck' AND table_name = '" . $provider . "_settings'")->execute()->get('count', 0))
+ {
+ $settings = DB::query(Database::SELECT, "SELECT * FROM " . $provider . "_settings")->execute()->as_array();
+ return $settings[0]; // Messy
+ }
+ else
+ {
+ return FALSE;
+ }
+ }
+
/**
* Return the last X items for a specified provider, in reverse date order.
* @return
@@ -60,9 +78,9 @@ public function insert($query = '', $parameters = array())
* @return
* @param $data Object
*/
- public function insert_raw($data)
+ public function insert_raw($provider, $data)
{
- $this->insert("INSERT INTO " . $this->provider . "_raw (timestamp, raw) VALUES (:timestamp, :raw)", array(
+ $this->insert("INSERT INTO " . $provider . "_raw (timestamp, raw) VALUES (:timestamp, :raw)", array(
':timestamp' => time(),
':raw' => $data,
));

0 comments on commit 662650b

Please sign in to comment.