Beispiel #1
0
 /**
  * @Route ("/broadcasts.json")
  */
 public function broadcasts()
 {
     $app = Application::instance();
     $broadcasts = $app->getCacheDriver()->fetch('pastbroadcasts');
     $response = new Response(Http::STATUS_OK, json_encode($broadcasts));
     $response->addHeader(Http::HEADER_CACHE_CONTROL, 'private');
     $response->addHeader(Http::HEADER_PRAGMA, 'public');
     $response->addHeader(Http::HEADER_CONTENTTYPE, MimeType::JSON);
     return $response;
 }
Beispiel #2
0
 /**
  * @param array $params
  * @throws Exception
  */
 public function authenticate(array $params)
 {
     if (!isset($params['authtoken']) || empty($params['authtoken'])) {
         return new Response(Http::STATUS_FORBIDDEN, 'Invalid or empty authToken');
     }
     $authToken = ApiAuthenticationService::instance()->getAuthToken($params['authtoken']);
     if (empty($authToken)) {
         return new Response(Http::STATUS_FORBIDDEN, 'Auth token not found');
     }
     $user = UserService::instance()->getUserById($authToken['userId']);
     if (empty($user)) {
         return new Response(Http::STATUS_FORBIDDEN, 'User not found');
     }
     $credentials = new SessionCredentials($user);
     $credentials->setAuthProvider('API');
     $credentials->addRoles(UserRole::USER);
     $credentials->addFeatures(UserFeaturesService::instance()->getUserFeatures($authToken['userId']));
     $credentials->addRoles(UserService::instance()->getUserRolesByUserId($authToken['userId']));
     $subscription = SubscriptionsService::instance()->getUserActiveSubscription($authToken['userId']);
     if (!empty($subscription)) {
         $credentials->addRoles(UserRole::SUBSCRIBER);
         $credentials->addFeatures(UserFeature::SUBSCRIBER);
         if ($subscription['subscriptionTier'] == 2) {
             $credentials->addFeatures(UserFeature::SUBSCRIBERT2);
         }
         if ($subscription['subscriptionTier'] == 3) {
             $credentials->addFeatures(UserFeature::SUBSCRIBERT3);
         }
     }
     $response = new Response(Http::STATUS_OK, json_encode($credentials->getData()));
     $response->addHeader(Http::HEADER_CONTENTTYPE, MimeType::JSON);
     return $response;
 }
Beispiel #3
0
 /**
  * @param array $params
  * @return Response
  * @throws Exception
  */
 public function authenticate(array $params)
 {
     if (!isset($params['authtoken']) || empty($params['authtoken'])) {
         return new Response(Http::STATUS_FORBIDDEN, 'Invalid or empty authToken');
     }
     $authToken = ApiAuthenticationService::instance()->getAuthToken($params['authtoken']);
     if (empty($authToken)) {
         return new Response(Http::STATUS_FORBIDDEN, 'Auth token not found');
     }
     $user = UserService::instance()->getUserById($authToken['userId']);
     if (empty($user)) {
         return new Response(Http::STATUS_FORBIDDEN, 'User not found');
     }
     $authenticationService = AuthenticationService::instance();
     $credentials = $authenticationService->getUserCredentials($user, 'API');
     $response = new Response(Http::STATUS_OK, json_encode($credentials->getData()));
     $response->addHeader(Http::HEADER_CONTENTTYPE, MimeType::JSON);
     return $response;
 }
 /**
  * @Route ("/gift/check")
  * @Secure ({"USER"})
  *
  * @param array $params
  * @return Response
  */
 public function giftCheckUser(array $params)
 {
     FilterParams::required($params, 's');
     $userService = UserService::instance();
     $subscriptionService = SubscriptionsService::instance();
     $userId = Session::getCredentials()->getUserId();
     $data = array('valid' => false, 'cangift' => false, 'username' => $params['s']);
     $user = $userService->getUserByUsername($params['s']);
     if (!empty($user)) {
         $data['cangift'] = $subscriptionService->getCanUserReceiveGift($userId, $user['userId']);
         $data['valid'] = true;
     }
     $response = new Response(Http::STATUS_OK);
     $response->addHeader(Http::HEADER_CONTENTTYPE, MimeType::JSON);
     $response->setBody(json_encode($data));
     return $response;
 }
Beispiel #5
0
 /**
  * @Route ("/profile/info")
  * @Secure ({"USER"})
  *
  * @return Response
  */
 public function profileInfo()
 {
     $response = new Response(Http::STATUS_OK, json_encode(Session::getCredentials()->getData()));
     $response->addHeader(Http::HEADER_CONTENTTYPE, MimeType::JSON);
     return $response;
 }
Beispiel #6
0
 /**
  * @Route ("/admin/chart/{type}")
  * @Secure ({"ADMIN"})
  *
  * @param array $params
  * @return Response
  */
 public function chartData(array $params)
 {
     FilterParams::required($params, 'type');
     $statisticsService = StatisticsService::instance();
     $cacheDriver = Application::instance()->getCacheDriver();
     $data = array();
     switch (strtoupper($params['type'])) {
         case 'REVENUELASTXDAYS':
             FilterParams::required($params, 'days');
             $key = 'RevenueLastXDays ' . intval($params['days']);
             if (!$cacheDriver->contains($key)) {
                 $data = $statisticsService->getRevenueLastXDays(intval($params['days']));
                 $cacheDriver->save($key, $data, 30);
             } else {
                 $data = $cacheDriver->fetch($key);
             }
             break;
         case 'REVENUELASTXMONTHS':
             FilterParams::required($params, 'months');
             $key = 'RevenueLastXMonths ' . intval($params['months']);
             if (!$cacheDriver->contains($key)) {
                 $data = $statisticsService->getRevenueLastXMonths(intval($params['months']));
                 $cacheDriver->save($key, $data, 30);
             } else {
                 $data = $cacheDriver->fetch($key);
             }
             break;
         case 'REVENUELASTXYEARS':
             FilterParams::required($params, 'years');
             $key = 'RevenueLastXYears ' . intval($params['years']);
             if (!$cacheDriver->contains($key)) {
                 $data = $statisticsService->getRevenueLastXYears(intval($params['years']));
                 $cacheDriver->save($key, $data, 30);
             } else {
                 $data = $cacheDriver->fetch($key);
             }
             break;
         case 'NEWSUBSCRIBERSLASTXDAYS':
             FilterParams::required($params, 'days');
             $key = 'NewSubscribersLastXDays ' . intval($params['days']);
             if (!$cacheDriver->contains($key)) {
                 $data = $statisticsService->getNewSubscribersLastXDays(intval($params['days']));
                 $cacheDriver->save($key, $data, 30);
             } else {
                 $data = $cacheDriver->fetch($key);
             }
             break;
         case 'NEWSUBSCRIBERSLASTXMONTHS':
             FilterParams::required($params, 'months');
             $key = 'NewSubscribersLastXMonths ' . intval($params['months']);
             if (!$cacheDriver->contains($key)) {
                 $data = $statisticsService->getNewSubscribersLastXMonths(intval($params['months']));
                 $cacheDriver->save($key, $data, 30);
             } else {
                 $data = $cacheDriver->fetch($key);
             }
             break;
         case 'NEWSUBSCRIBERSLASTXYEARS':
             FilterParams::required($params, 'years');
             $key = 'NewSubscribersLastXYears ' . intval($params['years']);
             if (!$cacheDriver->contains($key)) {
                 $data = $statisticsService->getNewSubscribersLastXYears(intval($params['years']));
                 $cacheDriver->save($key, $data, 30);
             } else {
                 $data = $cacheDriver->fetch($key);
             }
             break;
         case 'NEWTIEREDSUBSCRIBERSLASTXDAYS':
             FilterParams::required($params, 'days');
             $key = 'NewTieredSubscribersLastXDays ' . intval($params['days']);
             if (!$cacheDriver->contains($key)) {
                 $data = $statisticsService->getNewTieredSubscribersLastXDays(intval($params['days']));
                 $cacheDriver->save($key, $data, 30);
             } else {
                 $data = $cacheDriver->fetch($key);
             }
             break;
     }
     $response = new Response(Http::STATUS_OK, json_encode($data));
     $response->addHeader(Http::HEADER_CONTENTTYPE, MimeType::JSON);
     return $response;
 }
Beispiel #7
0
 /**
  * @Route ("/chat/emotes.json")
  *
  * @param array $params
  * @param ViewModel $model
  */
 public function emotes(array $params, ViewModel $model)
 {
     // just return every single one
     $emotes = array_merge(Config::$a['chat']['customemotes'], Config::$a['chat']['twitchemotes']);
     $response = new Response(Http::STATUS_OK, json_encode($emotes));
     $response->addHeader(Http::HEADER_CONTENTTYPE, MimeType::JSON);
     return $response;
 }
Beispiel #8
0
 /**
  * @Route ("/ping")
  *
  * @param array $params
  */
 public function ping(array $params)
 {
     $response = new Response(Http::STATUS_OK);
     $response->addHeader('X-Pong', 'Destiny');
     return $response;
 }
Beispiel #9
0
 /**
  * @Route ("/admin/user/find")
  * @Secure ({"ADMIN"})
  *
  * @param array $params         
  */
 public function adminUserFind(array $params)
 {
     FilterParams::isRequired($params, 's');
     $userService = UserService::instance();
     $users = $userService->findUsers($params['s'], 10);
     $response = new Response(Http::STATUS_OK);
     $response->addHeader(Http::HEADER_CONTENTTYPE, MimeType::JSON);
     $response->setBody(json_encode($users));
     return $response;
 }
Beispiel #10
0
 /**
  * @Route ("/chat/emotes.json")
  *
  * @param array $params
  * @param ViewModel $model
  */
 public function emotes(array $params, ViewModel $model)
 {
     $response = new Response(Http::STATUS_OK, json_encode(Config::$a['chat']['customemotes']));
     $response->addHeader(Http::HEADER_CONTENTTYPE, MimeType::JSON);
     return $response;
 }