|
1 | | -# Databox Java SDK |
| 1 | +# Databox Java SDK 2.0 [](https://travis-ci.org/umajeric/databox-java-sdk) |
2 | 2 |
|
3 | | -[](https://travis-ci.org/databox/databox-java) |
4 | | - |
5 | | -The Java SDK for interacting with the Databox Push API. |
6 | | - |
7 | | -## Features |
8 | | - |
9 | | -* Built on top of a solid and extensively tested framework [Apache HttpComponents](http://hc.apache.org/) |
10 | | -* Uses Java library to convert JSON to Java objects and vice-versa [google-gson](https://code.google.com/p/google-gson) |
11 | | -* Tested and well-documented |
| 3 | +The Java SDK for interacting with the Databox Push API v 2.0. |
12 | 4 |
|
13 | 5 | ## Requirements |
14 | 6 |
|
15 | 7 | * Java >= 1.5 or later, |
16 | | -* Maven >= 3.0.3 (optional but highly recomended) |
17 | | - |
18 | | -## Maven supported |
19 | | - |
20 | | -Add a maven repository to your pom file: |
21 | | -```xml |
22 | | -<repository> |
23 | | - <id>umajeric-public-repo</id> |
24 | | - <name>Umajeric Releases</name> |
25 | | - <releases> |
26 | | - <enabled>true</enabled> |
27 | | - </releases> |
28 | | - <snapshots> |
29 | | - <enabled>false</enabled> |
30 | | - </snapshots> |
31 | | - <url>https://raw.github.com/umajeric/maven-public-repo/releases</url> |
32 | | -</repository> |
33 | | -``` |
34 | | - |
35 | | -Then add a dependency for Databox Custom DataSource artefact (see [here](https://github.com/umajeric/maven-public-repo/tree/releases/com/databox/custom-datasource-sdk) to find the latest version): |
36 | | -```xml |
37 | | -<dependency> |
38 | | - <groupId>com.databox</groupId> |
39 | | - <artifactId>java-push-sdk</artifactId> |
40 | | - <version>LATEST</version> |
41 | | -</dependency> |
42 | | -``` |
43 | | - |
44 | | -## Basic usage of the Databox's `custom-datasource-sdk` client |
45 | | - |
46 | | -Most basic sample: |
47 | | - |
48 | | -```java |
49 | | - DataSink<DataboxDataSource> sink = new DataboxSink(); |
50 | | - |
51 | | - String accessToken = "hd32o1ga8sf7sad0fu9sdufs8440442kj2"; |
52 | | - DataboxDataSource dataSource = new DataboxDataSource(accessToken); |
53 | | - |
54 | | - DefaultDataProvider dataProvider = new DefaultDataProvider(); |
55 | | - dataProvider.addKPI(new KPI.Builder().setKey("new_signups").setValue(234D).withAttribute("no_of_items", 12).build()); |
56 | | - dataProvider.addKPI(new KPI.Builder().setKey("new_signups").setValue(234D).build()); |
57 | | - dataSource.addDataProvider(dataProvider); |
58 | | - |
59 | | - sink.push(dataSource); |
60 | | -``` |
| 8 | +* Maven >= 3.0.3 OR Gradle 2.x |
61 | 9 |
|
62 | | -One more advanced example (XSLDailyDataProvider implements DataProvider interface) that reads data from [Excel file](https://github.com/umajeric/databox-java-sdk/blob/master/sample/src/main/resources/cycling.xlsx): |
| 10 | +## Basic usage of the Databox's `databox-sdk` client |
63 | 11 |
|
64 | 12 | ```java |
65 | | - DataboxSink sink = new DataboxSink(); |
66 | | - List<DataboxDataSource> dataSources = new ArrayList<DataboxDataSource>(); |
67 | | - |
68 | | - String accessToken = "hd32o1ga8sf7sad0fu9sdufs8440442kj2"; |
69 | | - DataboxDataSource dataSource = new DataboxDataSource(accessToken); |
70 | | - |
71 | | - XSLDailyDataProvider xlsxDataProvider = new XSLDailyDataProvider("cycling.xlsx"); |
72 | | - dataSource.addDataProvider(xlsxDataProvider); |
73 | | - /* You can implement your own data provider that implements DataProvider interface */ |
74 | | - // dataSource.addDataProvider(new MyCustomDataProviderImpl()); |
75 | | - dataSources.add(dataSource); |
76 | | - |
77 | | - /* For each data source we add a separate connection to the sink (each uses a different API Key and URL postfix) */ |
78 | | - // dataSource2 = new DataboxDataSource("5r4w91ga8sf7sad0fu9sdufs844044"); |
79 | | - /* We can use the same data provider for different connections */ |
80 | | - // dataSource2.addDataProvider(xlsxDataProvider); |
81 | | - // dataSources.add(dataSource2); |
82 | | - |
83 | | - for (DataSource ds : dataSources) { |
84 | | - sink.push(ds); |
| 13 | + String TOKEN = "your_token_goes_here"; |
| 14 | + Databox databox = new Databox(TOKEN); |
| 15 | + try { |
| 16 | + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); |
| 17 | + databox.send("kitchen_light", 341d, sdf.parse("2015-12-25 00:00:00")); |
| 18 | + } catch (Exception e) { |
| 19 | + System.err.println(e.getLocalizedMessage()); |
85 | 20 | } |
86 | | - |
87 | 21 | ``` |
88 | | - |
89 | | -Snippet from excel file: |
90 | | - |
91 | | -|Date |Total Time |Moving Time |Distance |Distance Unit |Average Speed |Max Speed |Speed Unit| |
92 | | -| -------:| ------:| ------:| ------:|:------ | ------:| ------:|:------| |
93 | | -|7/6/13 | 56 | 56 | 27.00 | km | 28.93 | 34.00 | km/h | |
94 | | -|7/7/13 | 34 | 34 | 13 | km | 22.94 | 30 | km/h | |
95 | | -|7/8/13 | 56 | 56 | 23 | km | 24.54 | 38 | km/h | |
96 | | -|7/9/13 | 63 | 63 | 28 | km | 26.67 | 35 | km/h | |
97 | | -|7/10/13 | 22 | 22 | 9 | km | 24.55 | 35 | km/h | |
98 | | - |
99 | | - |
100 | | - |
101 | | -More examples can be found here [Example project](https://github.com/umajeric/databox-java-sdk/tree/master/sample) |
102 | | - |
103 | | -## Documentation |
104 | | - |
105 | | -See [wiki page](https://github.com/umajeric/databox-java-sdk/wiki) for additional documentation. |
106 | | - |
107 | 22 | ## License |
108 | 23 |
|
109 | | -Databox `databox-java` is licensed under the Apache License, Version 2.0 - see the [LICENSE](http://www.apache.org/licenses/LICENSE-2.0) file for details |
| 24 | +`databox-sdk` is licensed under the Apache License, Version 2.0 - see the [LICENSE](http://www.apache.org/licenses/LICENSE-2.0) file for details |
| 25 | + |
| 26 | +## Credits |
110 | 27 |
|
111 | | -### Contributors & Credits |
| 28 | +### Contributors |
112 | 29 |
|
113 | | -- [Uros Majeric](http://github.com/umajeric) |
114 | 30 |
|
| 31 | +- [Uros Majeric](http://github.com/umajeric) |
0 commit comments