Skip to content

Commit 88fca0a

Browse files
committed
Merge pull request #56 from remear/inception
Inception
2 parents 35cea26 + 4d1c24c commit 88fca0a

306 files changed

Lines changed: 2657 additions & 1243 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ target
2626

2727
# idea
2828
.idea
29-
*.iml
29+
*.iml
30+
31+
jangod

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ jdk:
44
- openjdk7
55
- openjdk6
66
- oraclejdk7
7+
8+
script: "mvn install -DskipTests=true -B && mvn cobertura:check"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ key.save();
4141
System.out.printf("Our secret is %s\n", key.secret);
4242

4343
System.out.printf("Configure with our secret\n");
44-
Settings.configure(key.secret);
44+
Balanced.configure(key.secret);
4545

4646
System.out.printf("Create marketplace\n");
4747
Marketplace mp = new Marketplace();

pom.xml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,25 @@
6666
<version>4.10</version>
6767
<scope>test</scope>
6868
</dependency>
69+
<dependency>
70+
<groupId>org.codehaus.mojo</groupId>
71+
<artifactId>cobertura-maven-plugin</artifactId>
72+
<version>2.6</version>
73+
</dependency>
74+
<dependency>
75+
<groupId>com.fasterxml.jackson.core</groupId>
76+
<artifactId>jackson-databind</artifactId>
77+
<version>2.2.3</version>
78+
</dependency>
79+
<!--
80+
<dependency>
81+
<groupId>net.asfun.jangod</groupId>
82+
<artifactId>jangod</artifactId>
83+
<version>1.0-SNAPSHOT</version>
84+
<scope>system</scope>
85+
<systemPath>${project.basedir}/lib/jangod.jar</systemPath>
86+
</dependency>
87+
-->
6988
</dependencies>
7089
<profiles>
7190
<profile>
@@ -156,7 +175,52 @@
156175
<useFile>false</useFile>
157176
<trimStackTrace>false</trimStackTrace>
158177
</configuration>
178+
<executions>
179+
<execution>
180+
<goals>
181+
<goal>test</goal>
182+
</goals>
183+
</execution>
184+
</executions>
185+
</plugin>
186+
187+
<plugin>
188+
<groupId>org.codehaus.mojo</groupId>
189+
<artifactId>cobertura-maven-plugin</artifactId>
190+
<version>2.6</version>
191+
<configuration>
192+
<instrumentation>
193+
<excludes>
194+
<exclude>${project.basedir}/src/scenarios/**</exclude>
195+
</excludes>
196+
</instrumentation>
197+
<check>
198+
<branchRate>0</branchRate>
199+
<lineRate>0</lineRate>
200+
<haltOnFailure>true</haltOnFailure>
201+
<totalBranchRate>30</totalBranchRate>
202+
<totalLineRate>30</totalLineRate>
203+
<packageLineRate>30</packageLineRate>
204+
<packageBranchRate>30</packageBranchRate>
205+
</check>
206+
</configuration>
207+
<executions>
208+
<execution>
209+
<goals>
210+
<goal>cobertura</goal>
211+
</goals>
212+
</execution>
213+
</executions>
159214
</plugin>
160215
</plugins>
161216
</build>
217+
<reporting>
218+
<plugins>
219+
<plugin>
220+
<groupId>org.codehaus.mojo</groupId>
221+
<artifactId>cobertura-maven-plugin</artifactId>
222+
<version>2.6</version>
223+
</plugin>
224+
</plugins>
225+
</reporting>
162226
</project>

src/examples/com/balancedpayments/QuickStart.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static void main(String [] args) throws HTTPError, NoResultsFound, Multip
1616
System.out.printf("Our secret is %s\n", key.secret);
1717

1818
System.out.printf("Configure with our secret\n");
19-
Settings.configure(key.secret);
19+
Balanced.configure(key.secret);
2020

2121
System.out.printf("Create marketplace\n");
2222
Marketplace mp = new Marketplace();

src/main/java/com/balancedpayments/APIKey.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
public class APIKey extends Resource
1212
{
13-
private static final String root_uri = String.format("/v%s/%s", Settings.VERSION, "api_keys");
13+
private static final String root_uri = String.format("/v%s/%s", Balanced.getInstance().getAPIVersion(), "api_keys");
1414

1515
@ResourceField()
1616
public Date created_at;
@@ -25,10 +25,17 @@ public static ResourceCollection<APIKey> query() {
2525
return new ResourceCollection<APIKey>(APIKey.class, root_uri);
2626
}
2727

28+
public void saveToExistingMarketplace() throws HTTPError {
29+
if (id == null && uri == null)
30+
uri = APIKey.root_uri;
31+
super.save();
32+
}
33+
2834
@Override
2935
public void save() throws HTTPError {
3036
if (id == null && uri == null)
3137
uri = APIKey.root_uri;
38+
Balanced.configure(null);
3239
super.save();
3340
}
3441
}

src/main/java/com/balancedpayments/Account.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.util.HashMap;
55
import java.util.Map;
66

7-
import com.balancedpayments.core.Client;
87
import com.balancedpayments.core.Resource;
98
import com.balancedpayments.core.ResourceCollection;
109
import com.balancedpayments.core.ResourceField;
@@ -55,7 +54,7 @@ public Collection(String uri) {
5554
};
5655

5756
public static Account get(String uri) throws HTTPError {
58-
return new Account((new Client()).get(uri));
57+
return new Account((Balanced.getInstance().getClient()).get(uri));
5958
}
6059

6160
public Account() {
@@ -108,7 +107,7 @@ public Debit debit(
108107
if (description != null)
109108
payload.put("description", description);
110109
if (source_uri != null)
111-
payload.put("source", source_uri);
110+
payload.put("source_uri", source_uri);
112111
if (appears_on_statement_as != null)
113112
payload.put("appears_on_statement_as", appears_on_statement_as);
114113
if (meta != null)
@@ -134,7 +133,7 @@ public Hold hold(
134133
if (description != null)
135134
payload.put("description", description);
136135
if (source_uri != null)
137-
payload.put("source", source_uri);
136+
payload.put("source_uri", source_uri);
138137
if (meta != null)
139138
payload.put("meta", meta);
140139
return holds.create(payload);
@@ -147,14 +146,14 @@ public Hold hold(int amount) throws HTTPError {
147146
public void associateBankAccount(String bank_account_uri) throws HTTPError {
148147
Map<String, Object> payload = new HashMap<String, Object>();
149148
payload.put("bank_account_uri", bank_account_uri);
150-
Map<String, Object> response = client.put(uri, payload);
149+
Map<String, Object> response = Balanced.getInstance().getClient().put(uri, payload);
151150
deserialize(response);
152151
}
153152

154153
public void promoteToMerchant(Map<String, Object> merchant_map) throws HTTPError {
155154
Map<String, Object> payload = new HashMap<String, Object>();
156155
payload.put("merchant", merchant_map);
157-
Map<String, Object> response = client.put(uri, payload);
156+
Map<String, Object> response = Balanced.getInstance().getClient().put(uri, payload);
158157
deserialize(response);
159158
}
160159

@@ -171,14 +170,14 @@ You should use the promoteToMerchant(Map<String, Object> merchant_map) method
171170
public void promoteToMerchant(String merchant_uri) throws HTTPError {
172171
Map<String, Object> payload = new HashMap<String, Object>();
173172
payload.put("merchant_uri", merchant_uri);
174-
Map<String, Object> response = client.put(uri, payload);
173+
Map<String, Object> response = Balanced.getInstance().getClient().put(uri, payload);
175174
deserialize(response);
176175
}
177176

178177
public void associateCard(String card_uri) throws HTTPError {
179178
Map<String, Object> payload = new HashMap<String, Object>();
180179
payload.put("card_uri", card_uri);
181-
Map<String, Object> response = client.put(uri, payload);
180+
Map<String, Object> response = Balanced.getInstance().getClient().put(uri, payload);
182181
deserialize(response);
183182
}
184183
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.balancedpayments;
2+
3+
import com.balancedpayments.core.Client;
4+
5+
public class Balanced {
6+
7+
private static final Balanced _instance = new Balanced();
8+
9+
private static final String API_VERSION = "1";
10+
private static final String API_URL = "https://api.balancedpayments.com";
11+
private String KEY;
12+
private Client client = new Client(API_URL, null);
13+
14+
private Balanced() {}
15+
16+
public static synchronized Balanced getInstance() {
17+
return _instance;
18+
}
19+
20+
public void configureClient(String key) {
21+
KEY=key;
22+
client = new Client(API_URL, key);
23+
}
24+
public static void configure(String key) {
25+
getInstance().configureClient(key);
26+
}
27+
28+
public Client getClient() {
29+
return client;
30+
}
31+
32+
public String getAPIVersion() {
33+
return API_VERSION;
34+
}
35+
36+
public String getAPIURL() {
37+
return API_URL;
38+
}
39+
}

src/main/java/com/balancedpayments/BankAccount.java

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.util.HashMap;
44
import java.util.Map;
55

6-
import com.balancedpayments.core.Client;
76
import com.balancedpayments.core.ResourceCollection;
87
import com.balancedpayments.core.ResourceField;
98
import com.balancedpayments.core.ResourceQuery;
@@ -13,8 +12,8 @@
1312

1413
public class BankAccount extends FundingInstrument {
1514

16-
public final static String Checking = "checking";
17-
public final static String Savings = "savings";
15+
public final static String CHECKING = "checking";
16+
public final static String SAVINGS = "savings";
1817

1918
@ResourceField()
2019
public String fingerprint;
@@ -34,7 +33,7 @@ public class BankAccount extends FundingInstrument {
3433
@ResourceField()
3534
public String bank_name;
3635

37-
@ResourceField()
36+
@ResourceField(mutable=true)
3837
public Map<String, String> meta;
3938

4039
@ResourceField(field="verifications_uri")
@@ -55,7 +54,7 @@ public class BankAccount extends FundingInstrument {
5554
@ResourceField(field="holds_uri")
5655
public Hold.Collection holds;
5756

58-
protected static final String root_uri = "/v" + Settings.VERSION + "/bank_accounts";
57+
protected static final String root_uri = "/v" + Balanced.getInstance().getAPIVersion() + "/bank_accounts";
5958

6059
public static class Collection extends ResourceCollection<BankAccount> {
6160
public Collection(String uri) {
@@ -64,7 +63,7 @@ public Collection(String uri) {
6463
}
6564

6665
public static BankAccount get(String uri) throws HTTPError {
67-
return new BankAccount((new Client()).get(uri));
66+
return new BankAccount((Balanced.getInstance().getClient()).get(uri));
6867
}
6968

7069
public BankAccount() {
@@ -102,30 +101,11 @@ public BankAccountVerification getVerification() throws HTTPError {
102101
return new BankAccountVerification(verification_uri);
103102
}
104103

105-
public Credit credit(
106-
int amount,
107-
String description,
108-
String destination_uri,
109-
String appears_on_statement_as,
110-
Map<String, String> meta) throws HTTPError {
111-
Map<String, Object> payload = new HashMap<String, Object>();
112-
payload.put("amount", amount);
113-
if (description != null)
114-
payload.put("description", description);
115-
if (destination_uri != null)
116-
payload.put("destination", destination_uri);
117-
if (appears_on_statement_as != null)
118-
payload.put("appears_on_statement_as", appears_on_statement_as);
119-
if (meta != null)
120-
payload.put("meta", meta);
104+
public Credit credit(Map<String, Object> payload) throws HTTPError {
121105
return credits.create(payload);
122106
}
123107

124-
public Credit credit(int amount) throws HTTPError {
125-
return credit(amount, null, null, null, null);
126-
}
127-
128-
public void unstore() throws HTTPError, NotCreated {
129-
super.delete();
108+
public Debit debit(Map<String, Object> payload) throws HTTPError {
109+
return debits.create(payload);
130110
}
131111
}

src/main/java/com/balancedpayments/BankAccountVerification.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,11 @@ public BankAccountVerification(String uri) throws HTTPError {
3333
super(uri);
3434
}
3535

36-
public BankAccountVerification(Map<String, Object> payload) {
37-
super(payload);
38-
}
39-
4036
public void confirm(int amount_1, int amount_2) throws HTTPError {
4137
Map<String, Object> request = new HashMap<String, Object>();
4238
request.put("amount_1", amount_1);
4339
request.put("amount_2", amount_2);
44-
Map<String, Object> response = client.put(uri, request);
40+
Map<String, Object> response = Balanced.getInstance().getClient().put(uri, request);
4541
deserialize(response);
4642
}
4743
}

0 commit comments

Comments
 (0)