From 1674afb1d3032d9a9556b498cfb26a26be09652d Mon Sep 17 00:00:00 2001 From: abythell Date: Thu, 6 Nov 2014 16:29:02 -0800 Subject: [PATCH 1/5] bug fix comparing Integers --- src/com/angryelectron/thingspeak/Feed.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/angryelectron/thingspeak/Feed.java b/src/com/angryelectron/thingspeak/Feed.java index 448ca54..b21e079 100644 --- a/src/com/angryelectron/thingspeak/Feed.java +++ b/src/com/angryelectron/thingspeak/Feed.java @@ -202,7 +202,7 @@ public Map getEntryMap() { */ public Entry getEntry(Integer id) throws ThingSpeakException { for (Entry entry : this.feeds) { - if (entry.getEntryId() == id) { + if (entry.getEntryId().equals(id)) { return entry; } } From f76ef9ae7a90476f0c6f37885f455edc6f6be1a1 Mon Sep 17 00:00:00 2001 From: abythell Date: Thu, 6 Nov 2014 16:29:25 -0800 Subject: [PATCH 2/5] improve tests --- .../thingspeak/TestPublicChannels.java | 72 ------------------- 1 file changed, 72 deletions(-) delete mode 100644 test/com/angryelectron/thingspeak/TestPublicChannels.java diff --git a/test/com/angryelectron/thingspeak/TestPublicChannels.java b/test/com/angryelectron/thingspeak/TestPublicChannels.java deleted file mode 100644 index b86efca..0000000 --- a/test/com/angryelectron/thingspeak/TestPublicChannels.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * ThingSpeak Java Client - * Copyright 2014, Andrew Bythell - * http://angryelectron.com - * - * The ThingSpeak Java Client is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at your - * option) any later version. - * - * The ThingSpeak Java Client is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * theThingSpeak Java Client. If not, see . - */ - -package com.angryelectron.thingspeak; - -import com.angryelectron.thingspeak.pub.PublicChannelCollection; -import com.angryelectron.thingspeak.pub.PublicChannel; -import java.util.Iterator; -import static org.junit.Assert.assertNotNull; -import org.junit.Test; - -public class TestPublicChannels { - - @Test - public void testPublic_IterateAll() throws Exception { - Integer count = 0; - PublicChannelCollection pl = new PublicChannelCollection(); - Iterator publicIterator = pl.iterator(); - while (publicIterator.hasNext()) { - PublicChannel p = publicIterator.next(); - count++; - } - assert(pl.size() == count); - } - - @Test - public void testPublic_InterateWithTag() throws Exception { - Integer count = 0; - PublicChannelCollection pl = new PublicChannelCollection("temperature"); - Iterator publicIterator = pl.iterator(); - while (publicIterator.hasNext()) { - PublicChannel p = publicIterator.next(); - count++; - } - assert(pl.size() == count); - } - - @Test - public void testPublic_ChannelInfoPopulated() throws Exception { - PublicChannelCollection publicChannels = new PublicChannelCollection("cheerlights"); - for (PublicChannel channel : publicChannels) { - assertNotNull(channel.getCreatedAt()); - assertNotNull(channel.getDescription()); - assertNotNull(channel.getElevation()); - assertNotNull(channel.getId()); - assertNotNull(channel.getLastEntryId()); - assertNotNull(channel.getLatitude()); - assertNotNull(channel.getLongitude()); - assertNotNull(channel.getName()); - assertNotNull(channel.getRanking()); - assertNotNull(channel.getTags()); - assertNotNull(channel.getUsername()); - } - } - -} From 1891602ac3ad67e17e5ffacdc3371c974294cded Mon Sep 17 00:00:00 2001 From: abythell Date: Thu, 6 Nov 2014 21:05:13 -0800 Subject: [PATCH 3/5] initialize log4j --- test/com/angryelectron/thingspeak/FeedTest.java | 8 +++++++- test/com/angryelectron/thingspeak/UpdateTest.java | 12 ++++++++++++ .../thingspeak/log4j/ThingSpeakAppenderTest.java | 13 ++++++++++--- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/test/com/angryelectron/thingspeak/FeedTest.java b/test/com/angryelectron/thingspeak/FeedTest.java index 8db09db..6b42fce 100644 --- a/test/com/angryelectron/thingspeak/FeedTest.java +++ b/test/com/angryelectron/thingspeak/FeedTest.java @@ -22,6 +22,9 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; +import org.apache.log4j.BasicConfigurator; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; import org.junit.AfterClass; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -38,6 +41,9 @@ public class FeedTest { */ @BeforeClass public static void setUpClass() throws Exception { + BasicConfigurator.resetConfiguration(); + BasicConfigurator.configure(); + Logger.getLogger("org.apache.http").setLevel(Level.OFF); Entry entry = new Entry(); entry.setElevation(0.0); entry.setField(1, "nonsense-data1"); @@ -129,7 +135,7 @@ public void testGetChannelFeedWithOptions() throws Exception { FeedParameters options = new FeedParameters(); options.location(true); options.status(true); - Feed publicFeed = publicChannel.getChannelFeed(options); + Feed publicFeed = publicChannel.getChannelFeed(options); Entry entry = publicFeed.getChannelLastEntry(); assertNotNull(entry.getStatus()); assertNotNull(entry.getElevation()); diff --git a/test/com/angryelectron/thingspeak/UpdateTest.java b/test/com/angryelectron/thingspeak/UpdateTest.java index fae418c..bab3db0 100644 --- a/test/com/angryelectron/thingspeak/UpdateTest.java +++ b/test/com/angryelectron/thingspeak/UpdateTest.java @@ -19,10 +19,22 @@ package com.angryelectron.thingspeak; +import org.apache.log4j.BasicConfigurator; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; public class UpdateTest { + @BeforeClass + public static void setUpClass() throws Exception { + BasicConfigurator.resetConfiguration(); + BasicConfigurator.configure(); + Logger.getLogger("org.apache.http").setLevel(Level.OFF); + } + /** * Pause to prevent multiple update requests from exceeding the API rate * limit. Call all the end of each test to prevent subsequent tests from diff --git a/test/com/angryelectron/thingspeak/log4j/ThingSpeakAppenderTest.java b/test/com/angryelectron/thingspeak/log4j/ThingSpeakAppenderTest.java index 19ca090..280961e 100644 --- a/test/com/angryelectron/thingspeak/log4j/ThingSpeakAppenderTest.java +++ b/test/com/angryelectron/thingspeak/log4j/ThingSpeakAppenderTest.java @@ -19,6 +19,7 @@ package com.angryelectron.thingspeak.log4j; +import org.apache.log4j.BasicConfigurator; import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.junit.Test; @@ -43,18 +44,24 @@ public ThingSpeakAppenderTest() { */ @Test public void testAppend() { - System.out.println("append."); + System.out.println("append."); + BasicConfigurator.resetConfiguration(); + BasicConfigurator.configure(); + Logger.getLogger("org.apache.http").setLevel(Level.OFF); ThingSpeakAppender appender = new ThingSpeakAppender(); appender.configureChannel(channelNumber, apiWriteKey, null); appender.setThreshold(Level.INFO); - appender.activateOptions(); + appender.activateOptions(); Logger.getRootLogger().addAppender(appender); Logger.getLogger(this.getClass()).log(Level.INFO, "Test message from ThingSpeakAppender"); } @Test public void testAppendWithServer() { - System.out.println("appendWithServer."); + System.out.println("appendWithServer."); + BasicConfigurator.resetConfiguration(); + BasicConfigurator.configure(); + Logger.getLogger("org.apache.http").setLevel(Level.OFF); ThingSpeakAppender appender = new ThingSpeakAppender(); appender.configureChannel(channelNumber, apiWriteKey, "http://api.thingspeak.com"); appender.setThreshold(Level.INFO); From f7ae2c853dafa99f080a822a3a9e0384af9e2e9c Mon Sep 17 00:00:00 2001 From: abythell Date: Thu, 6 Nov 2014 21:52:02 -0800 Subject: [PATCH 4/5] improve tests, init log4j, better rate limiting --- build.xml | 4 +- .../angryelectron/thingspeak/FeedTest.java | 13 ++++ .../angryelectron/thingspeak/UpdateTest.java | 75 ++++++++++--------- .../log4j/ThingSpeakAppenderTest.java | 38 +++++----- 4 files changed, 73 insertions(+), 57 deletions(-) diff --git a/build.xml b/build.xml index cbadf11..0d2402b 100644 --- a/build.xml +++ b/build.xml @@ -7,7 +7,7 @@ - + Builds, tests, and runs the project ThingSpeak. + + diff --git a/test/com/angryelectron/thingspeak/FeedTest.java b/test/com/angryelectron/thingspeak/FeedTest.java index 6b42fce..cd805a9 100644 --- a/test/com/angryelectron/thingspeak/FeedTest.java +++ b/test/com/angryelectron/thingspeak/FeedTest.java @@ -82,6 +82,7 @@ public static void tearDownClass() throws Exception { @Test public void testGetChannelFeedPublic() throws Exception { + System.out.println("testGetChannelFeedPublic"); Channel publicChannel = new Channel(TestChannelSettings.publicChannelID, TestChannelSettings.publicChannelWriteKey); publicChannel.setUrl(TestChannelSettings.server); Feed publicFeed = publicChannel.getChannelFeed(); @@ -98,6 +99,7 @@ public void testGetChannelFeedPublic() throws Exception { @Test public void testGetChannelFeedPrivate() throws Exception { + System.out.println("testGetChannelFeedPrivate"); Channel publicChannel = new Channel(TestChannelSettings.privateChannelID, TestChannelSettings.privateChannelWriteKey, TestChannelSettings.privateChannelReadKey); publicChannel.setUrl(TestChannelSettings.server); Feed publicFeed = publicChannel.getChannelFeed(); @@ -130,6 +132,7 @@ public void testGetChannelFeedPrivate() throws Exception { @Test public void testGetChannelFeedWithOptions() throws Exception { + System.out.println("testGetChannelFeedWithOptions"); Channel publicChannel = new Channel(TestChannelSettings.publicChannelID, TestChannelSettings.publicChannelWriteKey); publicChannel.setUrl(TestChannelSettings.server); FeedParameters options = new FeedParameters(); @@ -145,6 +148,7 @@ public void testGetChannelFeedWithOptions() throws Exception { @Test public void testGetLastEntry() throws Exception { + System.out.println("testGetLastEntry"); Channel publicChannel = new Channel(TestChannelSettings.publicChannelID, TestChannelSettings.publicChannelWriteKey); publicChannel.setUrl(TestChannelSettings.server); Entry entry = publicChannel.getLastChannelEntry(); @@ -165,6 +169,7 @@ public void testGetLastEntry() throws Exception { @Test public void testGetLastEntryWithOptions() throws Exception { + System.out.println("testGetLastEntryWithOptions"); Channel publicChannel = new Channel(TestChannelSettings.publicChannelID, TestChannelSettings.publicChannelWriteKey); publicChannel.setUrl(TestChannelSettings.server); FeedParameters options = new FeedParameters(); @@ -179,6 +184,7 @@ public void testGetLastEntryWithOptions() throws Exception { @Test public void testGetLastEntryWithTimezoneOffset() throws Exception { + System.out.println("testGetLastEntryWithTimezoneOffset"); Channel channel = new Channel(TestChannelSettings.publicChannelID); channel.setUrl(TestChannelSettings.server); FeedParameters options = new FeedParameters(); @@ -190,6 +196,7 @@ public void testGetLastEntryWithTimezoneOffset() throws Exception { @Test public void testGetFieldFeed() throws Exception { + System.out.println("testGetFieldFeed"); Channel publicChannel = new Channel(TestChannelSettings.publicChannelID); publicChannel.setUrl(TestChannelSettings.server); Feed feed = publicChannel.getFieldFeed(1); @@ -212,6 +219,7 @@ public void testGetFieldFeed() throws Exception { @Test public void testGetFieldFeedWithOptions() throws Exception { + System.out.println("testGetFieldFeedWithOptions"); Channel publicChannel = new Channel(TestChannelSettings.publicChannelID); publicChannel.setUrl(TestChannelSettings.server); FeedParameters options = new FeedParameters(); @@ -230,6 +238,7 @@ public void testGetFieldFeedWithOptions() throws Exception { @Test public void testGetFieldFeedLastEntry() throws Exception { + System.out.println("testGetFieldFeedLastEntry"); Channel publicChannel = new Channel(TestChannelSettings.publicChannelID); publicChannel.setUrl(TestChannelSettings.server); Entry entry = publicChannel.getLastFieldEntry(1); @@ -239,6 +248,7 @@ public void testGetFieldFeedLastEntry() throws Exception { @Test public void testGetFieldFeedLastEntryWithOptions() throws Exception { + System.out.println("testGetFieldFeedLastEntryWithOptions"); Channel publicChannel = new Channel(TestChannelSettings.publicChannelID); publicChannel.setUrl(TestChannelSettings.server); FeedParameters options = new FeedParameters(); @@ -255,6 +265,7 @@ public void testGetFieldFeedLastEntryWithOptions() throws Exception { @Test public void testGetStatus() throws Exception { + System.out.println("testGetStatus"); Channel channel = new Channel(TestChannelSettings.publicChannelID); channel.setUrl(TestChannelSettings.server); Feed feed = channel.getStatusFeed(); @@ -265,6 +276,7 @@ public void testGetStatus() throws Exception { @Test public void testGetStatusWithOptions() throws Exception { + System.out.println("testGetStatusWithOptions"); Channel channel = new Channel(TestChannelSettings.publicChannelID); channel.setUrl(TestChannelSettings.server); FeedParameters options = new FeedParameters(); @@ -279,6 +291,7 @@ public void testGetStatusWithOptions() throws Exception { @Test public void testGetStatus_emptyFields() throws Exception { + System.out.println("testGetStatusEmptyFields"); Channel channel = new Channel(TestChannelSettings.publicChannelID); channel.setUrl(TestChannelSettings.server); Feed statusFeed = channel.getStatusFeed(); diff --git a/test/com/angryelectron/thingspeak/UpdateTest.java b/test/com/angryelectron/thingspeak/UpdateTest.java index bab3db0..38d5a78 100644 --- a/test/com/angryelectron/thingspeak/UpdateTest.java +++ b/test/com/angryelectron/thingspeak/UpdateTest.java @@ -1,6 +1,5 @@ /** - * ThingSpeak Java Client - * Copyright 2014, Andrew Bythell + * ThingSpeak Java Client Copyright 2014, Andrew Bythell * http://angryelectron.com * * The ThingSpeak Java Client is free software: you can redistribute it and/or @@ -16,41 +15,41 @@ * You should have received a copy of the GNU General Public License along with * theThingSpeak Java Client. If not, see . */ - package com.angryelectron.thingspeak; import org.apache.log4j.BasicConfigurator; import org.apache.log4j.Level; import org.apache.log4j.Logger; -import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; -public class UpdateTest { - +public class UpdateTest { + @BeforeClass public static void setUpClass() throws Exception { BasicConfigurator.resetConfiguration(); BasicConfigurator.configure(); Logger.getLogger("org.apache.http").setLevel(Level.OFF); + pauseForAPIRateLimit(); } - + /** * Pause to prevent multiple update requests from exceeding the API rate - * limit. Call all the end of each test to prevent subsequent tests from - * failing. By appending to the end of each test instead of calling it using - * \@After, time can be saved when running tests that throw exceptions and don't - * actually do a successful update. - * @throws InterruptedException + * limit. Call all the end of each test to prevent subsequent tests from + * failing. By appending to the end of each test instead of calling it using + * \@After, time can be saved when running tests that throw exceptions and + * don't actually do a successful update. + * + * @throws InterruptedException */ - private void pauseForAPIRateLimit() throws InterruptedException { + private static void pauseForAPIRateLimit() throws InterruptedException { System.out.println("Waiting for rate limit to expire."); Thread.sleep(TestChannelSettings.rateLimit); } - + @Test - public void testUpdateChannel() throws Exception{ - System.out.println("testUpdatePublicChannel"); + public void testUpdateChannel() throws Exception { + System.out.println("testUpdateChannel"); Channel channel = new Channel(TestChannelSettings.publicChannelID, TestChannelSettings.publicChannelWriteKey); channel.setUrl(TestChannelSettings.server); Integer result = channel.update(new Entry()); @@ -58,16 +57,18 @@ public void testUpdateChannel() throws Exception{ pauseForAPIRateLimit(); } - @Test(expected = ThingSpeakException.class) public void testUpdateChannelWithInvalidAPIKey() throws Exception { System.out.println("testUpdatePublicChannelWithInvalidAPIKey"); - Channel channel = new Channel(TestChannelSettings.publicChannelID, "invalidChannelKey"); + Channel channel = new Channel(TestChannelSettings.publicChannelID, "invalidChannelKey"); channel.setUrl(TestChannelSettings.server); - channel.update(new Entry()); - pauseForAPIRateLimit(); + try { + channel.update(new Entry()); + } finally { + pauseForAPIRateLimit(); + } } - + @Test public void testUpdateSlowerThanAPIRateLimit() throws Exception { System.out.println("testUpdateSlowerThanAPIRateLimit"); @@ -77,22 +78,22 @@ public void testUpdateSlowerThanAPIRateLimit() throws Exception { Channel channel = new Channel(TestChannelSettings.publicChannelID, TestChannelSettings.publicChannelWriteKey); channel.setUrl(TestChannelSettings.server); Integer result0 = channel.update(new Entry()); - assert(result0 != 0); - + assert (result0 != 0); + /** * Pause until the rate limit has passed. */ Thread.sleep(TestChannelSettings.rateLimit); - + /** * Do another update and make sure it succeeds. */ Integer result1 = channel.update(new Entry()); - assert(result1 != 0); - + assert (result1 != 0); + pauseForAPIRateLimit(); } - + @Test(expected = ThingSpeakException.class) public void testUpdateFasterThanAPIRateLimit() throws Exception { System.out.println("testUpdateFasterThanAPIRateLimit"); @@ -102,22 +103,24 @@ public void testUpdateFasterThanAPIRateLimit() throws Exception { if (TestChannelSettings.rateLimit == 0) { throw new ThingSpeakException("Rate limiting not supported"); } - + /** * Do an update and make sure it succeeds. */ Channel channel = new Channel(TestChannelSettings.publicChannelID, TestChannelSettings.publicChannelWriteKey); channel.setUrl(TestChannelSettings.server); Integer result = channel.update(new Entry()); - assert(result != 0); - + assert (result != 0); + /** - * Don't wait for the rate limit to pass - send another update - * right away. This should cause a ThingSpeakException. + * Don't wait for the rate limit to pass - send another update right + * away. This should cause a ThingSpeakException. */ - channel.update(new Entry()); - - pauseForAPIRateLimit(); + try { + channel.update(new Entry()); + } finally { + pauseForAPIRateLimit(); + } } - + } diff --git a/test/com/angryelectron/thingspeak/log4j/ThingSpeakAppenderTest.java b/test/com/angryelectron/thingspeak/log4j/ThingSpeakAppenderTest.java index 280961e..bf6ef27 100644 --- a/test/com/angryelectron/thingspeak/log4j/ThingSpeakAppenderTest.java +++ b/test/com/angryelectron/thingspeak/log4j/ThingSpeakAppenderTest.java @@ -19,9 +19,11 @@ package com.angryelectron.thingspeak.log4j; +import com.angryelectron.thingspeak.TestChannelSettings; import org.apache.log4j.BasicConfigurator; import org.apache.log4j.Level; import org.apache.log4j.Logger; +import org.junit.BeforeClass; import org.junit.Test; /** @@ -37,17 +39,28 @@ public class ThingSpeakAppenderTest { public ThingSpeakAppenderTest() { } + + @BeforeClass + public static void setUpClass() throws Exception { + BasicConfigurator.resetConfiguration(); + BasicConfigurator.configure(); + Logger.getLogger("org.apache.http").setLevel(Level.OFF); + pauseForAPIRateLimit(); + } + + private static void pauseForAPIRateLimit() throws InterruptedException { + System.out.println("Waiting for rate limit to expire."); + Thread.sleep(TestChannelSettings.rateLimit); + } /** * Test of configureChannel method, of class ThingSpeakAppender. To view the * logged data on ThingSpeak, visit https://thingspeak.com/channels/15662/feeds. + * @throws java.lang.InterruptedException */ @Test - public void testAppend() { - System.out.println("append."); - BasicConfigurator.resetConfiguration(); - BasicConfigurator.configure(); - Logger.getLogger("org.apache.http").setLevel(Level.OFF); + public void testAppend() throws InterruptedException { + System.out.println("testAppend"); ThingSpeakAppender appender = new ThingSpeakAppender(); appender.configureChannel(channelNumber, apiWriteKey, null); appender.setThreshold(Level.INFO); @@ -55,19 +68,4 @@ public void testAppend() { Logger.getRootLogger().addAppender(appender); Logger.getLogger(this.getClass()).log(Level.INFO, "Test message from ThingSpeakAppender"); } - - @Test - public void testAppendWithServer() { - System.out.println("appendWithServer."); - BasicConfigurator.resetConfiguration(); - BasicConfigurator.configure(); - Logger.getLogger("org.apache.http").setLevel(Level.OFF); - ThingSpeakAppender appender = new ThingSpeakAppender(); - appender.configureChannel(channelNumber, apiWriteKey, "http://api.thingspeak.com"); - appender.setThreshold(Level.INFO); - appender.activateOptions(); - Logger.getRootLogger().addAppender(appender); - Logger.getLogger(this.getClass()).log(Level.INFO, "Test message from ThingSpeakAppender"); - } - } From a5c80f42da65043452dcc1248a80f3ea2cdf50c5 Mon Sep 17 00:00:00 2001 From: abythell Date: Thu, 6 Nov 2014 21:55:33 -0800 Subject: [PATCH 5/5] update test instructions --- README.md | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 29465a1..f538ad4 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,25 @@ ThingSpeak Java Client === -A Java client for the [ThingSpeak](http://thingspeak.com) Internet of -Things. Implements all aspects of the ThingSpeak API and can be used to -update channel data, retrieve and examine feeds, and query public channels. -It supports the hosted ThingSpeak server at api.thingspeak.com as well -as self-hosted open-source servers ([GitHub Source](https://github.com/iobridge/thingspeak)). +A Java client for the [ThingSpeak](http://thingspeak.com) Internet of Things. +Implements all aspects of the ThingSpeak API and can be used to update channel +data, retrieve and examine feeds, and query public channels. It supports the +hosted ThingSpeak server at api.thingspeak.com as well as self-hosted +open-source servers ([GitHub Source](https://github.com/iobridge/thingspeak)). -Also included: An appender for log4j - post data to ThingSpeak channels using Logger -framework. +Also included: An appender for log4j - post data to ThingSpeak channels using +Logger framework. How To Install --- -Get the source by [downloading a zip file](https://github.com/angryelectron/thingspeak-java/archive/master.zip) -or by cloning the git repository https://github.com/angryelectron/thingspeak-java.git . -Building the source requires the Java 7 SDK and Apache Ant, or use the [Netbeans IDE](http://netbeans.org). +Get the source by [downloading a zip +file](https://github.com/angryelectron/thingspeak-java/archive/master.zip) or +by cloning the git repository +https://github.com/angryelectron/thingspeak-java.git . Building the source +requires the Java 7 SDK and Apache Ant, or use the [Netbeans +IDE](http://netbeans.org). -Here is an example of how to install the client from the command line in Ubuntu/Debian/Raspbian with a minimal build environment: +Here is an example of how to install the client from the command line in +Ubuntu/Debian/Raspbian with a minimal build environment: ``` sudo apt-get update @@ -25,7 +29,9 @@ cd thingspeak-java ant ``` -After building, the jars, docs, and dependencies can be found in thingspeak/dist. +To run optional tests, run 'ant test'. Due to the rate limit of the public +Thingspeak server (15sec), tests can take a long time to run. After building, +the jars, docs, and dependencies can be found in thingspeak/dist. How To Use --- @@ -34,10 +40,14 @@ Add thingspeak-x.y.jar to your project and the following dependencies: * [Unirest](http://unirest.io) * [GSON](http://code.google.com/p/google-gson/) -Dependencies can be found in thingspeak/dist/lib after building the source. Refer to the included javadocs for more details. The [ThingSpeak API Documentation](http://community.thingspeak.com/documentation/api/#thingspeak_api) +Dependencies can be found in thingspeak/dist/lib after building the source. +Refer to the included javadocs for more details. The [ThingSpeak API +Documentation](http://community.thingspeak.com/documentation/api/#thingspeak_api) is also a good source of additional information about using the API. -If you encounter any issues with the ThingSpeak Java Client, please use the [GitHub issue tracker](https://github.com/angryelectron/thingspeak-java/issues). +If you encounter any issues with the ThingSpeak Java Client, please use the +[GitHub issue +tracker](https://github.com/angryelectron/thingspeak-java/issues). Examples --- @@ -60,13 +70,15 @@ Entry entry = channel.getLastChannelEntry(); System.out.println(entry.getField(1); ``` -Please refer to thingspeak/dist/javadoc for more information about customzing channel feeds, searching public channels, using open-source servers, and all the other operations supported by the ThingSpeak API. +Please refer to thingspeak/dist/javadoc for more information about customzing +channel feeds, searching public channels, using open-source servers, and all +the other operations supported by the ThingSpeak API. log4j Appender --- -Use log4j to update ThingSpeak channels. Date, Level, and Message are 'fields', -written as an 'entry'. Setup a new ThingSpeak channel with these three fields, then -pass the channel number and API write-key to the appender. +Use log4j to update ThingSpeak channels. Date, Level, and Message are +'fields', written as an 'entry'. Setup a new ThingSpeak channel with these +three fields, then pass the channel number and API write-key to the appender. Here's how to configure the appender and send a test message (just add your own channelNumber and apiWriteKey):