Advertisement
Guest User

Untitled

a guest
May 12th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. Skip to content
  3. This repository
  4.  
  5.     Pull requests
  6.     Issues
  7.     Marketplace
  8.     Explore
  9.  
  10.     @Brylat
  11.  
  12. 1
  13. 0
  14.  
  15.     0
  16.  
  17. Brylat/Spa-FootballSpy
  18. Code
  19. Issues 0
  20. Pull requests 0
  21. Projects 0
  22. Wiki
  23. Insights
  24. Settings
  25. Spa-FootballSpy/src/app/shared/football-data.service.ts
  26. d405d3e 2 days ago
  27. @Brylat Brylat add new api method
  28. @adian
  29. @Brylat
  30. 234 lines (195 sloc) 9.91 KB
  31. import { Injectable } from '@angular/core';
  32. import { Observable } from 'rxjs/Observable';
  33. import 'rxjs/add/operator/map';
  34. import 'rxjs/add/operator/mergeMap';
  35. import { HttpClient } from '@angular/common/http';
  36.  
  37. import { ApiResponse } from './objects-template/api-response';
  38. import { AccessToken } from './objects-template/access-token';
  39. import { SimpleCountry } from './objects-template/simple-country';
  40. import { Event } from './objects-template/event';
  41. import { Match } from './objects-template/match';
  42. import { League } from './objects-template/league';
  43. import { Player } from './objects-template/player';
  44. import { Season } from './objects-template/season';
  45. import { Stand } from './objects-template/stand';
  46. import { Stage } from './objects-template/stage';
  47. import { Stat } from './objects-template/stat';
  48. import { Team } from './objects-template/team';
  49. import { TeamSeason } from './objects-template/team-season';
  50. import { TeamSeasonPlayer } from './objects-template/team-season-player';
  51.  
  52. @Injectable()
  53. export class FootballDataService {
  54.   static CurrentAccesToken: Observable<AccessToken>;
  55.  
  56.   private BASE_API_URL = 'https://api.sportdeer.com/v1/';
  57.   private REFRESH_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI1YWRiMWY5ZTI3OTNiYjU2ODI2NTg3NDYiLCJpYXQiOjE1MjQzMDk5NTR9.ZuXvnZwCGpRLuP0gypum63omAC9zXGKRC5vo5F98mwc';
  58.  
  59.   constructor(private http: HttpClient) { }
  60.  
  61.   // TODO store current key 30 min
  62.   public getAccesKey() {
  63.      return this.http.get<AccessToken>(this.BASE_API_URL + 'accessToken?refresh_token=' + this.REFRESH_KEY);
  64.   }
  65.  
  66.   public GetAllCountry() {
  67.     return this.getAccesKey().flatMap(x => {
  68.       return this.http.get<ApiResponse<SimpleCountry[]>>(this.BASE_API_URL + 'countries?access_token=' + x.new_access_token);
  69.     });
  70.   }
  71.  
  72.   public GetCountryById(id: number) {
  73.     return this.getAccesKey().flatMap(x => {
  74.       return this.http.get<ApiResponse<SimpleCountry[]>>(this.BASE_API_URL + 'countries/' + id + '?access_token=' + x.new_access_token);
  75.     });
  76.   }
  77.  
  78.   public GetEventsByMatchId(id: number, page: number = 1) {
  79.     return this.getAccesKey().flatMap(x => {
  80.       return this.http.get<ApiResponse<Event[]>>(this.BASE_API_URL + 'fixtures/' + id + '/events?page=' + page + '&access_token=' + x.new_access_token);
  81.     });
  82.   }
  83.  
  84.   public GetMatchById(id: number) {
  85.     return this.getAccesKey().flatMap(x => {
  86.       return this.http.get<ApiResponse<Match[]>>(this.BASE_API_URL + 'fixtures/' + id + '?access_token=' + x.new_access_token);
  87.     });
  88.   }
  89.  
  90.   public GetMatchBySeasonId(id: number, page: number = 1) {
  91.     return this.getAccesKey().flatMap(x => {
  92.       return this.http.get<ApiResponse<Match[]>>(this.BASE_API_URL + 'seasons/' + id + '/fixtures?page=' + page + '&access_token=' + x.new_access_token);
  93.     });
  94.   }
  95.  
  96.   public GetMatchByStagesId(id: number, page: number = 1) {
  97.     return this.getAccesKey().flatMap(x => {
  98.       return this.http.get<ApiResponse<Match[]>>(this.BASE_API_URL + 'stages/' + id + '/fixtures?page=' + page + '&access_token=' + x.new_access_token);
  99.     });
  100.   }
  101.  
  102.   public GetMatchBetweenTeamsByTeamSeasonId(teamSeasonId1: number, teamSeasonId2: number, page: number = 1) {
  103.     return this.getAccesKey().flatMap(x => {
  104.       return this.http.get<ApiResponse<Match[]>>(this.BASE_API_URL + 'teamSeason2teamSeason?teamSeason1=' + teamSeasonId1 + '&teamSeason2=' + teamSeasonId2 + '&page=' + page + '&access_token=' + x.new_access_token);
  105.     });
  106.   }
  107.  
  108.   public GetMatchBetweenTeamsByTeamId(teamId1: number, teamId2: number, page: number = 1) {
  109.     return this.getAccesKey().flatMap(x => {
  110.       return this.http.get<ApiResponse<Match[]>>(this.BASE_API_URL + 'team2team?team1=' + teamId1 + '&team2=' + teamId2 + '&page=' + page + '&access_token=' + x.new_access_token);
  111.     });
  112.   }
  113.  
  114.   public GetAllInplay(page: number = 1) {
  115.     return this.getAccesKey().flatMap(x => {
  116.       return this.http.get<ApiResponse<Match[]>>(this.BASE_API_URL + 'inplay?page=' + page + '&access_token=' + x.new_access_token);
  117.     });
  118.   }
  119.  
  120.   public GetAllInplayBySeasonId(id: number, page: number = 1) {
  121.     return this.getAccesKey().flatMap(x => {
  122.       return this.http.get<ApiResponse<Match[]>>(this.BASE_API_URL + 'seasons/' + id + '/inplay?page=' + page + '&access_token=' + x.new_access_token);
  123.     });
  124.   }
  125.  
  126.   public GetUpcomingByStageId(id: number, page: number = 1) {
  127.     return this.getAccesKey().flatMap(x => {
  128.       return this.http.get<ApiResponse<Match[]>>(this.BASE_API_URL + 'stages/' + id + '/upcoming?page=' + page + '&access_token=' + x.new_access_token);
  129.     });
  130.   }
  131.  
  132.   public GetUpcomingBySeasonId(id: number, page: number = 1) {
  133.     return this.getAccesKey().flatMap(x => {
  134.       return this.http.get<ApiResponse<Match[]>>(this.BASE_API_URL + 'seasons/' + id + '/upcoming?page=' + page + '&access_token=' + x.new_access_token);
  135.     });
  136.   }
  137.  
  138.   public GetUpcomingByDate(dateFrom: Date, dateTo: Date, page: number = 1) {
  139.     return this.getAccesKey().flatMap(x => {
  140.       return this.http.get<ApiResponse<Match[]>>(this.BASE_API_URL + 'upcoming?dateFrom=' + dateFrom.toISOString() + '&dateTo=' + dateTo.toISOString() + '&page=' + page + '&access_token=' + x.new_access_token);
  141.     });
  142.   }
  143.  
  144.   public GetAllLeagues(page: number = 1) {
  145.     return this.getAccesKey().flatMap(x => {
  146.       return this.http.get<ApiResponse<League[]>>(this.BASE_API_URL + 'leagues?page=' + page + '&access_token=' + x.new_access_token);
  147.     });
  148.   }
  149.  
  150.   public GetLeaguesByCountryId(id: number, page: number = 1) {
  151.     return this.getAccesKey().flatMap(x => {
  152.       return this.http.get<ApiResponse<League[]>>(this.BASE_API_URL + 'countries/' + id + '/leagues?page=' + page + '&access_token=' + x.new_access_token);
  153.     });
  154.   }
  155.  
  156.   public GetLeagueById(id: number) {
  157.     return this.getAccesKey().flatMap(x => {
  158.       return this.http.get<ApiResponse<League[]>>(this.BASE_API_URL + 'leagues/' + id + '?access_token=' + x.new_access_token);
  159.     });
  160.   }
  161.  
  162.   public GetLineupByMatchId(id: number, page: number = 1) {
  163.     return this.getAccesKey().flatMap(x => {
  164.       return this.http.get<ApiResponse<Player[]>>(this.BASE_API_URL + 'fixtures/' + id + '/lineups?page=' + page + '&access_token=' + x.new_access_token);
  165.     });
  166.   }
  167.  
  168.   public GetPlayerById(id: number) {
  169.     return this.getAccesKey().flatMap(x => {
  170.       return this.http.get<ApiResponse<Player[]>>(this.BASE_API_URL + 'players/' + id + '?access_token=' + x.new_access_token);
  171.     });
  172.   }
  173.  
  174.   public GetAllSeasons(page: number = 1) {
  175.     return this.getAccesKey().flatMap(x => {
  176.       return this.http.get<ApiResponse<Season[]>>(this.BASE_API_URL + 'seasons?page=' + page + '&access_token=' + x.new_access_token);
  177.     });
  178.   }
  179.  
  180.   public GetAllSeasonsByLeagueId(id: number, page: number = 1) {
  181.     return this.getAccesKey().flatMap(x => {
  182.       return this.http.get<ApiResponse<Season[]>>(this.BASE_API_URL + 'leagues/' + id + '/seasons?page=' + page + '&access_token=' + x.new_access_token);
  183.     });
  184.   }
  185.  
  186.   public GetSeasonsById(id: number, page: number = 1) {
  187.     return this.getAccesKey().flatMap(x => {
  188.       return this.http.get<ApiResponse<Season[]>>(this.BASE_API_URL + 'seasons/' + id + '?page=' + page + '&access_token=' + x.new_access_token);
  189.     });
  190.   }
  191.  
  192.   public GetAllStages(page: number = 1) {
  193.     return this.getAccesKey().flatMap(x => {
  194.       return this.http.get<ApiResponse<Stage[]>>(this.BASE_API_URL + 'stages?page=' + page + '&access_token=' + x.new_access_token);
  195.     });
  196.   }
  197.  
  198.   public GetAllStagesBySeasonId(id: number, page: number = 1) {
  199.     return this.getAccesKey().flatMap(x => {
  200.       return this.http.get<ApiResponse<Stage[]>>(this.BASE_API_URL + 'seasons/' + id + '/stages?page=' + page + '&access_token=' + x.new_access_token);
  201.     });
  202.   }
  203.  
  204.   public GetStageById(id: number) {
  205.     return this.getAccesKey().flatMap(x => {
  206.       return this.http.get<ApiResponse<Stage[]>>(this.BASE_API_URL + 'stages/' + id + '?access_token=' + x.new_access_token);
  207.     });
  208.   }
  209.  
  210.   public GetStandingByStageId(id: number) {
  211.     return this.getAccesKey().flatMap(x => {
  212.       return this.http.get<ApiResponse<Stand[]>>(this.BASE_API_URL + 'stages/' + id + '/standing?access_token=' + x.new_access_token);
  213.     });
  214.   }
  215.  
  216.   public GetStatsByMatchId(id: number) {
  217.     return this.getAccesKey().flatMap(x => {
  218.       return this.http.get<ApiResponse<Stat[]>>(this.BASE_API_URL + 'fixtures/' + id + '/stats?access_token=' + x.new_access_token);
  219.     });
  220.   }
  221.  
  222.   public GetStatsByTeamSeasonId(id: number) {
  223.     return this.getAccesKey().flatMap(x => {
  224.       return this.http.get<ApiResponse<Stat[]>>(this.BASE_API_URL + 'teamSeasons/' + id + '/stats?access_token=' + x.new_access_token);
  225.     });
  226.   }
  227.  
  228.   public GetStatsByTeamSeasonPlayerId(id: number) {
  229.     return this.getAccesKey().flatMap(x => {
  230.       return this.http.get<ApiResponse<Stat[]>>(this.BASE_API_URL + 'teamSeasonPlayers/' + id + '/stats?access_token=' + x.new_access_token);
  231.     });
  232.   }
  233.  
  234.   public GetTeamById(id: number) {
  235.     return this.getAccesKey().flatMap(x => {
  236.       return this.http.get<ApiResponse<Team[]>>(this.BASE_API_URL + 'teams/' + id + '?access_token=' + x.new_access_token);
  237.     });
  238.   }
  239.  
  240.   public GetTeamSeasonById(id: number) {
  241.     return this.getAccesKey().flatMap(x => {
  242.       return this.http.get<ApiResponse<TeamSeason[]>>(this.BASE_API_URL + 'teamSeasons/' + id + '?access_token=' + x.new_access_token);
  243.     });
  244.   }
  245.  
  246.   public GetTeamsSeasonBySeasonId(id: number, page: number = 1) {
  247.     return this.getAccesKey().flatMap(x => {
  248.       return this.http.get<ApiResponse<TeamSeason[]>>(this.BASE_API_URL + 'seasons/' + id + '/teamSeasons?page=' + page + '&access_token=' + x.new_access_token);
  249.     });
  250.   }
  251.  
  252.   public GetTeamSeasonPlayerById(id: number) {
  253.     return this.getAccesKey().flatMap(x => {
  254.       return this.http.get<ApiResponse<TeamSeasonPlayer[]>>(this.BASE_API_URL + 'teamSeasonPlayers/' + id + '?access_token=' + x.new_access_token);
  255.     });
  256.   }
  257.  
  258.   public GetTeamSeasonPlayersByTeamSeasonId(id: number, page: number = 1) {
  259.     return this.getAccesKey().flatMap(x => {
  260.       return this.http.get<ApiResponse<TeamSeasonPlayer[]>>(this.BASE_API_URL + 'teamSeasons/' + id + '/teamSeasonPlayers?page=' + page + '&access_token=' + x.new_access_token);
  261.     });
  262.   }
  263. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement