|
1 | 1 | package com.databox.sdk.sample; |
2 | 2 |
|
| 3 | +import java.io.IOException; |
| 4 | +import java.text.SimpleDateFormat; |
| 5 | +import java.util.ArrayList; |
| 6 | +import java.util.List; |
| 7 | +import java.util.Locale; |
| 8 | + |
3 | 9 | import org.slf4j.Logger; |
4 | 10 | import org.slf4j.LoggerFactory; |
5 | 11 |
|
6 | | -import com.databox.sdk.DataSink; |
7 | | -import com.databox.sdk.ResponseWrapper; |
8 | | -import com.databox.sdk.impl.DataboxDataSource; |
9 | | -import com.databox.sdk.impl.DataboxSink; |
10 | | - |
11 | 12 | /** |
12 | 13 | * |
13 | 14 | * @author Uros Majeric |
14 | 15 | * |
15 | 16 | */ |
16 | 17 | public class DataboxSample { |
17 | 18 | private static final Logger logger = LoggerFactory.getLogger(DataboxSample.class); |
| 19 | + private static final String TOKEN = "my_api_key"; |
18 | 20 |
|
19 | 21 | public static void main(String[] args) throws Exception { |
20 | | - String spaceAccessToken = "hd32o1ga8sf7sad0fu9sdufs8440442kj2"; |
21 | | - |
22 | | - DataSink<DataboxDataSource> sink = new DataboxSink(); |
23 | | - |
24 | | - DataboxDataSource connection = new DataboxDataSource(spaceAccessToken); |
25 | | - XSLDailyDataProvider xlsxDataProvider = new XSLDailyDataProvider("cycling.xlsx"); |
26 | | - connection.addDataProvider(xlsxDataProvider); |
27 | | - |
28 | | - // DefaultDataProvider dataProvider = new DefaultDataProvider(); |
29 | | - // Calendar c = new GregorianCalendar(); |
30 | | - // dataProvider.addKPI(new KPI.Builder().setKey("visits_this_month").setValue(234D).setDate(c.getTime()).build()); |
31 | | - // c.add(Calendar.DAY_OF_MONTH, -1); |
32 | | - // dataProvider.addKPI(new KPI.Builder().setKey("visits_this_month").setValue(431D).build()); |
33 | | - // connection.addDataProvider(dataProvider); |
34 | | - |
35 | | - ResponseWrapper response = sink.push(connection); |
36 | | - if (!response.isSucceeded()) { |
37 | | - logger.error(sink.getLogs(connection)); |
38 | | - } else { |
39 | | - logger.info(response.getMessage()); |
| 22 | + final String TOKEN = "my_api_key"; |
| 23 | + Databox notification = new Databox(TOKEN); |
| 24 | + try { |
| 25 | + List<Databox.KPI> kpis = new ArrayList<>(); |
| 26 | + kpis.add(new Databox.KPI().setKey("my_first_key").setValue(1201.41)); |
| 27 | + kpis.add(new Databox.KPI().setKey("my_second_key").setValue(8249)); |
| 28 | + notification.push(kpis); |
| 29 | + } catch (Exception e) { |
| 30 | + logger.error(e.getLocalizedMessage(), e); |
40 | 31 | } |
41 | 32 | } |
42 | 33 | } |
0 commit comments