Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2.2.1 (2018-08-06)
- Remove Guava dependency
- Replace use of internal Sun API class

2.2.0 (2018-07-05)
=================

Expand Down
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apply plugin: 'signing'
apply plugin: 'java-library-distribution'

group = 'com.siftscience'
version = '2.1.0'
version = '2.1.1'
sourceCompatibility = 1.7
targetCompatibility = 1.7

Expand All @@ -17,7 +17,6 @@ dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
testCompile group: 'org.skyscreamer', name: 'jsonassert', version: '1.3.0'
testCompile group: 'com.squareup.okhttp3', name: 'mockwebserver', version: '3.4.1'
compile group: 'com.google.guava', name: 'guava', version:'13.0.1'
compile 'com.google.code.gson:gson:2.7'
compile 'com.squareup.okhttp3:okhttp:3.4.1'
compile 'com.squareup.okio:okio:1.9.0'
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/siftscience/GetDecisionsRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.siftscience.model.GetDecisionFieldSet;

import java.io.IOException;
import com.google.common.base.Joiner;
import okhttp3.Credentials;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
Expand All @@ -12,7 +11,6 @@


public class GetDecisionsRequest extends SiftRequest<GetDecisionsResponse> {
private final Joiner joiner = Joiner.on(",");

GetDecisionsRequest(HttpUrl baseUrl, OkHttpClient okClient, FieldSet fields) {
super(baseUrl, okClient, fields);
Expand Down Expand Up @@ -53,7 +51,7 @@ protected HttpUrl path(HttpUrl baseUrl) {
path.addQueryParameter(Query.FROM.toString(), String.valueOf(fieldSet.getFrom()));
}
if (fieldSet.getAbuseTypes() != null && !fieldSet.getAbuseTypes().isEmpty()) {
path.addQueryParameter(Query.ABUSE_TYPES.toString(), joiner.join(fieldSet.getAbuseTypes()));
path.addQueryParameter(Query.ABUSE_TYPES.toString(), StringUtils.joinWithComma(fieldSet.getAbuseTypes()));
}

return path.build();
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/siftscience/StringUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.siftscience;

import java.util.Collection;

final class StringUtils {

private StringUtils() {

}

static String joinWithComma(Collection<?> elements) {
if (elements == null || elements.isEmpty()) {
return "";
}
StringBuilder sb = new StringBuilder();
for (Object o: elements) {
sb.append(',');
sb.append(o.toString());
}
return sb.substring(1, sb.length());
}
}
3 changes: 1 addition & 2 deletions src/main/java/com/siftscience/UnlabelResponse.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.siftscience;

import okhttp3.Response;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;

import java.io.IOException;

Expand All @@ -17,6 +16,6 @@ public class UnlabelResponse extends SiftResponse {
*/
@Override
void populateBodyFromJson(String jsonBody) {
throw new NotImplementedException();
throw new UnsupportedOperationException();
}
}
11 changes: 6 additions & 5 deletions src/main/java/com/siftscience/model/GetDecisionFieldSet.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.siftscience.model;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.siftscience.FieldSet;
import com.siftscience.GetDecisionsRequest;
import com.siftscience.exception.InvalidFieldException;
import com.siftscience.exception.InvalidRequestException;

import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -28,7 +29,7 @@ public static GetDecisionFieldSet fromJson(String json) {
}

public static GetDecisionFieldSet fromNextRef(String nextRef) {
Preconditions.checkNotNull(nextRef,"Must provide valid nextRef");
Objects.requireNonNull(nextRef,"Must provide valid nextRef");
URI uri = URI.create(nextRef);
String queries = uri.getQuery();
if ( queries == null || queries.isEmpty()) {
Expand Down Expand Up @@ -70,11 +71,11 @@ public static GetDecisionFieldSet fromNextRef(String nextRef) {
}

private void setAbuseTypes(String abuseTypeCsv) {
ImmutableList.Builder<AbuseType> abuseTypes = ImmutableList.builder();
List<AbuseType> abuseTypes = new ArrayList<>();
for (String abuseType : abuseTypeCsv.split(",")) {
abuseTypes.add(AbuseType.valueOf(abuseType.toUpperCase()));
}
this.abuseTypes = abuseTypes.build();
this.abuseTypes = Collections.unmodifiableList(abuseTypes);
}

public enum AbuseType {
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/com/siftscience/ContentEventTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static java.net.HttpURLConnection.HTTP_OK;

import com.google.common.collect.Lists;
import com.siftscience.model.Address;
import com.siftscience.model.Comment;
import com.siftscience.model.CreateCommentFieldSet;
Expand Down Expand Up @@ -33,6 +32,7 @@
import org.skyscreamer.jsonassert.JSONAssert;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -210,7 +210,7 @@ public void testCreateListing() throws Exception {
Item item = new Item()
.setCurrencyCode("USD")
.setPrice(2950000000L)
.setTags(Lists.newArrayList("heat", "washer/dryer"));
.setTags(Arrays.asList("heat", "washer/dryer"));

Listing l = new Listing()
.setBody("Capitol Hill Seattle brand new condo. 2 bedrooms and 1 full bath.")
Expand Down Expand Up @@ -398,7 +398,7 @@ public void testCreateProfile() throws Exception {

Profile p = new Profile()
.setBody("Hi! My name is Alex and I just moved to New London!")
.setCategories(Lists.newArrayList("Friends", "Long-term dating"))
.setCategories(Arrays.asList("Friends", "Long-term dating"))
.setContactAddress(contactAddress)
.setContactEmail("alex_301@domain.com")
.setImages(images);
Expand Down Expand Up @@ -819,7 +819,7 @@ public void testUpdateListing() throws Exception {
Item item = new Item()
.setCurrencyCode("USD")
.setPrice(2950000000L)
.setTags(Lists.newArrayList("heat", "washer/dryer"));
.setTags(Arrays.asList("heat", "washer/dryer"));

Listing l = new Listing()
.setBody("Capitol Hill Seattle brand new condo. 2 bedrooms and 1 full bath.")
Expand Down Expand Up @@ -1011,7 +1011,7 @@ public void testUpdateProfile() throws Exception {

Profile p = new Profile()
.setBody("Hi! My name is Alex and I just moved to New London!")
.setCategories(Lists.newArrayList("Friends", "Long-term dating"))
.setCategories(Arrays.asList("Friends", "Long-term dating"))
.setContactAddress(contactAddress)
.setContactEmail("alex_301@domain.com")
.setImages(images);
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/siftscience/GetDecisionsTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.siftscience;

import com.google.common.collect.Lists;
import com.siftscience.model.GetDecisionFieldSet;
import okhttp3.HttpUrl;
import okhttp3.mockwebserver.MockResponse;
Expand All @@ -15,6 +14,7 @@
import static com.siftscience.model.GetDecisionFieldSet.EntityType.ORDER;
import static com.siftscience.model.GetDecisionFieldSet.EntityType.SESSION;
import static java.net.HttpURLConnection.HTTP_OK;
import java.util.Arrays;

public class GetDecisionsTest {

Expand Down Expand Up @@ -65,7 +65,7 @@ public void testDecisionStatus() throws Exception {
GetDecisionsRequest getDecisionsRequest = client.buildRequest(new GetDecisionFieldSet()
.setAccountId(accountId)
.setLimit(11)
.setAbuseTypes(Lists.newArrayList(ACCOUNT_ABUSE, ACCOUNT_TAKEOVER))
.setAbuseTypes(Arrays.asList(ACCOUNT_ABUSE, ACCOUNT_TAKEOVER))
.setFrom(1)
.setEntityType(ORDER)

Expand Down Expand Up @@ -137,7 +137,7 @@ public void testDecisionStatusWithEntityTypeSession() throws Exception {
GetDecisionsRequest getDecisionsRequest = client.buildRequest(new GetDecisionFieldSet()
.setAccountId(accountId)
.setLimit(11)
.setAbuseTypes(Lists.newArrayList(ACCOUNT_ABUSE, ACCOUNT_TAKEOVER))
.setAbuseTypes(Arrays.asList(ACCOUNT_ABUSE, ACCOUNT_TAKEOVER))
.setFrom(1)
.setEntityType(SESSION)

Expand Down
23 changes: 23 additions & 0 deletions src/test/java/com/siftscience/StringUtilsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.siftscience;

import java.util.Arrays;
import java.util.Collections;

import static org.junit.Assert.assertEquals;
import org.junit.Test;

public class StringUtilsTest {

@Test
public void testJoinWithCommaEmpty() {
assertEquals("", StringUtils.joinWithComma(null));
assertEquals("", StringUtils.joinWithComma(Collections.emptyList()));
}

@Test
public void testJoinWithComma() {
assertEquals("foo", StringUtils.joinWithComma(Collections.singleton("foo")));
assertEquals("foo,bar", StringUtils.joinWithComma(Arrays.asList("foo", "bar")));
assertEquals("1,2", StringUtils.joinWithComma(Arrays.asList(1, 2)));
}
}