summaryrefslogtreecommitdiffstats
path: root/src/MLEngineService.php
blob: 8fe02eaf6f6de01306a8064ae899610100b7c823 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php

namespace Drupal\ml_engine;

use Drupal\Component\Utility\Xss;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;

class MLEngineService {

  public $credential;

  public function __construct() {
  }

  public static function create(ContainerInterface $container) {
    return new static();
  }

  public function create_service(array $credential=[]){
    // Creting client and services.
    
    if(!$credential) {
      $credential = \Drupal::service('ml_engine.project')->get_credential();
    }
    $client = new \Google_Client();
    $client->setAuthConfig($credential);
    $client->addScope(\Google_Service_CloudMachineLearningEngine::CLOUD_PLATFORM);
    $service = new \Google_Service_CloudMachineLearningEngine($client);
    return $service;
  }

}