diff --git a/oauth_common.rules.inc b/oauth_common.rules.inc index 38168a2..0d92b0e 100644 --- a/oauth_common.rules.inc +++ b/oauth_common.rules.inc @@ -5,41 +5,116 @@ */ /** + * Implements hook_rules_data_info(). + */ +function oauth_common_rules_data_info() { + $data['oauth_common_consumer'] = array( + 'label' => t('OAuth common consumer'), + 'wrap' => TRUE, + 'property info' => array( + 'csid' => array( + 'type' => 'integer', + 'label' => t('ID'), + ), + 'uid' => array( + 'type' => 'user', + 'label' => t('Owner'), + ), + 'name' => array( + 'type' => 'text', + 'label' => t('Name'), + ), + 'context' => array( + 'type' => 'text', + 'label' => t('Context'), + ), + 'created' => array( + 'type' => 'date', + 'label' => t('Created date'), + ), + 'updated' => array( + 'type' => 'date', + 'label' => t('Updated date'), + ), + 'callback_url' => array( + 'type' => 'text', + 'label' => t('Callback URL'), + ), + 'provider_consumer' => array( + 'type' => 'boolean', + 'label' => t('Provider consumer'), + ), + 'in_database' => array( + 'type' => 'boolean', + 'label' => t('In database?'), + ), + 'key' => array( + 'type' => 'text', + 'label' => t('Key'), + ), + 'secret' => array( + 'type' => 'text', + 'label' => t('Secret'), + ), + ), + ); + + return $data; +} + +/** * Implements hook_rules_action_info(). */ function oauth_common_rules_action_info() { - $actions = array(); - $actions['oauth_common_consumer_add'] = array( - 'label' => t('Add new consumer'), - 'group' => t('OAuth'), - 'base' => 'oauth_common_rules_actions_consumer_add', + 'label' => t('Add new consumer'), + 'group' => t('OAuth'), + 'base' => 'oauth_common_rules_actions_consumer_add', 'arguments' => array( - 'account' => array( - 'type' => 'user', - 'label' => t('User acccount'), + 'account' => array( + 'type' => 'user', + 'label' => t('User acccount'), 'description' => t('The user account to add the consumer to.'), ), - 'name' => array( - 'type' => 'text', - 'label' => t('Consumer name'), + 'name' => array( + 'type' => 'text', + 'label' => t('Consumer name'), 'description' => t('The name of the consumer.'), ), 'callback_url' => array( - 'type' => 'text', - 'label' => t('Callback URL'), + 'type' => 'text', + 'label' => t('Callback URL'), 'description' => t('You must include a schema for this to work correctly, ie. http:// or iphoneappname://'), - 'optional' => TRUE, + 'optional' => TRUE, ), - 'context' => array( - 'type' => 'text', - 'label' => t('Application context'), - 'description' => '', + 'context' => array( + 'type' => 'text', + 'label' => t('Application context'), + 'description' => '', 'options list' => 'oauth_common_rules_action_consumer_add_allowed_contexts', ), ), ); + $actions['oauth_common_consumer_load'] = array( + 'label' => t('Load consumer'), + 'group' => t('OAuth'), + 'base' => 'oauth_common_rules_actions_consumer_load', + 'arguments' => array( + 'consumer_key' => array( + 'type' => 'text', + 'label' => t('Consumer key'), + 'optional' => TRUE, + ), + ), + 'provides' => array( + 'consumer' => array( + 'type' => 'oauth_common_consumer', + 'label' => t('Consumer'), + ), + ), + ); + return $actions; } @@ -48,10 +123,10 @@ function oauth_common_rules_action_info() { */ function oauth_common_rules_actions_consumer_add($account, $name, $callback_url, $context) { $consumer = new DrupalOAuthConsumer(user_password(32), user_password(32), array( - 'callback_url' => $callback_url, - 'uid' => $account->uid, - 'name' => $name, - 'context' => $context, + 'callback_url' => $callback_url, + 'uid' => $account->uid, + 'name' => $name, + 'context' => $context, 'provider_consumer' => TRUE, )); $consumer->write(); @@ -68,5 +143,17 @@ function oauth_common_rules_action_consumer_add_allowed_contexts() { $allowed_contexts[$context] = $title; } } + return $allowed_contexts; } + +/** + * Callback for 'oauth_common_consumer_load' rules action. + */ +function oauth_common_rules_actions_consumer_load($consumer_key) { + $consumer = DrupalOAuthConsumer::loadProviderByKey($consumer_key); + + return array( + 'consumer' => $consumer, + ); +}