UNPKG

@cevo/angular-gte

Version:

Angular Libraries for communicating with the Gfinity API v2

942 lines (772 loc) 24.8 kB
'use strict'; 'format amd'; (function () { 'use strict'; function __gte(angular, ngResource, ngStorage, cevoUtil) { angular.module('cevo.gte', ['ngResource', 'ngStorage', 'cevo.util']).provider('gte', function () { var config = {}; return { $get: function $get() { return config; } }; }); return 'cevo.gte'; } module.exports = __gte(require('angular'), require('angular-resource'), require('ngstorage'), require('@cevo/angular-util')); })(); 'use strict'; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; angular.module('cevo.gte').factory('Article', ["$http", "$q", "$sce", "cevo", "Logger", function ($http, $q, $sce, cevo, Logger) { function Article(id) { var obj = { id: id, getUrl: function getUrl(path) { return cevo.endpoint + 'news/' + this.id + (path ? '/' + path : ''); }, $get: function $get(id) { if (id) obj.id = id; var data = {}; return $http({ method: 'GET', url: obj.getUrl(), params: data }).then(function (data) { if (data) { var item = data.data.news; item.content = $sce.trustAsHtml(item.content); return angular.extend(obj, item); } }); }, $comments: function $comments() { var data = {}; return $http({ method: 'GET', url: obj.getUrl('comments'), params: data }).then(function (data) { obj.comments = data.data.comments; return obj.comments; }); } }; if ((typeof id === 'undefined' ? 'undefined' : _typeof(id)) === 'object') { angular.extend(obj, id); obj.id = _typeof(obj.id) === 'object' ? 0 : obj.id; } return obj; } return Article; }]); 'use strict'; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; angular.module('cevo.gte').factory('FranchiseLeaderboard', ["$http", "$q", "cevo", "Logger", function ($http, $q, cevo, Logger) { function FranchiseLeaderboard(id) { var obj = { id: id, leaderboard: [], getUrl: function getUrl(path) { return cevo.endpoint + 'franchiseLeaderboards/' + this.id + (path ? '/' + path : ''); }, $get: function $get(id) { if (id) obj.id = id; var data = {}; return $http({ method: 'GET', url: obj.getUrl(), params: data }).then(function (data) { var leaderboard = data.data.leaderboard; obj.leaderboard = leaderboard; return obj.leaderboard; }); } }; if ((typeof id === 'undefined' ? 'undefined' : _typeof(id)) === 'object') { angular.extend(obj, id); obj.id = _typeof(obj.id) === 'object' ? 0 : obj.id; } return obj; } return FranchiseLeaderboard; }]); 'use strict'; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; angular.module('cevo.gte').factory('Match', ["$http", "$q", "cevo", "Logger", function ($http, $q, cevo, Logger) { function Match(id) { var obj = { id: id, getUrl: function getUrl(path) { return cevo.endpoint + 'matches/' + this.id + (path ? '/' + path : ''); }, $get: function $get(id) { if (id) obj.id = id; var data = {}; return $http({ method: 'GET', url: obj.getUrl(), params: data }).then(function (data) { if (data) { angular.extend(obj, data.data.match); return data.data.match; } }); }, $vods: function $vods(id) { if (id) obj.id = id; var data = {}; return $http({ method: 'GET', url: obj.getUrl('vods'), params: data }).then(function (data) { if (data) { angular.extend(obj, data.data.vods); return data.data.vods; } }); } }; if ((typeof id === 'undefined' ? 'undefined' : _typeof(id)) === 'object') { angular.extend(obj, id); obj.id = _typeof(obj.id) === 'object' ? 0 : obj.id; } return obj; } return Match; }]); 'use strict'; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; angular.module('cevo.gte').factory('Member', ["$http", "$q", "cevo", "Logger", function ($http, $q, cevo, Logger) { function Member(id) { var obj = { id: id, getUrl: function getUrl(path) { return cevo.endpoint + 'profile/' + this.id + (path ? '/' + path : ''); }, $get: function $get(id) { if (id) obj.id = id; var data = {}; return $http({ method: 'GET', url: obj.getUrl(), params: data }).then(function (data) { if (data) { // angular.extend(obj, data.data.user); // return data.data.user; angular.extend(obj, data.data.user); return data.data.user; } }); }, $teams: function $teams() { var data = {}; return $http({ method: 'GET', url: obj.getUrl('teams'), params: data }).then(function (data) { if (data) { angular.extend(obj, data.data); return data.data; } }); } }; if ((typeof id === 'undefined' ? 'undefined' : _typeof(id)) === 'object') { angular.extend(obj, id); obj.id = _typeof(obj.id) === 'object' ? 0 : obj.id; } return obj; } return Member; }]); 'use strict'; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; angular.module('cevo.gte').factory('Realsport', ["$http", "$q", "$sce", "cevo", "Logger", function ($http, $q, $sce, cevo, Logger) { function Realsport(id) { if ((typeof id === 'undefined' ? 'undefined' : _typeof(id)) === 'object') { angular.extend(obj, id); obj.id = _typeof(obj.id) === 'object' ? 0 : obj.id; } return obj; } return Realsport; }]); 'use strict'; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; angular.module('cevo.gte').factory('Season', ["$http", "$q", "cevo", "Logger", "Team", function ($http, $q, cevo, Logger, Team) { function Season(id) { var obj = { id: id, getUrl: function getUrl(path) { return cevo.endpoint + 'seasons/' + this.id + (path ? '/' + path : ''); }, $get: function $get(id) { if (id) obj.id = id; var data = {}; return $http({ method: 'GET', url: obj.getUrl(), params: data }).then(function (data) { if (data) { angular.extend(obj, data.data.season); return data.data.season; } }); }, $team: function $team(id) { var data = {}; return $http({ method: 'GET', url: obj.getUrl('teams/' + id), params: data }).then(function (data) { obj.team = cevo.util.objectify(data.data, Team); return obj.team.team; }); }, $teams: function $teams() { var data = {}; return $http({ method: 'GET', url: obj.getUrl('teams'), params: data }).then(function (data) { obj.teams = cevo.util.objectify(data.data.teams, Team); return obj.teams; }); } }; if ((typeof id === 'undefined' ? 'undefined' : _typeof(id)) === 'object') { angular.extend(obj, id); obj.id = _typeof(obj.id) === 'object' ? 0 : obj.id; } return obj; } return Season; }]); 'use strict'; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; angular.module('cevo.gte').factory('Team', ["$http", "$q", "cevo", "Logger", "Member", function ($http, $q, cevo, Logger, Member) { function Team(id) { var obj = { id: id, players: {}, getUrl: function getUrl(path) { return cevo.endpoint + 'teams' + (path ? '/' + path : ''); }, //use this to load all information, including team members $get: function $get(id) { if (id) obj.id = id; var data = {}; return $http({ method: 'GET', url: obj.getUrl(obj.id), params: data }).then(function (data) { Logger.debug('team get', data); obj = angular.extend(obj, data.data.team); }); }, $players: function $players(season) { var data = {}; return $http({ method: 'GET', url: cevo.endpoint + 'seasons/' + season + '/teams/' + obj.id + '/players', params: data }).then(function (data) { var players = cevo.util.objectify(data.data.players, Member); return players; //obj.players[season] = ; //Logger.debug('team players', 'finished loading $players', data, obj.players); //return obj.players[season]; }); } }; if ((typeof id === 'undefined' ? 'undefined' : _typeof(id)) === 'object') { angular.extend(obj, id); obj.id = _typeof(obj.id) === 'object' ? 0 : obj.id; } return obj; } return Team; }]); 'use strict'; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; angular.module('cevo.gte').factory('Tournament', ["$http", "$q", "cevo", "Logger", "Match", "Team", function ($http, $q, cevo, Logger, Match, Team) { function Tournament(id) { var obj = { id: id, matches: { all: [], round: [], upcoming: [], past: [] }, getUrl: function getUrl(path) { return cevo.endpoint + 'tournaments/' + this.id + (path ? '/' + path : ''); }, $get: function $get(id) { if (id) obj.id = id; var data = {}; return $http({ method: 'GET', url: obj.getUrl(), params: data }).then(function (data) { if (data) { angular.extend(obj, data.data.tournament); return obj; } }); }, $matches: function $matches() { var data = {}; return $http({ method: 'GET', url: obj.getUrl('matches'), params: data }).then(function (data) { obj.matches.all = cevo.util.objectify(data.data.matches, Match); return obj.matches.all; }); }, $pastMatches: function $pastMatches() { var data = {}; return $http({ method: 'GET', url: obj.getUrl('matches/results'), params: data }).then(function (data) { obj.matches.past = cevo.util.objectify(data.data.matches, Match); return obj.matches.past; }); }, $placements: function $placements() { var data = {}; return $http({ method: 'GET', url: obj.getUrl('placements'), params: data }).then(function (data) { obj.placements = data.data.placements; return obj.placements; }); }, //[required] var round [0/1/2/3/4/5...] : an index, not an ID $roundMatches: function $roundMatches(round) { var data = {}; return $http({ method: 'GET', url: obj.getUrl('matches/round/' + round), params: data }).then(function (data) { obj.matches.round[round] = cevo.util.objectify(data.data.matches, Match); return obj.matches.round[round]; }); }, $standings: function $standings() { var data = {}; return $http({ method: 'GET', url: obj.getUrl('table'), params: data }).then(function (data) { obj.standings = data.data.table; return obj.standings; }); }, //DON'T USE THIS, USE /SEASONS/:ID/TEAMS instead //[optional] var type [regular/standby] $teams: function $teams(type) { var data = {}; return $http({ method: 'GET', url: obj.getUrl('teams' + (type ? '/' + type : '')), params: data }).then(function (data) { obj.teams = cevo.util.objectify(data.data.teams, Team); return obj.teams; }); }, $team: function $team(type) { var data = {}; var id = type; return $http({ method: 'GET', url: obj.getUrl('teams'), params: data }).then(function (data) { var item = data.data.teams.filter(function (i) { return i.id === id; }); return angular.extend(obj, item[0]); }); }, $upcomingMatches: function $upcomingMatches() { var data = {}; return $http({ method: 'GET', url: obj.getUrl('matches/fixtures'), params: data }).then(function (data) { obj.matches.upcoming = cevo.util.objectify(data.data.matches, Match); return obj.matches.upcoming; }); } }; if ((typeof id === 'undefined' ? 'undefined' : _typeof(id)) === 'object') { angular.extend(obj, id); obj.id = _typeof(obj.id) === 'object' ? 0 : obj.id; } return obj; } return Tournament; }]); 'use strict'; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; angular.module('cevo.gte').factory('VOD', ["$http", "$q", "cevo", "Logger", function ($http, $q, cevo, Logger) { function VOD(id) { var obj = { id: id, getUrl: function getUrl(path) { return cevo.endpoint + 'liveTv/vod/' + this.id + (path ? '/' + path : ''); }, //use this to load all information, including team members $get: function $get(id) { if (id) obj.id = id; var data = {}; return $http({ method: 'GET', url: obj.getUrl(), params: data }).then(function (data) { if (data) { angular.extend(obj, data.data.vod); return data.data.vod; } }); } }; if ((typeof id === 'undefined' ? 'undefined' : _typeof(id)) === 'object') { angular.extend(obj, id); obj.id = _typeof(obj.id) === 'object' ? 0 : obj.id; } return obj; } return VOD; }]); 'use strict'; angular.module('cevo.gte').provider('settings', function () { var config = { origin: '', token: '', tokenType: '' }; return { setOrigin: function setOrigin(origin) { config.origin = origin; }, setToken: function setToken(token) { config.token = token; }, setTokenType: function setTokenType(type) { config.tokenType = type; }, $get: function $get() { return config; } }; return obj; }); 'use strict'; angular.module('cevo.gte').service('FranchiseLeaderboards', ["$rootScope", "$http", "Logger", "cevo", "FranchiseLeaderboard", function ($rootScope, $http, Logger, cevo, FranchiseLeaderboard) { var obj = this; obj.list = []; obj.$list = function (status) { return $http({ method: 'GET', url: cevo.endpoint + 'franchiseLeaderboards' }).then(function (data) { obj.list = cevo.util.objectify(data.data.leaderboards, FranchiseLeaderboard); return obj.list; }); }; return obj; }]); 'use strict'; angular.module('cevo.gte').service('LiveTV', ["$rootScope", "$http", "Logger", "cevo", "VOD", function ($rootScope, $http, Logger, cevo, VOD) { var obj = this; obj.$vods = function (tag, pageSize, page) { return $http({ method: 'GET', url: cevo.endpoint + 'liveTv/vod' + (tag ? '/tags/' + tag : ''), params: { pageSize: pageSize, page: page } }).then(function (data) { return cevo.util.objectify(data.data.vods, VOD); }); }; obj.$channels = function () { return $http({ method: 'GET', url: cevo.endpoint + 'liveTv/channels' }).then(function (data) { return data.data.channels; }); }; return obj; }]); 'use strict'; angular.module('cevo.gte').service('News', ["$rootScope", "$http", "Logger", "cevo", "Article", function ($rootScope, $http, Logger, cevo, Article) { var obj = this; obj.$list = function (tag, pageSize, page, featured, categoryId) { var requestParams = { page_size: pageSize, page: page }; if (featured) { requestParams.is_featured = featured; } if (categoryId) { requestParams.category_id = categoryId; } return $http({ method: 'GET', url: cevo.endpoint + 'news' + (tag ? '/tags/' + tag : ''), params: requestParams }).then(function (data) { var returnObj = { meta: data.data.meta, news: cevo.util.objectify(data.data.news, Article) }; return returnObj; }); }; obj.$getByCategory = function (categoryId, pageSize, page, anchorDate, anchorDir) { var requestParams = { category_id: categoryId, page_size: pageSize, page: page }; if (anchorDate) { switch (anchorDir) { case 'before': case 'after': // good to go break; default: anchorDir = 'after'; break; } var param = 'published_' + anchorDir; requestParams[param] = anchorDate; } return $http({ method: 'GET', url: cevo.endpoint + 'news', params: requestParams }).then(function (data) { var returnObj = { meta: data.data.meta, news: cevo.util.objectify(data.data.news, Article) }; return returnObj; }); }; obj.$categories = function () { var requestParams = { page_size: 50, page: 1 }; return $http({ method: 'GET', url: cevo.endpoint + 'news/categories', params: requestParams }).then(function (data) { return data.data.categories; }); }; return obj; }]); 'use strict'; angular.module('cevo.gte').service('RealsportFeed', ["$rootScope", "$http", "Logger", "cevo", "Realsport", function ($rootScope, $http, Logger, cevo, Realsport) { var obj = this; obj.$list = function (pageSize) { var requestParams = { per_page: pageSize, _embed: true }; return $http({ method: 'GET', url: 'https://realsport101.com/wp-json/wp/v2/posts', params: requestParams, skip: true }).then(function (data) { return data.data; }); }; return obj; }]); 'use strict'; angular.module('cevo.gte').service('Seasons', ["$rootScope", "$http", "Logger", "cevo", "Season", function ($rootScope, $http, Logger, cevo, Season) { var obj = this; obj.$list = function (tag, pageSize, page) { return $http({ method: 'GET', url: cevo.endpoint + 'seasons', params: { pageSize: pageSize, page: page } }).then(function (data) { return cevo.util.objectify(data.data.news, Season); }); }; return obj; }]); 'use strict'; angular.module('cevo.gte').service('Sort', ["$http", "cevo", "Logger", "$sce", function ($http, cevo, Logger, $sce) { var obj = this; obj.sortArrayOfObjects = function () { /* * save the arguments object as it will be overwritten * note that arguments object is an array-like object * consisting of the names of the properties to sort by */ var props = arguments; var site = this; return function (obj1, obj2) { var i = 0, result = 0, numberOfProperties = props.length; /* try getting a different result from 0 (equal) * as long as we have extra properties to compare */ while (result === 0 && i < numberOfProperties) { result = site.sortArrayOfObjectsByProperty(props[i])(obj1, obj2); i++; } return result; }; }; obj.sortArrayOfObjectsByProperty = function (property) { var sortOrder = 1; if (property[0] === "-") { sortOrder = -1; property = property.substr(1); } return function (a, b) { var aVal = a[property]; var bVal = b[property]; var aParsed = parseInt(aVal); var bParsed = parseInt(bVal); if (aVal == aParsed && bVal == bParsed) { aVal = aParsed; bVal = bParsed; } var result = aVal < bVal ? -1 : aVal > bVal ? 1 : 0; return result * sortOrder; }; }; return obj; }]); 'use strict'; angular.module('cevo.gte').service('Tournaments', ["$rootScope", "$http", "Logger", "cevo", "Tournament", function ($rootScope, $http, Logger, cevo, Tournament) { var obj = this; //var status [active/archived/featured] obj.list = []; obj.$list = function (status) { return $http({ method: 'GET', url: cevo.endpoint + 'tournaments' + (status ? '/' + status : '') }).then(function (data) { obj.list = cevo.util.objectify(data.data.tournaments, Tournament); return obj.list; }); }; return obj; }]); 'use strict'; angular.module('cevo.gte').service('Twitter', ["$http", "cevo", "Logger", "$sce", function ($http, cevo, Logger, $sce) { var obj = this; obj.$search = function (search, count) { return $http({ method: 'GET', url: 'https://api.cevo.com/1.0/twitter/search/', params: { search: search, count: count } }).then(function (data) { return data.data.data.results; }); }; obj.$fromUser = function (user, count) { Logger.debug("fetching twitter results from user ", user, count); return $http({ method: 'GET', url: 'https://api.cevo.com/1.0/twitter/fromuser/', params: { user: user, count: count } }).then(function (data) { Logger.debug("twitter fromuser saw data", data); return data.data.data.results; }); }; obj.ProcessText = function (post) { post.text = post.full_text.substr(post.display_text_range[0], post.display_text_range[1]); }; obj.ProcessURLs = function (post) { var urls = post.entities.urls; if (!urls || urls.length <= 0) return true; Logger.debug('twitter', 'Processing URLs for post', post, urls); for (var i in urls) { post.text = post.text.replace(RegExp(urls[i].url, "g"), $sce.trustAsUrl('<a href="' + urls[i].expanded_url + '" target="_blank">' + urls[i].url + '</a>')); } }; obj.ProcessHashtags = function (post) { var hashtags = post.entities.hashtags; if (!hashtags || hashtags.length <= 0) return true; Logger.debug('twitter', 'Processing hashtags for post', post, hashtags); for (var i in hashtags) { post.text = post.text.replace(RegExp('#' + hashtags[i].text, "g"), $sce.trustAsUrl('<a href="https://twitter.com/search?q=%23' + hashtags[i].text + '" target="_blank">#' + hashtags[i].text + '</a>')); } }; obj.ProcessMentions = function (post) { var mentions = post.entities.user_mentions; if (!mentions || mentions.length <= 0) return true; Logger.debug('twitter', 'Processing mentions for post', post, mentions); for (var i in mentions) { post.text = post.text.replace(RegExp('@' + mentions[i].screen_name, "g"), $sce.trustAsUrl('<a href="https://twitter.com/' + mentions[i].screen_name + '" target="_blank">@' + mentions[i].screen_name + '</a>')); } }; obj.ProcessMedia = function (post) { var media = post.entities.media; if (!media || media.length <= 0) return true; Logger.debug('twitter', 'Processing media for post', post, media); for (var i in media) { post.text = post.text.replace(RegExp(media[i].url, "g"), ''); post.image = media[i]; //Logger.debug('twitter', 'Setting image for', post, 'to', media[i]); } }; return obj; }]); 'use strict'; angular.module('cevo.gte').service('VODs', ["$rootScope", "$http", "Logger", "cevo", "VOD", function ($rootScope, $http, Logger, cevo, VOD) { var obj = this; obj.$list = function (tag, pageSize, page) { return $http({ method: 'GET', url: cevo.endpoint + 'liveTv/vod' + (tag ? '/tags/' + tag : ''), params: { pageSize: pageSize, page: page } }).then(function (data) { return cevo.util.objectify(data.data.vods, VOD); }); }; return obj; }]);