Skip to content

Commit b3eb0a9

Browse files
committed
Traitify api client and tests.
1 parent 3bbfcae commit b3eb0a9

18 files changed

+974
-12
lines changed

Diff for: .gitignore

+7-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
*.class
2-
3-
# Mobile Tools for Java (J2ME)
4-
.mtj.tmp/
5-
6-
# Package Files #
7-
*.jar
8-
*.war
9-
*.ear
10-
11-
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
12-
hs_err_pid*
1+
*.swp
2+
.classpath
3+
.project
4+
.settings
5+
target
6+
.idea
7+
*.iml

Diff for: LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License
2+
3+
Copyright (c) 2014- Traitify, Inc. (https://traitify.com)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Diff for: README.md

+60
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,63 @@ traitify-java
22
=============
33

44
Traitify API client written in Java.
5+
=======
6+
# Traitify Java Client
7+
8+
You can sign up for a Traitify account at https://developers.traitify.com.
9+
10+
Requirements
11+
============
12+
13+
Java 1.5 and later.
14+
15+
Installation
16+
============
17+
18+
### Maven users
19+
20+
Add this dependency to your project's POM:
21+
22+
<dependency>
23+
<groupId>com.traitify</groupId>
24+
<artifactId>traitify-java</artifactId>
25+
<version>0.0.1</version>
26+
</dependency>
27+
28+
### Others
29+
30+
You'll need to manually install the following JARs:
31+
32+
* The Traitify JAR from https://code.stripe.com/traitify-java-latest.jar
33+
* [Jersey Client](https://jersey.java.net/nonav/documentation/1.17/chapter_deps.html#core_client) from <http://maven.java.net/service/local/artifact/maven/redirect?r=releases&g=com.sun.jersey&a=jersey-client&v=1.17&e=jar>.
34+
* [Jersey Core](https://jersey.java.net/download.html) from <http://maven.java.net/service/local/artifact/maven/redirect?r=releases&g=com.sun.jersey&a=jersey-core&v=1.17&e=jar>.
35+
36+
Usage
37+
=====
38+
39+
TraitifyExample.java
40+
41+
import com.traitify.Traitify;
42+
import com.traitify.model.Assessment;
43+
import com.traitify.model.Deck;
44+
45+
public class TraitifyExample {
46+
public static void main(String[] args) {
47+
Traitify.apiKey = "YOUR-SECRET-KEY";
48+
List<Deck> decks = Deck.list();
49+
Deck deck;
50+
for(Deck _deck:decks){
51+
if(_deck.getName().equals("General Personality"){
52+
deck = _deck;
53+
}
54+
}
55+
Assessment assessment = Assessment.create(deck.getId());
56+
}
57+
}
58+
59+
See [TraitifyTest.java](https://github.com/woofound/traitify-java/blob/master/src/test/java/com/traitify/TraitifyTest.java) for more examples.
60+
61+
Testing
62+
=======
63+
64+
You must have Maven installed. To run the tests, simply run `mvn test`. You can run particular tests by passing `-D test=Class#method` -- for example, `-D test=StripeTest#testPlanCreate`. You must also specify your `apiKey` when testing, you can do that by passing `-DapiKey=yourapikey`.

Diff for: VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.0.1

Diff for: pom.xml

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.traitify</groupId>
5+
<artifactId>traitify-java</artifactId>
6+
<packaging>jar</packaging>
7+
<version>0.0.1</version>
8+
<name>traitify-java</name>
9+
<url>https://github.com/woofound/traitify-java</url>
10+
<dependencies>
11+
<dependency>
12+
<groupId>com.sun.jersey</groupId>
13+
<artifactId>jersey-client</artifactId>
14+
<version>1.17</version>
15+
</dependency>
16+
<dependency>
17+
<groupId>com.sun.jersey</groupId>
18+
<artifactId>jersey-json</artifactId>
19+
<version>1.17</version>
20+
</dependency>
21+
<dependency>
22+
<groupId>junit</groupId>
23+
<artifactId>junit</artifactId>
24+
<version>4.10</version>
25+
<scope>test</scope>
26+
</dependency>
27+
</dependencies>
28+
<description>Traitify Java Client</description>
29+
<organization>
30+
<name>Traitify</name>
31+
<url>https://traitify.com</url>
32+
</organization>
33+
<parent>
34+
<groupId>org.sonatype.oss</groupId>
35+
<artifactId>oss-parent</artifactId>
36+
<version>7</version>
37+
</parent>
38+
<scm>
39+
<connection>scm:git:[email protected]:woofound/traitify-java.git</connection>
40+
<developerConnection>scm:git:[email protected]:woofound/traitify-java.git</developerConnection>
41+
<url>[email protected]:woofound/traitify-java.git</url>
42+
</scm>
43+
<build>
44+
<resources>
45+
<resource>
46+
<directory>.</directory>
47+
<includes>
48+
<include>VERSION</include>
49+
</includes>
50+
</resource>
51+
</resources>
52+
<plugins>
53+
<plugin>
54+
<groupId>org.apache.maven.plugins</groupId>
55+
<artifactId>maven-gpg-plugin</artifactId>
56+
<executions>
57+
<execution>
58+
<id>sign-artifacts</id>
59+
<phase>verify</phase>
60+
<goals>
61+
<goal>sign</goal>
62+
</goals>
63+
</execution>
64+
</executions>
65+
</plugin>
66+
<plugin>
67+
<groupId>org.apache.maven.plugins</groupId>
68+
<artifactId>maven-compiler-plugin</artifactId>
69+
<configuration>
70+
<source>1.5</source>
71+
<target>1.5</target>
72+
</configuration>
73+
</plugin>
74+
<plugin>
75+
<groupId>org.apache.maven.plugins</groupId>
76+
<artifactId>maven-source-plugin</artifactId>
77+
<executions>
78+
<execution>
79+
<id>attach-sources</id>
80+
<goals>
81+
<goal>jar</goal>
82+
</goals>
83+
</execution>
84+
</executions>
85+
</plugin>
86+
<plugin>
87+
<groupId>org.apache.maven.plugins</groupId>
88+
<artifactId>maven-javadoc-plugin</artifactId>
89+
<executions>
90+
<execution>
91+
<id>attach-javadocs</id>
92+
<goals>
93+
<goal>jar</goal>
94+
</goals>
95+
</execution>
96+
</executions>
97+
</plugin>
98+
<plugin>
99+
<groupId>org.sonatype.plugins</groupId>
100+
<artifactId>nexus-staging-maven-plugin</artifactId>
101+
<executions>
102+
<execution>
103+
<id>default-deploy</id>
104+
<phase>deploy</phase>
105+
<goals>
106+
<goal>deploy</goal>
107+
</goals>
108+
</execution>
109+
</executions>
110+
<configuration>
111+
<serverId>sonatype-nexus-staging</serverId>
112+
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
113+
</configuration>
114+
</plugin>
115+
</plugins>
116+
</build>
117+
</project>
118+

Diff for: src/main/java/com/traitify/Traitify.java

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.traitify;
2+
3+
public abstract class Traitify {
4+
5+
public static final String LIVE_API_BASE = "https://api.traitify.com";
6+
public static final String VERSION = "0.0.1";
7+
public static String apiKey;
8+
public static String apiVersion = "v1";
9+
10+
private static String apiBase = LIVE_API_BASE;
11+
12+
/**
13+
* (FOR TESTING ONLY)
14+
* If you'd like your API requests to hit your own (mocked) server,
15+
* you can set this up here by overriding the base api URL.
16+
*/
17+
public static void overrideApiBase(final String overriddenApiBase) {
18+
apiBase = overriddenApiBase;
19+
}
20+
21+
public static String getApiBase() {
22+
return apiBase;
23+
}
24+
25+
}

Diff for: src/main/java/com/traitify/models/Assessment.java

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package com.traitify.models;
2+
3+
import com.sun.jersey.api.client.GenericType;
4+
import com.traitify.net.ApiModel;
5+
6+
import java.util.Date;
7+
import java.util.List;
8+
9+
public class Assessment extends ApiModel {
10+
11+
public static Assessment get(String assessment_id) {
12+
return baseResource("assessments/" + assessment_id).get(Assessment.class);
13+
}
14+
15+
public static Assessment create(String deck_id, String user_id) {
16+
Assessment assessment = new Assessment();
17+
assessment.setDeck_id(deck_id);
18+
assessment.setUser_id(user_id);
19+
return Assessment.create(assessment);
20+
}
21+
22+
public static Assessment create(String deck_id) {
23+
Assessment assessment = new Assessment();
24+
assessment.setDeck_id(deck_id);
25+
return Assessment.create(assessment);
26+
}
27+
28+
public static Assessment create(Assessment assessment) {
29+
return baseResource("assessments").post(Assessment.class, assessment);
30+
}
31+
32+
public static Assessment update(Assessment assessment) {
33+
return baseResource("assessments/" + assessment.getId()).put(Assessment.class, assessment);
34+
}
35+
36+
public static AssessmentPersonalityTypes personalityTypes(String assessment_id){
37+
return baseResource("assessments/" + assessment_id + "/personality_types").get(AssessmentPersonalityTypes.class);
38+
}
39+
40+
public static List<AssessmentPersonalityTrait> personalityTraits(String assessment_id, String personality_type_id){
41+
return baseResource("assessments/" + assessment_id + "/personality_types/" + personality_type_id + "/personality_traits").get(new GenericType<List<AssessmentPersonalityTrait>>(){});
42+
}
43+
44+
private String id;
45+
private String deck_id;
46+
private String user_id;
47+
private Date created_at;
48+
private Date completed_at;
49+
50+
public String getId() {
51+
return id;
52+
}
53+
54+
public void setId(String id) {
55+
this.id = id;
56+
}
57+
58+
public String getDeck_id() {
59+
return deck_id;
60+
}
61+
62+
public void setDeck_id(String deck_id) {
63+
this.deck_id = deck_id;
64+
}
65+
66+
public String getUser_id() {
67+
return user_id;
68+
}
69+
70+
public void setUser_id(String user_id) {
71+
this.user_id = user_id;
72+
}
73+
74+
public Date getCreated_at() {
75+
return created_at;
76+
}
77+
78+
public void setCreated_at(Date created_at) {
79+
this.created_at = created_at;
80+
}
81+
82+
public Date getCompleted_at() {
83+
return completed_at;
84+
}
85+
86+
public void setCompleted_at(Date completed_at) {
87+
this.completed_at = completed_at;
88+
}
89+
90+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.traitify.models;
2+
3+
import com.traitify.net.ApiModel;
4+
5+
public class AssessmentPersonalityTrait extends ApiModel {
6+
7+
private PersonalityTrait personality_trait;
8+
private Float score;
9+
10+
public PersonalityTrait getPersonality_trait() {
11+
return personality_trait;
12+
}
13+
14+
public void setPersonality_trait(PersonalityTrait personality_trait) {
15+
this.personality_trait = personality_trait;
16+
}
17+
18+
public Float getScore() {
19+
return score;
20+
}
21+
22+
public void setScore(Float score) {
23+
this.score = score;
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.traitify.models;
2+
3+
public class AssessmentPersonalityType {
4+
5+
private PersonalityType personality_type;
6+
private Float score;
7+
8+
public PersonalityType getPersonality_type() {
9+
return personality_type;
10+
}
11+
12+
public void setPersonality_type(PersonalityType personality_type) {
13+
this.personality_type = personality_type;
14+
}
15+
16+
public Float getScore() {
17+
return score;
18+
}
19+
20+
public void setScore(Float score) {
21+
this.score = score;
22+
}
23+
}

0 commit comments

Comments
 (0)