diff --git a/build.gradle b/build.gradle index bd357c1..b6edeb2 100644 --- a/build.gradle +++ b/build.gradle @@ -1,38 +1,38 @@ -plugins { - id 'java' -} - -group 'SeniorAssistant' -version '1.0-SNAPSHOT' - -sourceCompatibility = 1.8 - -repositories { - mavenCentral() -} - -dependencies { - testCompile group: 'junit', name: 'junit', version: '4.12' -// compile "com.sparkjava:spark-core:2.5.5" -// compile "org.slf4j:slf4j-simple:1.7.21" - compile "com.google.code.gson:gson:2.8.0" -// compile "org.xerial:sqlite-jdbc:3.15.1" - compile 'org.apache.httpcomponents:httpclient:4.5.3' - compile 'com.google.api-client:google-api-client:1.23.0' - compile group: 'com.google.oauth-client', name: 'google-oauth-client-jetty', version: '1.11.0-beta' - - -// z-way-lib and all its dependencies (from https://github.com/pathec/ZWay-library-for-Java) - - compile files('lib/zway-lib-0.2.9-SNAPSHOT.jar') -// compile 'com.google.code.gson:gson:2.4' //already up there - compile 'org.apache.commons:commons-lang3:3.4' - compile 'org.eclipse.jetty:jetty-client:9.3.11.v20160721' - compile 'org.eclipse.jetty:jetty-http:9.3.11.v20160721' - compile 'org.eclipse.jetty:jetty-io:9.3.11.v20160721' - compile 'org.eclipse.jetty:jetty-util:9.3.11.v20160721' - compile 'org.eclipse.jetty.websocket:websocket-api:9.3.12.v20160915' - compile 'org.eclipse.jetty.websocket:websocket-client:9.3.12.v20160915' - compile 'org.eclipse.jetty.websocket:websocket-common:9.3.12.v20160915' - compile 'org.slf4j:slf4j-simple:1.7.21' -} +plugins { + id 'java' +} + +group 'SeniorAssistant' +version '1.0-SNAPSHOT' + +sourceCompatibility = 1.8 + +repositories { + mavenCentral() +} + +dependencies { + testCompile group: 'junit', name: 'junit', version: '4.12' +// compile "com.sparkjava:spark-core:2.5.5" +// compile "org.slf4j:slf4j-simple:1.7.21" + compile "com.google.code.gson:gson:2.8.0" +// compile "org.xerial:sqlite-jdbc:3.15.1" + compile 'org.apache.httpcomponents:httpclient:4.5.3' + compile 'com.google.api-client:google-api-client:1.23.0' + compile group: 'com.google.oauth-client', name: 'google-oauth-client-jetty', version: '1.11.0-beta' + + +// z-way-lib and all its dependencies (from https://github.com/pathec/ZWay-library-for-Java) + + compile files('lib/zway-lib-0.2.9-SNAPSHOT.jar') +// compile 'com.google.code.gson:gson:2.4' //already up there + compile 'org.apache.commons:commons-lang3:3.4' + compile 'org.eclipse.jetty:jetty-client:9.3.11.v20160721' + compile 'org.eclipse.jetty:jetty-http:9.3.11.v20160721' + compile 'org.eclipse.jetty:jetty-io:9.3.11.v20160721' + compile 'org.eclipse.jetty:jetty-util:9.3.11.v20160721' + compile 'org.eclipse.jetty.websocket:websocket-api:9.3.12.v20160915' + compile 'org.eclipse.jetty.websocket:websocket-client:9.3.12.v20160915' + compile 'org.eclipse.jetty.websocket:websocket-common:9.3.12.v20160915' + compile 'org.slf4j:slf4j-simple:1.7.21' +} diff --git a/src/main/java/manage/AuthFITBIT.java b/src/main/java/manage/AuthFITBIT.java index b2497a3..e4b223a 100644 --- a/src/main/java/manage/AuthFITBIT.java +++ b/src/main/java/manage/AuthFITBIT.java @@ -34,8 +34,8 @@ public class AuthFITBIT { private static FileDataStoreFactory DATA_STORE_FACTORY; /** OAuth 2 scope. */ - private static final String SCOPE = "read"; - + private static final String SCOPE = "activity"; + //private static final String SCOPE[] = new String[]{"activity","heartrate","location","sleep"}; /** Global instance of the HTTP transport. */ private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport(); @@ -63,7 +63,8 @@ public class AuthFITBIT { // authorize LocalServerReceiver receiver = new LocalServerReceiver.Builder().setHost( OAuth2ClientCredentials.DOMAIN).setPort(OAuth2ClientCredentials.PORT).build(); - return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user"); + + return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user" ); } private static void run(HttpRequestFactory requestFactory) throws IOException { @@ -74,19 +75,19 @@ public class AuthFITBIT { UserData data = request.execute().parseAs(UserData.class); if (data.list.isEmpty()) { System.out.println("Error in retrieve user data"); - } /*else { + } else/* { if (data.hasMore) { System.out.print("First "); }*/ //i don't think is necessary /* System.out.println(data.list.size() + " favorite videos found:"); - for (Data datas: data.list) { - System.out.println(); + */for (FITIBITData datas: data.list) { + System.out.println(datas.toString());/* System.out.println("-----------------------------------------------"); System.out.println("ID: " + datas.id); System.out.println("Title: " + datas.title); System.out.println("Tags: " + datas.tags); System.out.println("URL: " + datas.url); - } + */ }/* }*/ //neither this } diff --git a/src/main/java/manage/Data.java b/src/main/java/manage/Data.java deleted file mode 100644 index 3ed39cf..0000000 --- a/src/main/java/manage/Data.java +++ /dev/null @@ -1,22 +0,0 @@ -package manage; - -import com.google.api.client.util.Key; - -import java.util.List; - -//da modificare inserendo gli attributi del json (activity, heartrate, sleep, location) - -public class Data { - - @Key - public String id; - - @Key - public List tags; - - @Key - public String title; - - @Key - public String url; -} \ No newline at end of file diff --git a/src/main/java/manage/FITIBITData.java b/src/main/java/manage/FITIBITData.java new file mode 100644 index 0000000..374cbf7 --- /dev/null +++ b/src/main/java/manage/FITIBITData.java @@ -0,0 +1,21 @@ +package manage; + +import com.google.api.client.util.Key; + +import java.util.List; + + +public class FITIBITData { + + @Key + public String activity; + + @Key + public String heartrate; + + @Key + public String sleep; + + @Key + public String location; +} \ No newline at end of file diff --git a/src/main/java/manage/OAuth2ClientCredentials.java b/src/main/java/manage/OAuth2ClientCredentials.java index 5c66572..0a77a40 100644 --- a/src/main/java/manage/OAuth2ClientCredentials.java +++ b/src/main/java/manage/OAuth2ClientCredentials.java @@ -3,16 +3,16 @@ package manage; public class OAuth2ClientCredentials { /** Value of the "API Key". */ - public static final String API_KEY = "22CSTL"; + public static final String API_KEY = "22CSTL"; //maybe togliere le virgolette /** Value of the "API Secret". */ - public static final String API_SECRET = "ea2452013abd35609940ce5601960a08"; + public static final String API_SECRET = "ea2452013abd35609940ce5601960a08"; //maybe togliere le virgolette /** Port in the "Callback URL". */ public static final int PORT = 8080; /** Domain name in the "Callback URL". */ - public static final String DOMAIN = "http://127.0.0.1:8080/"; + public static final String DOMAIN = "127.0.0.1"; public static void errorIfNotSpecified() { if (API_KEY.startsWith("Enter ") || API_SECRET.startsWith("Enter ")) { diff --git a/src/main/java/manage/UserData.java b/src/main/java/manage/UserData.java index 14e52cd..68bc9cc 100644 --- a/src/main/java/manage/UserData.java +++ b/src/main/java/manage/UserData.java @@ -7,7 +7,7 @@ import java.util.List; public class UserData { @Key - public List list; + public List list; /* @Key public int limit; diff --git a/src/test/java/TestLights.java b/src/test/java/TestLights.java index 6a2fdda..7f0cb51 100644 --- a/src/test/java/TestLights.java +++ b/src/test/java/TestLights.java @@ -1,38 +1,30 @@ import device.Hue; import org.junit.Test; -import java.util.HashSet; -import java.util.Set; - public class TestLights { @Test synchronized public void firstTestLights() throws InterruptedException { - //Hue lights = new Hue("http://localhost/api/newdeveloper/"); - Hue lights = new Hue(); - - Set toRemove = new HashSet<>(); - for(String str: lights.getNameLights()) - if(!str.equals("4")) - toRemove.add(str); - lights.removeLights(toRemove); + Hue lights = new Hue("http://localhost/api/newdeveloper/"); for(int i=0; i<10; i++) { lights.turnOn(); - this.wait(0b1111101000); // 1000 + this.wait(0b11001000); // 200 lights.turnOff(); - this.wait(0b1111101000); // 1000 + this.wait(0b11001000); // 200 } - lights.turnOn(); for(int i=0; i<256; i++) { lights.setBrightness(i); - this.wait(2); + this.wait(50); + } + + for(int i=256; i>=0; i--) { + lights.setBrightness(i); + this.wait(50); } - lights.colorLoop(); - this.wait(20); - lights.turnOff(); } + }