Example #1
0
 public function dashboard()
 {
     // Get services
     $services = Service::transformMany(Auth::user()->services->toArray());
     $ga_services = [];
     $slack_services = [];
     foreach ($services as $v) {
         if ($v['slug'] == "ga") {
             array_push($ga_services, $v);
         } else {
             if ($v['slug'] == "slack") {
                 array_push($slack_services, $v);
             }
         }
     }
     // Get generators
     $generators = Generator::where('user_id', Auth::user()->id)->get();
     return view('pages.dashboard')->with(['ga_services' => $ga_services, 'slack_services' => $slack_services, 'generators' => $generators]);
 }
Example #2
0
 public function actions($action, $param = null, $param2 = null, $param3 = null)
 {
     if ($action == "getservices") {
         return Service::transformMany(Service::where('slug', 'slack')->orWhere('slug', 'ga')->where('user_id', Auth::user()->id)->get());
     }
     if ($action == "getaccounts") {
         $service = Service::where('id', (int) $param)->where('user_id', Auth::user()->id)->first();
         $client = new \Google_Client();
         $client->setAuthConfigFile(public_path() . '/private/google_oauth.json');
         $client->refreshToken($service['var2']);
         $analytics = new \Google_Service_Analytics($client);
         $accounts = $analytics->management_accounts->listManagementAccounts();
         return $accounts->getItems();
     }
     if ($action == "getproperties") {
         $service = Service::where('id', (int) $param)->where('user_id', Auth::user()->id)->first();
         $client = new \Google_Client();
         $client->setAuthConfigFile(public_path() . '/private/google_oauth.json');
         $client->refreshToken($service['var2']);
         $analytics = new \Google_Service_Analytics($client);
         $properties = $analytics->management_webproperties->listManagementWebproperties($param2);
         return $properties->getItems();
     }
     if ($action == "getprofiles") {
         $service = Service::where('id', (int) $param)->where('user_id', Auth::user()->id)->first();
         $client = new \Google_Client();
         $client->setAuthConfigFile(public_path() . '/private/google_oauth.json');
         $client->refreshToken($service['var2']);
         $analytics = new \Google_Service_Analytics($client);
         $profiles = $analytics->management_profiles->listManagementProfiles($param2, $param3);
         return $profiles->getItems();
     }
     if ($action == "testslack") {
         $service = Service::where('id', (int) $param)->where('user_id', Auth::user()->id)->first();
         $client = new \Maknz\Slack\Client($service['var2'], ['username' => 'Cyril', 'channel' => '#' . $param2, 'link_names' => true]);
         $client->send('Hey, this is a test message from SlackReport !');
         return 'success';
     }
 }