Explorar el Código

Adding logic for parsing tweets
adding instagram settings config

logicp hace 7 años
padre
commit
29e7e7477f

+ 17 - 0
config/schema/statusmessage.schema.yml

@@ -14,3 +14,20 @@ twitter_api.config:
     consumer_secret:
           type: text
           label: 'Consumer secret'
+
+instagram_api.config:
+  type: config_object
+  label: 'Credentials to authenticate with Instagram API'
+  mapping:
+    oauth_access_token:
+          type: text
+          label: 'Access Token'
+    oauth_access_token_secret:
+          type: text
+          label: 'Access Token Secret'
+    consumer_key:
+          type: text
+          label: 'Consumer key'
+    consumer_secret:
+          type: text
+          label: 'Consumer secret'

+ 122 - 0
src/Form/InstagramApiForm.php

@@ -0,0 +1,122 @@
+<?php
+
+namespace Drupal\statusmessage\Form;
+
+use Drupal\Core\Form\FormBase;
+use Drupal\Core\Form\FormStateInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+use Drupal\Core\Config\ConfigFactory;
+
+/**
+ * Class instagramApiForm.
+ *
+ * @package Drupal\statusmessage\Form
+ */
+class instagramApiForm extends FormBase {
+
+  /**
+   * The configuration factory.
+   *
+   * @var \Drupal\Core\Config\ConfigFactoryInterface
+   */
+  protected $configFactory;
+
+  private $instagramConfig;
+  /**
+   * Constructs a new instagramApiForm object.
+   */
+  public function __construct(ConfigFactory $config_factory) {
+    $this->configFactory = $config_factory;
+    $this->instagramConfig = $this->configFactory->getEditable('instagram_api.settings');
+  }
+
+  public static function create(ContainerInterface $container) {
+    return new static(
+      $container->get('config.factory')
+    );
+  }
+
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getFormId() {
+    return 'instagram_api_form';
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function buildForm(array $form, FormStateInterface $form_state) {
+
+    $muhTokens = $this->instagramConfig->get('oauth_access_token');
+
+    $form['oauth_access_token'] = [
+      '#type' => 'textfield',
+      '#title' => $this->t('Oauth Access Token'),
+//      '#description' => $this->t('Oauth Access Token'),
+      '#maxlength' => 64,
+      '#size' => 64,
+      '#value' => $this->instagramConfig->get('oauth_access_token'),
+    ];
+    $form['oauth_access_token_secret'] = [
+      '#type' => 'textfield',
+      '#title' => $this->t('Oauth Access Token Secret'),
+//      '#description' => $this->t('Oauth Access Token Secret'),
+      '#maxlength' => 64,
+      '#size' => 64,
+      '#value' => $this->instagramConfig->get('oauth_access_token_secret'),
+    ];
+    $form['consumer_key'] = [
+      '#type' => 'textfield',
+      '#title' => $this->t('Consumer Key'),
+//      '#description' => $this->t('Consumer Key'),
+      '#maxlength' => 64,
+      '#size' => 64,
+      '#value' => $this->instagramConfig->get('consumer_key'),
+    ];
+    $form['consumer_secret'] = [
+      '#type' => 'textfield',
+      '#title' => $this->t('Consumer Secret'),
+//      '#description' => $this->t('Consumer Secret'),
+      '#maxlength' => 64,
+      '#sizeue' => 64,
+      '#value' => $this->instagramConfig->get('consumer_secret'),
+
+    ];
+
+    $form['submit'] = [
+      '#type' => 'submit',
+      '#value' => $this->t('Submit'),
+    ];
+
+    return $form;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function validateForm(array &$form, FormStateInterface $form_state) {
+    parent::validateForm($form, $form_state);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function submitForm(array &$form, FormStateInterface $form_state) {
+    // Display result.
+    foreach ($form_state->getValues() as $key => $value) {
+      drupal_set_message($key . ': ' . $value);
+    }
+
+
+    if ($form_state->getValue('oauth_access_token')) {
+
+      $this->instagramConfig->set('consumer_key', $form_state->getValue('consumer_key'))->save();
+      $this->instagramConfig->set('consumer_secret', $form_state->getValue('consumer_secret'))->save();
+      $this->instagramConfig->set('oauth_access_token', $form_state->getValue('oauth_access_token'))->save();
+      $this->instagramConfig->set('oauth_access_token_secret', $form_state->getValue('oauth_access_token_secret'))->save();
+
+    }
+  }
+}

+ 26 - 0
src/StatusTwitter.php

@@ -16,10 +16,13 @@ class StatusTwitter {
   protected $consumerKey;
   protected $consumerSecret;
 
+  private $instagramConfig;
 
   public function __construct() {
+    $this->instagramConfig = \Drupal::config('twitter_api.settings');
   }
 
+
   /**
    * @return mixed
    */
@@ -82,4 +85,27 @@ class StatusTwitter {
   }
 
 
+  public function generateRequest($url) {
+
+  }
+
+  public function sendRequest($twid) {
+
+    //TODO Instantiating an Http Client
+
+    $twitterConfig = \Drupal::config('twitter_api.settings');
+
+
+    }
+
+  private function parseUrl ($text) {
+    //TODO retrieve Tweet ID
+  }
+
+
+  public function setNodeData() {
+
+  }
+
+
 }

+ 3 - 3
statusmessage.links.menu.yml

@@ -1,6 +1,6 @@
 # Status menu items definition
 entity.status.collection:
-  title: 'Status list'
+  title: 'Status Message'
   route_name: entity.status.collection
   description: 'List Status entities'
   parent: system.admin_structure
@@ -8,7 +8,7 @@ entity.status.collection:
 
 # Status type menu items definition
 entity.status_type.collection:
-  title: 'Status type'
+  title: 'Status Message type'
   route_name: entity.status_type.collection
   description: 'List Status type (bundles)'
   parent: system.admin_structure
@@ -19,6 +19,6 @@ config.statusmessage.twitter:
   title: Twitter API Settings
   description: 'Configure Authentication tokens for Twitter API'
   route_name: statusmessage.twitter_api_form
-  parent: system.admin_structure
+  parent: entity.status.collection