Skip to content

Commit 671a9b3

Browse files
authored
Merge pull request #229 from mwarzybok-sumoheavy/feature/SP-522
Improve create clients
2 parents af156b7 + c9ffa15 commit 671a9b3

38 files changed

+327
-520
lines changed

src/main/java/com/bitpay/sdk/Client.java

Lines changed: 63 additions & 63 deletions
Large diffs are not rendered by default.

src/main/java/com/bitpay/sdk/client/BillClient.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
/**
2929
* The type Bill client.
3030
*/
31-
public class BillClient {
31+
public class BillClient implements ResourceClient {
3232

33+
private static BillClient instance;
3334
private final BitPayClient bitPayClient;
3435
private final TokenContainer accessTokens;
3536

@@ -39,11 +40,26 @@ public class BillClient {
3940
* @param bitPayClient the bit pay client
4041
* @param accessTokens the access tokens
4142
*/
42-
public BillClient(BitPayClient bitPayClient, TokenContainer accessTokens) {
43+
private BillClient(BitPayClient bitPayClient, TokenContainer accessTokens) {
4344
this.bitPayClient = bitPayClient;
4445
this.accessTokens = accessTokens;
4546
}
4647

48+
/**
49+
* Factory method for Bill Client.
50+
*
51+
* @param bitPayClient BitPay Client
52+
* @param accessTokens Access Tokens
53+
* @return BillClient
54+
*/
55+
public static BillClient getInstance(BitPayClient bitPayClient, TokenContainer accessTokens) {
56+
if (Objects.isNull(instance)) {
57+
instance = new BillClient(bitPayClient, accessTokens);
58+
}
59+
60+
return instance;
61+
}
62+
4763
/**
4864
* Create a BitPay Bill.
4965
*

src/main/java/com/bitpay/sdk/client/CurrencyClient.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
/**
2020
* The type Currency client.
2121
*/
22-
public class CurrencyClient {
22+
public class CurrencyClient implements ResourceClient {
2323

24+
private static CurrencyClient instance;
2425
private final BitPayClient client;
2526
private List<Map<String, String>> currenciesInfo;
2627

@@ -30,13 +31,27 @@ public class CurrencyClient {
3031
* @param client the client
3132
* @throws BitPayException the bit pay exception
3233
*/
33-
public CurrencyClient(BitPayClient client) throws BitPayException {
34+
private CurrencyClient(BitPayClient client) throws BitPayException {
3435
if (Objects.isNull(client)) {
3536
throw new BitPayException(null, "failed init Currency Client");
3637
}
3738
this.client = client;
3839
}
3940

41+
/**
42+
* Factory method for Currency Client.
43+
*
44+
* @param bitPayClient BitPay Client
45+
* @return CurrencyClient
46+
*/
47+
public static CurrencyClient getInstance(BitPayClient bitPayClient) throws BitPayException {
48+
if (Objects.isNull(instance)) {
49+
instance = new CurrencyClient(bitPayClient);
50+
}
51+
52+
return instance;
53+
}
54+
4055
/**
4156
* Gets info for specific currency.
4257
*

src/main/java/com/bitpay/sdk/client/InvoiceClient.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@
3131
/**
3232
* The type Invoice client.
3333
*/
34-
public class InvoiceClient {
34+
public class InvoiceClient implements ResourceClient {
3535

36+
private static InvoiceClient instance;
3637
private final BitPayClient bitPayClient;
3738
private final TokenContainer accessTokens;
3839
private final GuidGenerator guidGenerator;
@@ -44,7 +45,7 @@ public class InvoiceClient {
4445
* @param accessTokens the access tokens
4546
* @param guidGenerator the Guid generator
4647
*/
47-
public InvoiceClient(
48+
private InvoiceClient(
4849
BitPayClient bitPayClient,
4950
TokenContainer accessTokens,
5051
GuidGenerator guidGenerator
@@ -54,6 +55,26 @@ public InvoiceClient(
5455
this.guidGenerator = guidGenerator;
5556
}
5657

58+
/**
59+
* Factory method for Invoice Client.
60+
*
61+
* @param bitPayClient BitPay Client
62+
* @param accessTokens Access Tokens
63+
* @param guidGenerator Guid Generator
64+
* @return InvoiceClient
65+
*/
66+
public static InvoiceClient getInstance(
67+
BitPayClient bitPayClient,
68+
TokenContainer accessTokens,
69+
GuidGenerator guidGenerator
70+
) {
71+
if (Objects.isNull(instance)) {
72+
instance = new InvoiceClient(bitPayClient, accessTokens, guidGenerator);
73+
}
74+
75+
return instance;
76+
}
77+
5778
/**
5879
* Create a BitPay invoice.
5980
*

src/main/java/com/bitpay/sdk/client/LedgerClient.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
/**
2424
* The type Ledger client.
2525
*/
26-
public class LedgerClient {
26+
public class LedgerClient implements ResourceClient {
2727

28+
private static LedgerClient instance;
2829
private final BitPayClient bitPayClient;
2930
private final TokenContainer accessTokens;
3031

@@ -34,11 +35,26 @@ public class LedgerClient {
3435
* @param bitPayClient the bit pay client
3536
* @param accessTokens the access tokens
3637
*/
37-
public LedgerClient(BitPayClient bitPayClient, TokenContainer accessTokens) {
38+
private LedgerClient(BitPayClient bitPayClient, TokenContainer accessTokens) {
3839
this.bitPayClient = bitPayClient;
3940
this.accessTokens = accessTokens;
4041
}
4142

43+
/**
44+
* Factory method for Ledger Client.
45+
*
46+
* @param bitPayClient BitPay Client
47+
* @param accessTokens Access Tokens
48+
* @return LedgerClient
49+
*/
50+
public static LedgerClient getInstance(BitPayClient bitPayClient, TokenContainer accessTokens) {
51+
if (Objects.isNull(instance)) {
52+
instance = new LedgerClient(bitPayClient, accessTokens);
53+
}
54+
55+
return instance;
56+
}
57+
4258
/**
4359
* Retrieve a list of ledgers entries by currency and date range using the merchant facade.
4460
*

src/main/java/com/bitpay/sdk/client/PayoutClient.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
/**
3131
* The type Payout client.
3232
*/
33-
public class PayoutClient {
33+
public class PayoutClient implements ResourceClient {
3434

35+
private static PayoutClient instance;
3536
private final BitPayClient bitPayClient;
3637
private final TokenContainer accessTokens;
3738

@@ -41,11 +42,26 @@ public class PayoutClient {
4142
* @param bitPayClient the bit pay client
4243
* @param accessTokens the access tokens
4344
*/
44-
public PayoutClient(BitPayClient bitPayClient, TokenContainer accessTokens) {
45+
private PayoutClient(BitPayClient bitPayClient, TokenContainer accessTokens) {
4546
this.bitPayClient = bitPayClient;
4647
this.accessTokens = accessTokens;
4748
}
4849

50+
/**
51+
* Factory method for Bill Client.
52+
*
53+
* @param bitPayClient BitPay Client
54+
* @param accessTokens Access Tokens
55+
* @return PayoutClient
56+
*/
57+
public static PayoutClient getInstance(BitPayClient bitPayClient, TokenContainer accessTokens) {
58+
if (Objects.isNull(instance)) {
59+
instance = new PayoutClient(bitPayClient, accessTokens);
60+
}
61+
62+
return instance;
63+
}
64+
4965
/**
5066
* Submit a BitPay Payout.
5167
*

src/main/java/com/bitpay/sdk/client/PayoutRecipientsClient.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@
3333
/**
3434
* The type Payout recipients client.
3535
*/
36-
public class PayoutRecipientsClient {
36+
public class PayoutRecipientsClient implements ResourceClient {
3737

38+
private static PayoutRecipientsClient instance;
3839
private final BitPayClient bitPayClient;
3940
private final TokenContainer accessTokens;
4041
private final GuidGenerator guidGenerator;
@@ -46,7 +47,7 @@ public class PayoutRecipientsClient {
4647
* @param accessTokens the access tokens
4748
* @param guidGenerator the Guid generator
4849
*/
49-
public PayoutRecipientsClient(
50+
private PayoutRecipientsClient(
5051
BitPayClient bitPayClient,
5152
TokenContainer accessTokens,
5253
GuidGenerator guidGenerator
@@ -56,6 +57,26 @@ public PayoutRecipientsClient(
5657
this.guidGenerator = guidGenerator;
5758
}
5859

60+
/**
61+
* Factory method for Bill Client.
62+
*
63+
* @param bitPayClient BitPay Client
64+
* @param accessTokens Access Tokens
65+
* @param guidGenerator Guid Generator
66+
* @return PayoutRecipientsClient
67+
*/
68+
public static PayoutRecipientsClient getInstance(
69+
BitPayClient bitPayClient,
70+
TokenContainer accessTokens,
71+
GuidGenerator guidGenerator
72+
) {
73+
if (Objects.isNull(instance)) {
74+
instance = new PayoutRecipientsClient(bitPayClient, accessTokens, guidGenerator);
75+
}
76+
77+
return instance;
78+
}
79+
5980
/**
6081
* Submit BitPay Payout Recipients.
6182
*

src/main/java/com/bitpay/sdk/client/RateClient.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,40 @@
1111
import com.fasterxml.jackson.core.JsonProcessingException;
1212
import java.util.Arrays;
1313
import java.util.List;
14+
import java.util.Objects;
1415
import org.apache.http.HttpResponse;
1516

1617
/**
1718
* The type Rate client.
1819
*/
19-
public class RateClient {
20+
public class RateClient implements ResourceClient {
2021

22+
private static RateClient instance;
2123
private final BitPayClient bitPayClient;
2224

2325
/**
2426
* Instantiates a new Rate client.
2527
*
2628
* @param bitPayClient the bit pay client
2729
*/
28-
public RateClient(BitPayClient bitPayClient) {
30+
private RateClient(BitPayClient bitPayClient) {
2931
this.bitPayClient = bitPayClient;
3032
}
3133

34+
/**
35+
* Factory method for Rate Client.
36+
*
37+
* @param bitPayClient BitPay Client
38+
* @return RateClient
39+
*/
40+
public static RateClient getInstance(BitPayClient bitPayClient) {
41+
if (Objects.isNull(instance)) {
42+
instance = new RateClient(bitPayClient);
43+
}
44+
45+
return instance;
46+
}
47+
3248
/**
3349
* Retrieve the rates for a cryptocurrency / fiat pair. See https://bitpay.com/bitcoin-exchange-rates.
3450
*

src/main/java/com/bitpay/sdk/client/RefundClient.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@
3131
/**
3232
* The type Refund client.
3333
*/
34-
public class RefundClient {
34+
public class RefundClient implements ResourceClient {
3535

36+
private static RefundClient instance;
3637
private final BitPayClient bitPayClient;
3738
private final TokenContainer accessTokens;
3839
private final GuidGenerator guidGenerator;
@@ -44,12 +45,32 @@ public class RefundClient {
4445
* @param accessTokens the access tokens
4546
* @param guidGenerator GUID generator
4647
*/
47-
public RefundClient(BitPayClient bitPayClient, TokenContainer accessTokens, GuidGenerator guidGenerator) {
48+
private RefundClient(BitPayClient bitPayClient, TokenContainer accessTokens, GuidGenerator guidGenerator) {
4849
this.bitPayClient = bitPayClient;
4950
this.accessTokens = accessTokens;
5051
this.guidGenerator = guidGenerator;
5152
}
5253

54+
/**
55+
* Factory method for Bill Client.
56+
*
57+
* @param bitPayClient BitPay Client
58+
* @param accessTokens Access Tokens
59+
* @param guidGenerator Guid generator
60+
* @return RefundClient
61+
*/
62+
public static RefundClient getInstance(
63+
BitPayClient bitPayClient,
64+
TokenContainer accessTokens,
65+
GuidGenerator guidGenerator
66+
) {
67+
if (Objects.isNull(instance)) {
68+
instance = new RefundClient(bitPayClient, accessTokens, guidGenerator);
69+
}
70+
71+
return instance;
72+
}
73+
5374
/**
5475
* Create a refund for a BitPay invoice.
5576
*
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.bitpay.sdk.client;
2+
3+
public interface ResourceClient {
4+
}

0 commit comments

Comments
 (0)