UNPKG

aping-plugin-footballdata

Version:
8 lines 11.7 kB
/** @name: aping-plugin-footballdata @version: 0.5.6 (23-12-2016) @author: Jonathan Hornung @url: https://github.com/JohnnyTheTank/apiNG-plugin-footballdata @license: MIT */ "use strict";angular.module("jtt_aping_footballdata",["jtt_footballdata"]).directive("apingFootballdata",["apingFootballDataHelper","apingUtilityHelper","footballdataFactory",function(a,b,c){return{require:"?aping",restrict:"A",replace:"false",link:function(d,e,f,g){var h=g.getAppSettings(),i=b.parseJsonFromAttributes(f.apingFootballdata,a.getThisPlatformString(),h);i.forEach(function(d){var e={model:h.model};angular.isDefined(h.getNativeData)?e.getNativeData=h.getNativeData:e.getNativeData=!1;var f={apiKey:b.getApiCredentials(a.getThisPlatformString(),"api_key")};if("http"===d.protocol||"https"===d.protocol?f.protocol=d.protocol:"http"===h.protocol||"https"===h.protocol?f.protocol=h.protocol:f.protocol="",angular.isDefined(d.items)){if(0===d.items||"0"===d.items)return!1;(d.items<0||isNaN(d.items))&&(d.items=void 0)}switch(e.model){case"fbd-team":angular.isDefined(d.teamId)?(f.id=d.teamId,c.getTeam(f).then(function(b){b&&g.concatToResults(a.getObjectByJsonData(b,e))})):angular.isDefined(d.leagueId)&&(f.id=d.leagueId,c.getTeamsBySeason(f).then(function(b){b&&g.concatToResults(a.getObjectByJsonData(b,e))}));break;case"fbd-league":angular.isDefined(d.year)?("$CURRENT"!==d.year&&(f.season=d.year),c.getSeasons(f).then(function(b){b&&g.concatToResults(a.getObjectByJsonData(b,e))})):angular.isDefined(d.leagueId)&&(f.id=d.leagueId,c.getSeason(f).then(function(b){b&&g.concatToResults(a.getObjectByJsonData(b,e))}));break;case"fbd-player":angular.isDefined(d.teamId)&&(f.id=d.teamId,c.getPlayersByTeam(f).then(function(b){b&&g.concatToResults(a.getObjectByJsonData(b,e))}));break;case"fbd-table":angular.isDefined(d.leagueId)&&(f.id=d.leagueId,angular.isDefined(d.matchday)&&(f.matchday=d.matchday),c.getLeagueTableBySeason(f).then(function(b){b&&g.concatToResults(a.getObjectByJsonData(b,e))}));break;case"fbd-fixture":angular.isDefined(d.fixtureId)?(f.id=d.fixtureId,c.getFixture(f).then(function(b){b&&g.concatToResults(a.getObjectByJsonData(b,e))})):angular.isDefined(d.leagueId)?(f.id=d.leagueId,angular.isDefined(d.timeFrame)&&(f.timeFrame=d.timeFrame),angular.isDefined(d.matchday)&&(f.matchday=d.matchday),c.getFixturesBySeason(f).then(function(b){b&&g.concatToResults(a.getObjectByJsonData(b,e))})):angular.isDefined(d.teamId)?(f.id=d.teamId,angular.isDefined(d.timeFrame)&&(f.timeFrame=d.timeFrame),angular.isDefined(d.year)&&"$CURRENT"!==d.year&&(f.season=d.year),angular.isDefined(d.venue)&&(f.venue=d.venue),c.getFixturesByTeam(f).then(function(b){b&&g.concatToResults(a.getObjectByJsonData(b,e))})):(angular.isDefined(d.timeFrame)&&(f.timeFrame=d.timeFrame),angular.isDefined(d.leagueCodes)&&(f.league=d.leagueCodes),c.getFixtures(f).then(function(b){b&&g.concatToResults(a.getObjectByJsonData(b,e))}))}})}}}]),angular.module("jtt_aping_footballdata").service("apingFootballDataHelper",["apingModels","apingTimeHelper","apingUtilityHelper",function(a,b,c){this.getThisPlatformString=function(){return"footballdata"},this.getIdByLinksObject=function(a,b){angular.isUndefined(b)&&(b="self");var c;if(a&&a[b]&&a[b].href){var d=a[b].href.split("/").pop();d.length>0&&(c=d)}return c},this.getObjectByJsonData=function(a,b){var c=[];if(a&&a.data){var d=this,e=[];switch(b.model){case"fbd-team":angular.isDefined(a.data.teams)?e=a.data.teams:e.push(a.data);break;case"fbd-table":e.push(a.data);break;case"fbd-league":a.data.constructor===Array?e=a.data:e.push(a.data);break;case"fbd-player":a.data.players&&a.data.players.length>0&&(e=a.data.players);break;case"fbd-fixture":angular.isDefined(a.data.fixture)?e.push(a.data.fixture):angular.isDefined(a.data.fixtures)&&(e=a.data.fixtures)}e.constructor===Array&&e.length>0&&angular.forEach(e,function(a,e){var f;f=b.getNativeData===!0||"true"===b.getNativeData?a:d.getItemByJsonData(a,b.model),f&&c.push(f)})}return c},this.getItemByJsonData=function(a,b){var c={};if(a&&b)switch(b){case"fbd-team":c=this.getFbdTeamItemByJsonData(a);break;case"fbd-league":c=this.getFbdLeagueItemByJsonData(a);break;case"fbd-player":c=this.getFbdPlayerItemByJsonData(a);break;case"fbd-table":c=this.getFbdTableItemByJsonData(a);break;case"fbd-fixture":c=this.getFbdFixtureItemByJsonData(a);break;default:return!1}return c},this.getFbdTeamItemByJsonData=function(b){var c=a.getNew("fbd-team",this.getThisPlatformString());return angular.extend(c,{teamId:b._links?this.getIdByLinksObject(b._links):void 0,code:b.code||void 0,shortName:b.shortName||void 0,name:b.name||void 0,squadMarketValue:b.squadMarketValue||void 0,crestUrl:b.crestUrl?b.crestUrl.replace("http://","https://"):void 0}),c},this.getFbdLeagueItemByJsonData=function(b){var c=a.getNew("fbd-league",this.getThisPlatformString());return angular.extend(c,{leagueId:b.id||void 0,league:b.league||void 0,caption:b.caption||void 0,currentMatchday:b.currentMatchday||void 0,lastUpdated:b.lastUpdated||void 0,numberOfGames:b.numberOfGames||void 0,numberOfMatchdays:b.numberOfMatchdays||void 0,numberOfTeams:b.numberOfTeams||void 0,year:b.year||void 0}),c},this.getFbdPlayerItemByJsonData=function(b){var c=a.getNew("fbd-player",this.getThisPlatformString());return angular.extend(c,{contractUntil:b.contractUntil||void 0,dateOfBirth:b.dateOfBirth||void 0,jerseyNumber:b.jerseyNumber||void 0,marketValue:b.marketValue||void 0,name:b.name||void 0,nationality:b.nationality||void 0,position:b.position||void 0}),c},this.getFbdTableItemByJsonData=function(b){var c=a.getNew("fbd-table",this.getThisPlatformString()),d=this;return angular.extend(c,{leagueId:b._links?d.getIdByLinksObject(b._links,"soccerseason"):void 0,leagueCaption:b.leagueCaption||void 0,matchday:b.matchday||void 0}),b.standing&&b.standing.constructor===Array&&b.standing.length>0?(c.standing=[],angular.forEach(b.standing,function(a,b){c.standing.push({teamId:a.teamId||(a._links?d.getIdByLinksObject(a._links,"team"):void 0),away:a.away||void 0,crestURI:a.crestURI?a.crestURI.replace("http://","https://"):void 0,draws:angular.isDefined(a.draws)?a.draws:void 0,goalDifference:angular.isDefined(a.goalDifference)?a.goalDifference:void 0,goals:angular.isDefined(a.goals)?a.goals:void 0,goalsAgainst:angular.isDefined(a.goalsAgainst)?a.goalsAgainst:void 0,home:a.home||void 0,losses:angular.isDefined(a.losses)?a.losses:void 0,playedGames:angular.isDefined(a.playedGames)?a.playedGames:void 0,points:angular.isDefined(a.points)?a.points:void 0,position:angular.isDefined(a.position)?a.position:void 0,rank:angular.isDefined(a.rank)?a.rank:void 0,teamName:a.teamName||void 0,wins:angular.isDefined(a.wins)?a.wins:void 0,group:a.group||void 0,team:a.team||void 0})})):"object"==typeof b.standings&&null!==b.standings&&(c.groups=[],angular.forEach(b.standings,function(a,b){var e=[];angular.forEach(a,function(a,b){e.push({teamId:a.teamId||(a._links?d.getIdByLinksObject(a._links,"team"):void 0),away:a.away||void 0,crestURI:a.crestURI?a.crestURI.replace("http://","https://"):void 0,draws:angular.isDefined(a.draws)?a.draws:void 0,goalDifference:angular.isDefined(a.goalDifference)?a.goalDifference:void 0,goals:angular.isDefined(a.goals)?a.goals:void 0,goalsAgainst:angular.isDefined(a.goalsAgainst)?a.goalsAgainst:void 0,home:a.home||void 0,losses:angular.isDefined(a.losses)?a.losses:void 0,playedGames:angular.isDefined(a.playedGames)?a.playedGames:void 0,points:angular.isDefined(a.points)?a.points:void 0,position:angular.isDefined(a.position)?a.position:void 0,rank:angular.isDefined(a.rank)?a.rank:void 0,teamName:a.teamName||void 0,wins:angular.isDefined(a.wins)?a.wins:void 0,group:a.group||void 0,team:a.team||void 0})}),c.groups.push({name:b,standing:e})})),c},this.getFbdFixtureItemByJsonData=function(b){var c=a.getNew("fbd-fixture",this.getThisPlatformString());return angular.extend(c,{fixtureId:b._links?this.getIdByLinksObject(b._links):void 0,awayTeamName:b.awayTeamName||void 0,date:b.date||void 0,homeTeamName:b.homeTeamName||void 0,matchday:b.matchday||void 0,result:b.result||void 0,status:b.status||void 0}),c}}]),angular.module("jtt_footballdata",[]).factory("footballdataFactory",["$http","footballdataSearchDataService",function(a,b){var c={};return c.getSeasons=function(c){var d=b.getNew("getSeasons",c);return a({method:"GET",url:d.url,params:d.object,headers:{"X-Auth-Token":c.apiKey}})},c.getSeason=function(c){var d=b.getNew("getSeason",c);return a({method:"GET",url:d.url,params:d.object,headers:{"X-Auth-Token":c.apiKey}})},c.getTeam=function(c){var d=b.getNew("getTeam",c);return a({method:"GET",url:d.url,params:d.object,headers:{"X-Auth-Token":c.apiKey?c.apiKey:apiKey}})},c.getPlayersByTeam=function(c){var d=b.getNew("getPlayersByTeam",c);return a({method:"GET",url:d.url,params:d.object,headers:{"X-Auth-Token":c.apiKey?c.apiKey:apiKey}})},c.getFixtures=function(c){var d=b.getNew("getFixtures",c);return a({method:"GET",url:d.url,params:d.object,headers:{"X-Auth-Token":c.apiKey?c.apiKey:apiKey}})},c.getFixture=function(c){var d=b.getNew("getFixture",c);return a({method:"GET",url:d.url,params:d.object,headers:{"X-Auth-Token":c.apiKey?c.apiKey:apiKey}})},c.getFixturesByTeam=function(c){var d=b.getNew("getFixturesByTeam",c);return a({method:"GET",url:d.url,params:d.object,headers:{"X-Auth-Token":c.apiKey?c.apiKey:apiKey}})},c.getTeamsBySeason=function(c){var d=b.getNew("getTeamsBySeason",c);return a({method:"GET",url:d.url,params:d.object,headers:{"X-Auth-Token":c.apiKey?c.apiKey:apiKey}})},c.getLeagueTableBySeason=function(c){var d=b.getNew("getLeagueTableBySeason",c);return a({method:"GET",url:d.url,params:d.object,headers:{"X-Auth-Token":c.apiKey?c.apiKey:apiKey}})},c.getFixturesBySeason=function(c){var d=b.getNew("getFixturesBySeason",c);return a({method:"GET",url:d.url,params:d.object,headers:{"X-Auth-Token":c.apiKey?c.apiKey:apiKey}})},c}]).service("footballdataSearchDataService",function(){this.getApiBaseUrl=function(a){switch(a){case"http":case"https":a+=":";break;default:a=""}return a+"//api.football-data.org/v1/"},this.fillDataInObjectByList=function(a,b,c){return angular.forEach(c,function(c,d){angular.isDefined(b[c])&&(a.object[c]=b[c])}),a},this.getNew=function(a,b){var c={object:{},url:""};switch(a){case"getSeasons":c=this.fillDataInObjectByList(c,b,["apiKey","season"]),c.url=this.getApiBaseUrl(b.protocol)+"soccerseasons/";break;case"getSeason":c=this.fillDataInObjectByList(c,b,["apiKey"]),c.url=this.getApiBaseUrl(b.protocol)+"soccerseasons/"+b.id;break;case"getTeam":c=this.fillDataInObjectByList(c,b,["apiKey"]),c.url=this.getApiBaseUrl(b.protocol)+"teams/"+b.id;break;case"getPlayersByTeam":c=this.fillDataInObjectByList(c,b,["apiKey"]),c.url=this.getApiBaseUrl(b.protocol)+"teams/"+b.id+"/players";break;case"getFixtures":c=this.fillDataInObjectByList(c,b,["apiKey","league","timeFrame"]),c.url=this.getApiBaseUrl(b.protocol)+"fixtures";break;case"getFixture":c=this.fillDataInObjectByList(c,b,["apiKey","head2head"]),c.url=this.getApiBaseUrl(b.protocol)+"fixtures/"+b.id;break;case"getTeamsBySeason":c=this.fillDataInObjectByList(c,b,["apiKey"]),c.url=this.getApiBaseUrl(b.protocol)+"soccerseasons/"+b.id+"/teams";break;case"getLeagueTableBySeason":c=this.fillDataInObjectByList(c,b,["apiKey","matchday"]),c.url=this.getApiBaseUrl(b.protocol)+"soccerseasons/"+b.id+"/leagueTable";break;case"getFixturesBySeason":c=this.fillDataInObjectByList(c,b,["apiKey","matchday","timeFrame"]),c.url=this.getApiBaseUrl(b.protocol)+"soccerseasons/"+b.id+"/fixtures";break;case"getFixturesByTeam":c=this.fillDataInObjectByList(c,b,["apiKey","season","timeFrame","venue"]),c.url=this.getApiBaseUrl(b.protocol)+"teams/"+b.id+"/fixtures"}return c}});