[LIB-5] Site sources of snooker-score-api
[snooker-score-api.git] / src / site / apt / examples / work-with-the-cached-api.apt.vm
1  ------
2  Working with the cached version API
3  ------
4  Dmitry Samoshin aka gotty
5  ------
6  2017-01-27
7  ------
8
9 ~~ Copyright (c) 2017. Developed by Hedgecode.
10 ~~
11 ~~ Licensed under the Apache License, Version 2.0 (the "License");
12 ~~ you may not use this file except in compliance with the License.
13 ~~ You may obtain a copy of the License at
14 ~~
15 ~~   http://www.apache.org/licenses/LICENSE-2.0
16 ~~
17 ~~ Unless required by applicable law or agreed to in writing, software
18 ~~ distributed under the License is distributed on an "AS IS" BASIS,
19 ~~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 ~~ See the License for the specific language governing permissions and
21 ~~ limitations under the License.
22
23 ~~ NOTE: For help with the syntax of this file, see:
24 ~~ http://maven.apache.org/doxia/references/apt-format.html
25
26 Working with the cached version API
27
28   When you first call the API method to get the main interface of the library
29
30 +-------
31 SnookerScoreAPI api = Snooker.API();
32 +-------
33
34   by default we get the cached implementation of the API interface <<<SnookerScoreAPI>>>.\
35   What are its advantages?
36
37 ===
38
39   Firstly, when using the cached version of the interface for various queries, you get a full range 
40   of useful information. For example, when requesting current matches, the sample will contain 
41   links to the tournament (object <<<Event>>>) as well as to the players 
42   participating in each match (objects <<<Player>>>) in addition to other information:
43
44 +-------
45 SnookerScoreAPI api = Snooker.API();
46 OngoingMatches matches = api.getOngoingMatches();
47 for (OngoingMatch match : matches) {
48     Event event = match.event();
49     Player player1 = match.player1();
50     Player player2 = match.player2();
51 }
52 +-------
53
54   Whereas when working with the noncached version of the interface, you will have to make 
55   additional queries about the tournament and players in order to get full information 
56   about the ongoing matches:
57
58 +-------
59 SnookerScoreAPI api = Snooker.uncachedAPI();
60 OngoingMatches matches = api.getOngoingMatches();
61 for (OngoingMatch match : matches) {
62     Event event = api.getEvent(match.eventId());
63     Player player1 = api.getPlayer(match.player1Id());
64     Player player2 = api.getPlayer(match.player2Id());
65 }
66 +-------
67
68 ===
69
70   Secondly, in the cached version of the interface, you are given the opportunity to specify 
71   the current season, with the events of which in the future you are going to work 
72   by requesting tournaments and matches:
73
74 +-------
75 SnookerScoreAPI api = Snooker.API();
76 api.setCurrentSeason(Season.getSeason(2015));
77 +-------
78
79 ===
80
81   P.S. If you need to use the noncached version of the API, you can get it as follows:
82
83 +-------
84 SnookerScoreAPI uncachedApi = Snooker.uncachedAPI();
85 +-------