Sift Science Java library

Java library which help integrate your Java application to Sift Science quicker and easier.

License

License

Categories

Categories

Java Languages
GroupId

GroupId

com.github.mcac0006
ArtifactId

ArtifactId

sift-java
Last Version

Last Version

0.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

Sift Science Java library
Java library which help integrate your Java application to Sift Science quicker and easier.
Project URL

Project URL

https://github.com/mcac0006/sift-java
Source Code Management

Source Code Management

http://github.com/mcac0006/sift-java/tree/master

Download sift-java

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.mcac0006/sift-java/ -->
<dependency>
    <groupId>com.github.mcac0006</groupId>
    <artifactId>sift-java</artifactId>
    <version>0.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.mcac0006/sift-java/
implementation 'com.github.mcac0006:sift-java:0.0.1'
// https://jarcasting.com/artifacts/com.github.mcac0006/sift-java/
implementation ("com.github.mcac0006:sift-java:0.0.1")
'com.github.mcac0006:sift-java:jar:0.0.1'
<dependency org="com.github.mcac0006" name="sift-java" rev="0.0.1">
  <artifact name="sift-java" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.mcac0006', module='sift-java', version='0.0.1')
)
libraryDependencies += "com.github.mcac0006" % "sift-java" % "0.0.1"
[com.github.mcac0006/sift-java "0.0.1"]

Dependencies

compile (4)

Group / Artifact Type Version
org.codehaus.jackson : jackson-mapper-asl jar 1.9.13
org.glassfish.jersey.core : jersey-client jar 2.7
org.mockito : mockito-core jar 1.9.5
com.jayway.jsonpath : json-path jar 1.1.0

test (4)

Group / Artifact Type Version
junit : junit jar 4.11
org.powermock : powermock-module-junit4 jar 1.5.1
org.powermock : powermock-api-mockito jar 1.5.1
commons-io : commons-io jar 2.4

Project Modules

There are no modules declared in this project.

sift-java

Java library which help integrate your Java application to Sift Science (http://www.siftscience.com) quicker and easier.

This library has been made using Jersey (https://jersey.java.net) for the transport layer and Jackson JSON Processor (http://jackson.codehaus.org) as (de)serializer.

  1. Installation (using Maven)

The library is distributed via Sonatype - just add the following dependency to your project and it will download by itself:

<dependency>  
	<groupId>com.github.mcac0006</groupId>  
	<artifactId>sift-java</artifactId>  
	<version>0.0.1</version>  
</dependency>
  1. How to use

SiftScienceHelper contains a static of methods which can be used to send and receive requests with SiftScience using Jersey (https://jersey.java.net) to send and receive HTTP requests/responses.

// Sending a an Event (such as a Transaction) is easy! Let's create a Transaction ($transaction) event.
Event event = new Transaction(); // create an event
event.setApiKey("API_KEY_GOES_HERE");
event.setX(...).setY(...).setZ(...); //fill in all fields using setters

// ... you can also add custom fields of your own to any event!
event.addCustomField('key1', 'value1');
event.addCustomField('key2', 'value2');
...

SiftScienceResult ssr = SiftScienceHelper.send(event); //send the event to Sift Science

// Labels are also created in the same fashion
Label label = new Label(); // create an event
label.setApiKey("API_KEY_GOES_HERE");
label.setX(...).setY(...).setZ(...); //fill in all fields using setters

SiftScienceResult ssr = SiftScienceHelper.send(event); //send the event to Sift Science
// If you're interested in getting the SiftScore for that particular user ...
SiftScienceScore score = SiftScienceHelper.getScore("API_KEY_GOES_HERE", "mcac0006");
// Use the getters to retrieve the score information, such as ...
score.getScore();

Using your own Http client? You can use this library just to serialize/deserialize objects to JSON-ready requests!

`` // ... // creation of Event/Label // ...

String $transaction = SiftScienceHelper.serialize(event); // serialize an event such as a $transaction
String $label = SiftScienceHelper.serialize(label); // serialize a $label

SiftScienceResponse response = SiftScienceHelper.deserializeResponse($response); // create a POJO out of the response returned after submitting an $event or $label.

SiftScienceScore score = SiftScienceHelper.deserializeScore($scoreResponse); // create a POJO out of the response returned by Sift Science for a particular user.

Do you have a custom event of your own?

  1. Creating a custom event of your own (is easy!)

  1. Create your own Java class and extend com.mcac0006.siftscience.event.domain.Event

  2. Create your private attributes and their getters and setters

  3. Make sure you override and implement the equals() method. You will need it for your JUnit test (below).

  4. Recommended! Create at least one JUnit test to make sure your class is being serialized properly. Check out com.mcac0006.services.siftscience.SiftScienceBodyTest to have a better idea on how this is done with the standard Event classes.

  5. License


The MIT License (MIT)

Copyright (c) 2014 Matthew Cachia

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.

Versions

Version
0.0.1