11package org .restcomm .sdk ;
22
3- import java .util .HashMap ;
3+ import java .util .Collections ;
44import java .util .Map ;
55
66import org .restcomm .sdk .domain .Account ;
@@ -22,24 +22,22 @@ public class RestcommClient {
2222
2323 private final HttpClient httpClient ;
2424
25- protected final String baseRestcommUrl ;
26- protected final String baseRestcommUrlWithoutAccount ;
25+ private final String baseRestcommUrlWithoutAccount ;
2726
28- protected final String baseUrl ;
27+ private final String baseUrl ;
2928 private final String accountSid ;
3029
31- protected final Map <String , String > endpoints ;
30+ private final Map <String , String > endpoints ;
3231
3332 public RestcommClient (RestcommClientConfiguration config ) {
3433 this .httpClient = new HttpClient (config .getAccountSid (), config .getAccountToken ());
3534
3635 this .baseUrl = config .getBaseUrl ();
3736 this .baseRestcommUrlWithoutAccount = baseUrl + "/restcomm/2012-04-24/Accounts" ;
38- this .baseRestcommUrl = baseUrl + "/restcomm/2012-04-24/Accounts/" + config .getAccountSid ();
3937 if (config .getEndpoints () != null )
4038 this .endpoints = config .getEndpoints ();
4139 else
42- this .endpoints = new HashMap < String , String > ();
40+ this .endpoints = Collections . emptyMap ();
4341 this .accountSid = config .getAccountSid ();
4442 }
4543
@@ -48,70 +46,98 @@ public String getAccountSid() {
4846 }
4947
5048 public RestEndpoints <CallPage > getCallsEndpoint () {
51- return getEndpoints ("calls" , baseRestcommUrl + "/Calls.json" , CallPage . class );
49+ return getCallsEndpoint ("calls" , this . accountSid );
5250 }
5351
5452 public RestEndpoints <CallPage > getCallsEndpoint (String accountSid ) {
55- return getEndpoints ("calls" , baseRestcommUrlWithoutAccount + "/" + accountSid + "/Calls.json" , CallPage .class );
53+ return getCallsEndpoint ("calls-" + accountSid , accountSid );
54+ }
55+
56+ private RestEndpoints <CallPage > getCallsEndpoint (String endpoint , String accountSid ) {
57+ return getEndpoints (endpoint , baseRestcommUrlWithoutAccount + "/" + accountSid + "/Calls.json" , CallPage .class );
5658 }
5759
5860 public RestEndpoints <RecordingPage > getRecordingsEndpoint () {
59- return getEndpoints ("recordings" , baseRestcommUrl + "/Recordings.json" , RecordingPage . class );
61+ return getRecordingsEndpoint ("recordings" , this . accountSid );
6062 }
6163
6264 public RestEndpoints <RecordingPage > getRecordingsEndpoint (String accountSid ) {
63- return getEndpoints ("recordings" , baseRestcommUrlWithoutAccount + "/" + accountSid + "/Recordings.json" ,
65+ return getRecordingsEndpoint ("recordings-" + accountSid , accountSid );
66+ }
67+
68+ private RestEndpoints <RecordingPage > getRecordingsEndpoint (String endpoint , String accountSid ) {
69+ return getEndpoints (endpoint , baseRestcommUrlWithoutAccount + "/" + accountSid + "/Recordings.json" ,
6470 RecordingPage .class );
6571 }
6672
6773 public RestEndpoints <Client > getClientsEndpoints () {
68- return getEndpoints ("clients" , baseRestcommUrl + "/Clients.json" , Client .class );
74+ return getClientsEndpoints ("clients" , this .accountSid );
75+ }
76+
77+ public RestEndpoints <Client > getClientsEndpoints (String accountSid ) {
78+ return getClientsEndpoints ("clients-" + accountSid , accountSid );
79+ }
80+
81+ private RestEndpoints <Client > getClientsEndpoints (String endpoint , String accountSid ) {
82+ return getEndpoints (endpoint , baseRestcommUrlWithoutAccount + "/" + accountSid + "/Clients.json" , Client .class );
6983 }
7084
7185 public RestEndpoints <Account > getAccountsEndpoints () {
7286 return getEndpoints ("accounts" , baseRestcommUrlWithoutAccount + ".json" , Account .class );
7387 }
7488
7589 public RestEndpoints <Account > getAccountsEndpoints (String accountSid ) {
76- return getEndpoints ("accounts" , baseRestcommUrlWithoutAccount + ".json/" + accountSid , Account .class );
90+ return getEndpoints ("accounts-" + accountSid , baseRestcommUrlWithoutAccount + ".json/" + accountSid , Account .class );
7791 }
7892
7993 public RestEndpoints <Application > getApplicationsEndpoints () {
80- return getEndpoints ("applications" , baseRestcommUrl + "/Applications.json" , Application . class );
94+ return getApplicationsEndpoints ("applications" , this . accountSid );
8195 }
8296
8397 public RestEndpoints <Application > getApplicationsEndpoints (String accountSid ) {
84- return getEndpoints ("applications" , baseRestcommUrlWithoutAccount + "/" + accountSid + "/Applications.json" ,
98+ return getApplicationsEndpoints ("applications-" + accountSid , accountSid );
99+ }
100+
101+ private RestEndpoints <Application > getApplicationsEndpoints (String endpoint , String accountSid ) {
102+ return getEndpoints (endpoint , baseRestcommUrlWithoutAccount + "/" + accountSid + "/Applications.json" ,
85103 Application .class );
86104 }
87105
88106 public RestEndpoints <IncomingPhoneNumber > getIncomingPhoneNumbersEndpoints () {
89- return getEndpoints ("incoming-phone-numbers" , baseRestcommUrl + "/IncomingPhoneNumbers.json" , IncomingPhoneNumber . class );
107+ return getIncomingPhoneNumbersEndpoints ("incoming-phone-numbers" , this . accountSid );
90108 }
91109
92110 public RestEndpoints <IncomingPhoneNumber > getIncomingPhoneNumbersEndpoints (String accountSid ) {
93- return getEndpoints ("incoming-phone-numbers" , baseRestcommUrlWithoutAccount + "/" + accountSid
94- + "/IncomingPhoneNumbers.json" , IncomingPhoneNumber .class );
111+ return getIncomingPhoneNumbersEndpoints ("incoming-phone-numbers-" + accountSid , accountSid );
112+ }
113+
114+ private RestEndpoints <IncomingPhoneNumber > getIncomingPhoneNumbersEndpoints (String endpoint , String accountSid ) {
115+ return getEndpoints (endpoint , baseRestcommUrlWithoutAccount + "/" + accountSid + "/IncomingPhoneNumbers.json" ,
116+ IncomingPhoneNumber .class );
95117 }
96118
97119 public RestEndpoints <XmppMapping > getXmppMappingsEndpoints () {
98120 return getEndpoints ("xmpp-mappings" , baseUrl + "/xmpp/xmppMappings" , XmppMapping .class );
99121 }
100122
101123 public RestEndpoints <ShortMessage > getShortMessagesEndpoints () {
102- return getEndpoints ("messages" , baseRestcommUrl + "/SMS/Messages.json" , ShortMessage . class );
124+ return getShortMessagesEndpoints ("messages" , this . accountSid );
103125 }
104126
105127 public RestEndpoints <ShortMessage > getShortMessagesEndpoints (String accountSid ) {
106- return getEndpoints ("messages" , baseRestcommUrlWithoutAccount + "/" + accountSid + "/SMS/Messages.json" ,
128+ return getShortMessagesEndpoints ("messages-" + accountSid , accountSid );
129+ }
130+
131+ private RestEndpoints <ShortMessage > getShortMessagesEndpoints (String endpoint , String accountSid ) {
132+ return getEndpoints (endpoint , baseRestcommUrlWithoutAccount + "/" + accountSid + "/SMS/Messages.json" ,
107133 ShortMessage .class );
108134 }
109135
110136 public RestEndpoints <ExtensionData > getExtensions () {
111137 return getEndpoints ("extensions" , baseUrl + "/restcomm/2012-04-24/ExtensionsConfiguration.json" , ExtensionData .class );
112138 }
113139
114- protected <T > RestEndpoints <T > getEndpoints (String endpoint , String defaultUrl , Class <T > type ) {
140+ private <T > RestEndpoints <T > getEndpoints (String endpoint , String defaultUrl , Class <T > type ) {
115141 String url = endpoints .getOrDefault (endpoint , defaultUrl );
116142 return new RestEndpoints (url , httpClient , type );
117143 }
0 commit comments