diff --git a/src/main/lombok/com/restfb/types/whatsapp/WABAConversationAnalytics.java b/src/main/lombok/com/restfb/types/whatsapp/WABAConversationAnalytics.java new file mode 100644 index 000000000..73a84ab74 --- /dev/null +++ b/src/main/lombok/com/restfb/types/whatsapp/WABAConversationAnalytics.java @@ -0,0 +1,190 @@ +/* + * Copyright (c) 2010-2022 Mark Allen, Norbert Bartels. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.restfb.types.whatsapp; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import com.restfb.Facebook; + +import lombok.Getter; +import lombok.Setter; + +/** + * Represents the WhatsApp + * Business Account Conversation Analytics type + */ +public class WABAConversationAnalytics { + + @Facebook("conversation_directions") + private List conversationDirections; + + @Facebook("conversation_types") + private List conversationTypes; + + @Facebook("country_codes") + private List countryCodes; + + @Facebook + private List dimensions; + + @Getter + @Setter + @Facebook + private Integer end; + + @Getter + @Setter + @Facebook + private WABAGranularity granularity; + + @Facebook("metric_types") + private List metricTypes; + + @Facebook("phone_numbers") + private List phoneNumbers; + + @Getter + @Setter + @Facebook + private Integer start; + + + public List getMetricTypes() { + return Collections.unmodifiableList(getMetricTypesList()); + } + + public boolean addMetricType(WABAMetricType metricType) { + return getMetricTypesList().add(metricType); + } + + public boolean removeMetricType(WABAMetricType metricType) { + return getMetricTypesList().remove(metricType); + } + + private List getMetricTypesList() { + if (metricTypes == null) { + metricTypes = new ArrayList<>(); + } + return metricTypes; + } + + public List getConversationTypes() { + return Collections.unmodifiableList(getConversationTypesList()); + } + + public boolean addConversationType(WABAConversationType conversationType) { + return getConversationTypesList().add(conversationType); + } + + public boolean removeConversationType(WABAConversationType conversationType) { + return getConversationTypesList().remove(conversationType); + } + + private List getConversationTypesList() { + if (conversationTypes == null) { + conversationTypes = new ArrayList<>(); + } + return conversationTypes; + } + + public List getConversationDirections() { + return Collections.unmodifiableList(getConversationDirectionsList()); + } + + public boolean addConversationDirection(WABAConversationDirection conversationDirection) { + return getConversationDirectionsList().add(conversationDirection); + } + + public boolean removeConversationDirection(WABAConversationDirection conversationDirection) { + return getConversationDirectionsList().remove(conversationDirection); + } + + private List getConversationDirectionsList() { + if (conversationDirections == null) { + conversationDirections = new ArrayList<>(); + } + return conversationDirections; + } + + public List getDimensions() { + return Collections.unmodifiableList(getDimensionsList()); + } + + public boolean addDimension(WABADimension dimension) { + return getDimensionsList().add(dimension); + } + + public boolean removeDimension(WABADimension dimension) { + return getDimensionsList().remove(dimension); + } + + private List getDimensionsList() { + if (dimensions == null) { + dimensions = new ArrayList<>(); + } + return dimensions; + } + + public List getPhoneNumbers() { + return Collections.unmodifiableList(getPhoneNumbersList()); + } + + public boolean addPhoneNumber(String phoneNumber) { + return getPhoneNumbersList().add(phoneNumber); + } + + public boolean removePhoneNumber(String phoneNumber) { + return getPhoneNumbersList().remove(phoneNumber); + } + + private List getPhoneNumbersList() { + if (phoneNumbers == null) { + phoneNumbers = new ArrayList<>(); + } + return phoneNumbers; + } + + /** + * List of ISO 3166 country codes (e.g. US, IN) + */ + public List getCountryCodes() { + return Collections.unmodifiableList(getCountryCodesList()); + } + + public boolean addCountryCode(String countryCode) { + return getCountryCodesList().add(countryCode); + } + + public boolean removeCountryCode(String countryCode) { + return getCountryCodesList().remove(countryCode); + } + + private List getCountryCodesList() { + if (countryCodes == null) { + countryCodes = new ArrayList<>(); + } + return countryCodes; + } +} diff --git a/src/main/lombok/com/restfb/types/whatsapp/WABAConversationDirection.java b/src/main/lombok/com/restfb/types/whatsapp/WABAConversationDirection.java new file mode 100644 index 000000000..0269fc271 --- /dev/null +++ b/src/main/lombok/com/restfb/types/whatsapp/WABAConversationDirection.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2010-2022 Mark Allen, Norbert Bartels. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.restfb.types.whatsapp; + +public enum WABAConversationDirection { + UNKNOWN, BUSINESS_INITIATED, USER_INITIATED +} diff --git a/src/main/lombok/com/restfb/types/whatsapp/WABAConversationType.java b/src/main/lombok/com/restfb/types/whatsapp/WABAConversationType.java new file mode 100644 index 000000000..9b075f9a5 --- /dev/null +++ b/src/main/lombok/com/restfb/types/whatsapp/WABAConversationType.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2010-2022 Mark Allen, Norbert Bartels. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.restfb.types.whatsapp; + +public enum WABAConversationType { + UNKNOWN, REGULAR, FREE_ENTRY_POINT, FREE_TIER +} diff --git a/src/main/lombok/com/restfb/types/whatsapp/WABADimension.java b/src/main/lombok/com/restfb/types/whatsapp/WABADimension.java new file mode 100644 index 000000000..6cdeba5bd --- /dev/null +++ b/src/main/lombok/com/restfb/types/whatsapp/WABADimension.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2010-2022 Mark Allen, Norbert Bartels. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.restfb.types.whatsapp; + +public enum WABADimension { + UNKNOWN, PHONE, COUNTRY, CONVERSATION_TYPE, CONVERSATION_DIRECTION +} diff --git a/src/main/lombok/com/restfb/types/whatsapp/WABAGranularity.java b/src/main/lombok/com/restfb/types/whatsapp/WABAGranularity.java new file mode 100644 index 000000000..490839986 --- /dev/null +++ b/src/main/lombok/com/restfb/types/whatsapp/WABAGranularity.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2010-2022 Mark Allen, Norbert Bartels. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.restfb.types.whatsapp; + +public enum WABAGranularity { + HALF_HOUR, DAILY, MONTHLY +} diff --git a/src/main/lombok/com/restfb/types/whatsapp/WABAMetricType.java b/src/main/lombok/com/restfb/types/whatsapp/WABAMetricType.java new file mode 100644 index 000000000..aeda4c25c --- /dev/null +++ b/src/main/lombok/com/restfb/types/whatsapp/WABAMetricType.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2010-2022 Mark Allen, Norbert Bartels. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.restfb.types.whatsapp; + +public enum WABAMetricType { + UNKNOWN, CONVERSATION, COST +} diff --git a/src/test/java/com/restfb/types/whatsapp/WABAConversationAnalyticsTest.java b/src/test/java/com/restfb/types/whatsapp/WABAConversationAnalyticsTest.java new file mode 100644 index 000000000..1fa79733c --- /dev/null +++ b/src/test/java/com/restfb/types/whatsapp/WABAConversationAnalyticsTest.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2010-2022 Mark Allen, Norbert Bartels. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.restfb.types.whatsapp; + +import static com.restfb.testutils.AssertJson.assertEquals; + +import org.junit.jupiter.api.Test; + +import com.restfb.AbstractJsonMapperTests; + +class WABAConversationAnalyticsTest extends AbstractJsonMapperTests { + + @Test + void simpleTest() { + WABAConversationAnalytics conversationAnalytics = new WABAConversationAnalytics(); + assertEquals("{}", createJsonMapper().toJson(conversationAnalytics, true)); + } + + @Test + void withConversionDirection() { + WABAConversationAnalytics conversationAnalytics = new WABAConversationAnalytics(); + conversationAnalytics.addConversationDirection(WABAConversationDirection.USER_INITIATED); + assertEquals("{\"conversation_directions\":[\"USER_INITIATED\"]}", + createJsonMapper().toJson(conversationAnalytics, true)); + } + + @Test + void withConversionTypes() { + WABAConversationAnalytics conversationAnalytics = new WABAConversationAnalytics(); + conversationAnalytics.addConversationType(WABAConversationType.FREE_TIER); + assertEquals("{\"conversation_types\":[\"FREE_TIER\"]}", createJsonMapper().toJson(conversationAnalytics, true)); + } + + @Test + void withCountryCode() { + WABAConversationAnalytics conversationAnalytics = new WABAConversationAnalytics(); + conversationAnalytics.addCountryCode("de"); + assertEquals("{\"country_codes\":[\"de\"]}", createJsonMapper().toJson(conversationAnalytics, true)); + } + + @Test + void withDimensions() { + WABAConversationAnalytics conversationAnalytics = new WABAConversationAnalytics(); + conversationAnalytics.addDimension(WABADimension.COUNTRY); + assertEquals("{\"dimensions\":[\"COUNTRY\"]}", createJsonMapper().toJson(conversationAnalytics, true)); + } + + @Test + void withMetricTypes() { + WABAConversationAnalytics conversationAnalytics = new WABAConversationAnalytics(); + conversationAnalytics.addMetricType(WABAMetricType.CONVERSATION); + assertEquals("{\"metric_types\":[\"CONVERSATION\"]}", createJsonMapper().toJson(conversationAnalytics, true)); + } + + @Test + void full() { + WABAConversationAnalytics conversationAnalytics = new WABAConversationAnalytics(); + conversationAnalytics.addMetricType(WABAMetricType.CONVERSATION); + conversationAnalytics.addConversationDirection(WABAConversationDirection.BUSINESS_INITIATED); + conversationAnalytics.addConversationType(WABAConversationType.REGULAR); + conversationAnalytics.addDimension(WABADimension.COUNTRY); + conversationAnalytics.addCountryCode("de"); + conversationAnalytics.addCountryCode("en"); + conversationAnalytics.addPhoneNumber("12345"); + conversationAnalytics.setGranularity(WABAGranularity.DAILY); + String expectedObj = "{\"conversation_directions\":[\"BUSINESS_INITIATED\"]," // + + "\"conversation_types\":[\"REGULAR\"]," // + + "\"country_codes\":[\"de\",\"en\"]," // + + "\"dimensions\":[\"COUNTRY\"]," // + + "\"granularity\":\"DAILY\"," // + + "\"metric_types\":[\"CONVERSATION\"]," // + + "\"phone_numbers\":[\"12345\"]}"; + assertEquals(expectedObj, createJsonMapper().toJson(conversationAnalytics, true)); + } + +}