diff --git a/tracker/src/main/java/org/matomo/sdk/dispatcher/PacketFactory.java b/tracker/src/main/java/org/matomo/sdk/dispatcher/PacketFactory.java index bdc671bd..6666aebf 100644 --- a/tracker/src/main/java/org/matomo/sdk/dispatcher/PacketFactory.java +++ b/tracker/src/main/java/org/matomo/sdk/dispatcher/PacketFactory.java @@ -7,10 +7,10 @@ package org.matomo.sdk.dispatcher; -import androidx.annotation.NonNull; +import android.text.TextUtils; + import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; -import android.text.TextUtils; import org.json.JSONArray; import org.json.JSONException; @@ -37,19 +37,11 @@ public PacketFactory(final String apiUrl) { public List buildPackets(final List events) { if (events.isEmpty()) return Collections.emptyList(); - if (events.size() == 1) { - Packet p = buildPacketForGet(events.get(0)); - if (p == null) return Collections.emptyList(); - else return Collections.singletonList(p); - } - int packets = (int) Math.ceil(events.size() * 1.0 / PAGE_SIZE); List freshPackets = new ArrayList<>(packets); for (int i = 0; i < events.size(); i += PAGE_SIZE) { List batch = events.subList(i, Math.min(i + PAGE_SIZE, events.size())); - final Packet packet; - if (batch.size() == 1) packet = buildPacketForGet(batch.get(0)); - else packet = buildPacketForPost(batch); + final Packet packet = buildPacketForPost(batch); if (packet != null) freshPackets.add(packet); } return freshPackets; @@ -74,12 +66,4 @@ private Packet buildPacketForPost(List events) { } return null; } - - // "http://domain.com/matomo.php?idsite=1&url=http://a.org&action_name=Test bulk log Pageview&rec=1" - @Nullable - private Packet buildPacketForGet(@NonNull Event event) { - if (event.getEncodedQuery().isEmpty()) return null; - return new Packet(mApiUrl + event); - } - } diff --git a/tracker/src/test/java/org/matomo/sdk/dispatcher/PacketFactoryTest.java b/tracker/src/test/java/org/matomo/sdk/dispatcher/PacketFactoryTest.java index cb4e8042..21feaa36 100644 --- a/tracker/src/test/java/org/matomo/sdk/dispatcher/PacketFactoryTest.java +++ b/tracker/src/test/java/org/matomo/sdk/dispatcher/PacketFactoryTest.java @@ -37,20 +37,6 @@ public void testPOST_data() throws Exception { assertEquals("berries", packets.get(0).getPostData().getJSONArray("requests").get(1)); } - @Test - public void testGET_apiUrl() { - String url = "http://example.com/"; - PacketFactory factory = new PacketFactory(url); - List packets = factory.buildPackets(Collections.singletonList(new Event("strawberries"))); - assertTrue(packets.get(0).getTargetURL().startsWith(url)); - } - - @Test - public void testGET_badUrl() { - PacketFactory factory = new PacketFactory("http://example.com/"); - assertTrue(factory.buildPackets(Collections.singletonList(new Event(""))).isEmpty()); - } - @Test public void testEmptyEvents() { PacketFactory factory = new PacketFactory("http://example.com/"); @@ -71,8 +57,7 @@ public void testPacking_rest() { Packet second = packets.get(1); assertEquals(1, second.getEventCount()); - assertNull(second.getPostData()); - assertTrue(second.getTargetURL().endsWith("?eve" + events.size())); + assertNotNull(second.getPostData()); } @Test