Skip to content

Commit 648697f

Browse files
authored
Merge pull request #7 from PersephonyAPI/issue/6
Remove CallsRequester#create with callConnectUrl and statusCallbackUrl
2 parents 28616fd + 2360a31 commit 648697f

File tree

8 files changed

+19
-279
lines changed

8 files changed

+19
-279
lines changed

README.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ To include the SDK in your build, follow the instructions on [Jitpack](https://j
1313

1414
## Testing your Installation
1515

16-
Test the SDK is working by sending yourself a phone call.
16+
Test the SDK is working by sending yourself a text message.
1717

1818
```java
1919
public class Example {
@@ -26,18 +26,12 @@ public class Example {
2626
public static void main(String[] args) throws PersyException {
2727
PersyClient client = new PersyClient(accountId, authToken);
2828

29-
client.calls.create(To, From, "https://www.persephony.com/testApp/voice", (String)null);
29+
client.messages.create(From, To, "Welcome to Persephony!");
3030
}
3131
}
3232
```
3333

34-
When you run this code you should get a phone call. On answering the call, you should hear a short message ("Thanks for using Persephony!"). This indicates that you've successfully setup your SDK.
35-
36-
`https://www.persephony.com/testApp/voice` contains a small Persephony application that also uses the Persephony Java SDK. When a request is made to its `/voice` endpoint, it will respond with the following PerCL script, which produces the message you heard.
37-
38-
```json
39-
[{"Say": {"text": "Thanks for using Persephony!"}}]
40-
```
34+
When you run this code you should get a text message.
4135

4236
### Running Unit Tests
4337

src/main/java/com/vailsys/persephony/api/call/CallOptions.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
* creating a Call.
88
*
99
* @see com.vailsys.persephony.api.call.CallsRequester#create(String,String,String,CallOptions)
10-
* @see com.vailsys.persephony.api.call.CallsRequester#create(String,String,String,String,CallOptions)
1110
*/
1211
public class CallOptions extends CommonFields {
1312
/**

src/main/java/com/vailsys/persephony/api/call/CallsRequester.java

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -129,69 +129,6 @@ public Call create(String to, String from, String applicationId, CallOptions cal
129129
}
130130
}
131131

132-
/**
133-
* Create a new call through the Persephony API using an unregistered
134-
* Persephony-compatible application. This function wraps an HTTP POST
135-
* request to the Persephony API's /Account/$accountId/Calls endpoint. This
136-
* places a new call from the {@code actingAccountId} to the number
137-
* provided from the number provided.
138-
*
139-
* @param to The number to call out to (DNIS). This can be any valid phone
140-
* number formatted in E.164 format.
141-
* @param from The number to call from (ANI). This must be a number
142-
* purchase from Persephony or a verified phone number owned by the user.
143-
* @param callConnectUrl Like with a registered Persephony application,
144-
* this is the URL that Persephony makes requests to when the call
145-
* connects. See the {@code callConnectUrl} in the Persephony Application
146-
* documentation.
147-
* @param statusCallbackUrl The URL to which Persephony will report call
148-
* status notifications. See the {@code statusCallbackUrl} in the
149-
* Persephony Application documentation.
150-
*
151-
* @return The {@link com.vailsys.persephony.api.call.Call} object returned by
152-
* Persephony that represents the call that was created.
153-
* @throws PersyException when the request fails or the JSON is invalid.
154-
*/
155-
public Call create(String to, String from, String callConnectUrl, String statusCallbackUrl) throws PersyException {
156-
return this.create(to, from, callConnectUrl, statusCallbackUrl, null);
157-
}
158-
159-
/**
160-
* Create a new call through the Persephony API using an unregistered
161-
* Persephony-compatible application. This function wraps an HTTP POST
162-
* request to the Persephony API's /Account/$accountId/Calls endpoint. This
163-
* places a new call from the {@code actingAccountId} to the number
164-
* provided from the number provided.
165-
*
166-
* @param to The number to call out to (DNIS). This can be any valid phone
167-
* number formatted in E.164 format.
168-
* @param from The number to call from (ANI). This must be a number
169-
* purchase from Persephony or a verified phone number owned by the user.
170-
* @param callConnectUrl Like with a registered Persephony application,
171-
* this is the URL that Persephony makes requests to when the call
172-
* connects. See the {@code callConnectUrl} in the Persephony Application
173-
* documentation.
174-
* @param statusCallbackUrl The URL to which Persephony will report call
175-
* status notifications. See the {@code statusCallbackUrl} in the
176-
* Persephony Application documentation.
177-
* @param callOptions Optional arguments that can be provided when creating
178-
* a call. See Persephony documentation for details.
179-
*
180-
* @return The {@link com.vailsys.persephony.api.call.Call} object returned by
181-
* Persephony that represents the call that was created.
182-
*
183-
* @see com.vailsys.persephony.api.call.CallOptions
184-
* @throws PersyException when the request fails or the JSON is invalid.
185-
*/
186-
public Call create(String to, String from, String callConnectUrl, String statusCallbackUrl, CallOptions callOptions) throws PersyException {
187-
try {
188-
return Call.fromJson(this.POST(this.path, new CreateCallRequest(to, from, callConnectUrl, statusCallbackUrl, callOptions).toJson()));
189-
}
190-
catch (JsonIOException jioe) {
191-
throw new PersyJSONException(jioe);
192-
}
193-
}
194-
195132
/**
196133
* Retrieve a list of calls associated with the {@code actingAccountId}.
197134
* This wraps a HTTP GET request to the Persephony API's

src/main/java/com/vailsys/persephony/api/call/CreateCallRequest.java

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ class CreateCallRequest {
1919

2020
public String applicationId;
2121

22-
public String callConnectUrl;
23-
public String statusCallbackUrl;
24-
2522
public CallOptions options;
2623

2724
/**
@@ -37,59 +34,9 @@ class CreateCallRequest {
3734
* a call. See Persephony documentation for details.
3835
*/
3936
public CreateCallRequest(String to, String from, String applicationId, CallOptions options) {
40-
this(to, from, null, null, applicationId, options);
41-
}
42-
43-
/**
44-
* Setup a new call creation payload using an raw URLs.
45-
*
46-
* @param to The number to call out to (DNIS). This can be any valid phone
47-
* number formatted in E.164 format.
48-
* @param from The number to call from (ANI). This must be a number
49-
* purchase from Persephony or a verified phone number owned by the user.
50-
* @param callConnectUrl Like with a registered Persephony application,
51-
* this is the URL that Persephony makes requests to when the call
52-
* connects. See the {@code callConnectUrl} in the Persephony Application
53-
* documentation.
54-
* @param statusCallbackUrl The URL to which Persephony will report call
55-
* status notifications. See the {@code statusCallbackUrl} in the
56-
* Persephony Application documentation.
57-
* @param options Optional arguments that can be provided when creating
58-
* a call. See Persephony documentation for details.
59-
*/
60-
public CreateCallRequest(String to, String from, String callConnectUrl, String statusCallbackUrl, CallOptions options) {
61-
this(to, from, callConnectUrl, statusCallbackUrl, null, options);
62-
}
63-
64-
/**
65-
* Setup a new call creation payload. This is a catch all constructor that
66-
* exists to reduce code duplication but should never be used outside the
67-
* overloaded constructors for this class.
68-
*
69-
* @param to The number to call out to (DNIS). This can be any valid phone
70-
* number formatted in E.164 format.
71-
* @param from The number to call from (ANI). This must be a number
72-
* purchase from Persephony or a verified phone number owned by the user.
73-
* @param applicationId The {@code applicationId} for the registered
74-
* Persephony application which should handle this call.
75-
* @param callConnectUrl Like with a registered Persephony application,
76-
* this is the URL that Persephony makes requests to when the call
77-
* connects. See the {@code callConnectUrl} in the Persephony Application
78-
* documentation.
79-
* @param statusCallbackUrl The URL to which Persephony will report call
80-
* status notifications. See the {@code statusCallbackUrl} in the
81-
* Persephony Application documentation.
82-
* @param options Optional arguments that can be provided when creating
83-
* a call. See Persephony documentation for details.
84-
*/
85-
private CreateCallRequest(String to, String from, String callConnectUrl, String statusCallbackUrl, String applicationId, CallOptions options) {
8637
this.to = to;
8738
this.from = from;
88-
8939
this.applicationId = applicationId;
90-
91-
this.callConnectUrl = callConnectUrl;
92-
this.statusCallbackUrl = statusCallbackUrl;
9340
this.options = options;
9441
}
9542

src/test/java/com/vailsys/persephony/api/call/CallsRequesterTest.java

Lines changed: 5 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -76,48 +76,11 @@ public void placeApplicationCallWithOptions(String from, String to, String appli
7676
assertTrue(this.callsR.create(from, to, applicationId, options).equals(Call.fromJson(CallsRequesterTest.aTestCall)));
7777
}
7878

79-
@Then("^place a call from (\\+?[1-9]\\d{1,14}) to (\\+?[1-9]\\d{1,14}) using callConnectUrl$")
80-
public void placeCallConnectUrlCall(String from, String to) throws Throwable {
81-
String callConnectUrl = "http://vailsys.com/callConnect";
82-
CreateCallRequest query = new CreateCallRequest(from, to, callConnectUrl, (String)null, null);
83-
84-
Helper.getMockServer().when(
85-
request().withMethod("POST").withPath(this.callsR.getPath()).withBody(query.toJson())
86-
).respond(
87-
response().withStatusCode(200).withBody(CallsRequesterTest.aTestCall)
88-
);
89-
90-
assertTrue(this.callsR.create(from, to, callConnectUrl, (String)null).equals(Call.fromJson(CallsRequesterTest.aTestCall)));
91-
}
92-
93-
@Then("^place a call from (\\+?[1-9]\\d{1,14}) to (\\+?[1-9]\\d{1,14}) using callConnectUrl with options$")
94-
public void placeCallConnectUrlCallWithOptions(String from, String to) throws Throwable {
95-
Integer timeout = 55;
96-
String callConnectUrl = "http://vailsys.com/callConnect";
97-
79+
@Then("^place a call from (\\+?[1-9]\\d{1,14}) to (\\+?[1-9]\\d{1,14}) using application (AP[0-9A-Fa-f]{40}) with requestId (.*)$")
80+
public void placeApplicationCallWithRequestId(String from, String to, String applicationId, String requestId) throws Throwable {
9881
CallOptions options = new CallOptions();
99-
options.setTimeout(timeout);
100-
101-
CreateCallRequest query = new CreateCallRequest(to, from, callConnectUrl, (String)null, options);
102-
103-
Helper.getMockServer().when(
104-
request().withMethod("POST").withPath(this.callsR.getPath()).withBody(query.toJson())
105-
).respond(
106-
response().withStatusCode(200).withBody(CallsRequesterTest.aTestCall)
107-
);
108-
109-
assertTrue(this.callsR.create(to, from, callConnectUrl, (String)null, options).equals(Call.fromJson(CallsRequesterTest.aTestCall)));
110-
}
111-
112-
@Then("^place a call from (\\+?[1-9]\\d{1,14}) to (\\+?[1-9]\\d{1,14}) using callConnectUrl with requestId (.*)")
113-
public void placeCallConnectUrlCallWithRequestId(String from, String to, String requestId) throws Throwable {
114-
String callConnectUrl = "http://vailsys.com/callConnect";
115-
116-
CallOptions options = new CallOptions();
117-
options.setTimeout(10);
11882
options.setRequestId(requestId);
119-
120-
CreateCallRequest query = new CreateCallRequest(to, from, callConnectUrl, (String)null, options);
83+
CreateCallRequest query = new CreateCallRequest(to, from, applicationId, options);
12184

12285

12386
Helper.getMockServer().when(
@@ -126,49 +89,13 @@ public void placeCallConnectUrlCallWithRequestId(String from, String to, String
12689
response().withStatusCode(200).withBody(CallsRequesterTest.aTestCall)
12790
);
12891

129-
this.callsR.create(to, from, callConnectUrl, (String)null, options);
92+
assertTrue(this.callsR.create(to, from, applicationId, options).equals(Call.fromJson(CallsRequesterTest.aTestCall)));
13093

13194
Helper.getMockServer().verify(
132-
request().withMethod("POST").withPath(this.callsR.getPath()).withBody(new JsonBody("{from:'" + from + "',to:'" + to + "', callConnectUrl:'" + callConnectUrl + "',timeout:10,requestId:'" +requestId + "'}")),
95+
request().withMethod("POST").withPath(this.callsR.getPath()).withBody(new JsonBody("{from:'" + from + "',to:'" + to + "', applicationId:'" + applicationId + "',requestId:'" +requestId + "'}")),
13396
VerificationTimes.exactly(1)
13497
);
13598
}
136-
137-
@Then("^place a call from (\\+?[1-9]\\d{1,14}) to (\\+?[1-9]\\d{1,14}) using callConnectUrl and statusCallbackUrl$")
138-
public void placeCallConnectUrlCallWithStatusCallbackUrl(String from, String to) throws Throwable {
139-
String callConnectUrl = "http://vailsys.com/call";
140-
String statusCallbackUrl = "http://vailsys.com/status";
141-
CreateCallRequest query = new CreateCallRequest(from, to, callConnectUrl, statusCallbackUrl, null);
142-
143-
Helper.getMockServer().when(
144-
request().withMethod("POST").withPath(this.callsR.getPath()).withBody(query.toJson())
145-
).respond(
146-
response().withStatusCode(200).withBody(CallsRequesterTest.aTestCall)
147-
);
148-
149-
assertTrue(this.callsR.create(from, to, callConnectUrl, statusCallbackUrl).equals(Call.fromJson(CallsRequesterTest.aTestCall)));
150-
}
151-
152-
@Then("^place a call from (\\+?[1-9]\\d{1,14}) to (\\+?[1-9]\\d{1,14}) using callConnectUrl and statusCallbackUrl with options$")
153-
public void placeCallConnectUrlCallAndStatusCallbackUrlWithOptions(String from, String to) throws Throwable {
154-
Integer timeout = 55;
155-
String callConnectUrl = "http://vailsys.com/call";
156-
String statusCallbackUrl = "http://vailsys.com/status";
157-
158-
CallOptions options = new CallOptions();
159-
options.setTimeout(timeout);
160-
161-
CreateCallRequest query = new CreateCallRequest(from, to, callConnectUrl, statusCallbackUrl, options);
162-
163-
Helper.getMockServer().when(
164-
request().withMethod("POST").withPath(this.callsR.getPath()).withBody(query.toJson())
165-
).respond(
166-
response().withStatusCode(200).withBody(CallsRequesterTest.aTestCall)
167-
);
168-
169-
assertTrue(this.callsR.create(from, to, callConnectUrl, statusCallbackUrl, options).equals(Call.fromJson(CallsRequesterTest.aTestCall)));
170-
}
171-
17299

173100
@Then("^get a list of calls$")
174101
public void getCallsList() throws Throwable {
Lines changed: 6 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.vailsys.persephony.api.call;
22

3-
import static com.vailsys.persephony.json.PersyGson.gson;
4-
53
import cucumber.api.java.en.Given;
64
import cucumber.api.java.en.Then;
75

@@ -16,8 +14,6 @@ public class CreateCallRequestTest {
1614

1715
String applicationId = null;
1816

19-
String callConnectUrl = null;
20-
String statusCallbackUrl = null;
2117

2218
CallOptions options = null;
2319
String sendDigits = null;
@@ -26,10 +22,8 @@ public class CreateCallRequestTest {
2622

2723
CreateCallRequest request;
2824

29-
@Given("^an applicationId based CreateCallRequest without options.$")
30-
public void createWithApplicationId() {
31-
this.callConnectUrl = null;
32-
this.statusCallbackUrl = null;
25+
@Given("^a CreateCallRequest without options.$")
26+
public void create() {
3327
this.applicationId = "AP1234567890123456789012345678901234567890";
3428

3529
this.sendDigits = null;
@@ -40,24 +34,8 @@ public void createWithApplicationId() {
4034
this.request = new CreateCallRequest(this.to, this.from, this.applicationId, null);
4135
}
4236

43-
@Given("^an url based CreateCallRequest without options.$")
44-
public void createWithUrls() {
45-
this.callConnectUrl = "127.0.0.1/call";
46-
this.statusCallbackUrl = "127.0.0.1/status";
47-
this.applicationId = null;
48-
49-
this.sendDigits = null;
50-
this.ifMachine = null;
51-
this.timeout = null;
52-
this.options = null;
53-
54-
this.request = new CreateCallRequest(this.to, this.from, this.callConnectUrl, this.statusCallbackUrl, null);
55-
}
56-
57-
@Given("^an applicationId based CreateCallRequest with options.$")
58-
public void createWithApplicationIdAndOptions() {
59-
this.statusCallbackUrl = null;
60-
this.applicationId = null;
37+
@Given("^a CreateCallRequest with options.$")
38+
public void createWithOptions() {
6139
this.applicationId = "AP1234567890123456789012345678901234567890";
6240

6341
this.sendDigits = "1234";
@@ -72,44 +50,18 @@ public void createWithApplicationIdAndOptions() {
7250
this.request = new CreateCallRequest(this.to, this.from, this.applicationId, this.options);
7351
}
7452

75-
@Given("^an url based CreateCallRequest with options.$")
76-
public void createWithUrlsAndOptions() {
77-
this.callConnectUrl = "127.0.0.1/call";
78-
this.statusCallbackUrl = "127.0.0.1/status";
79-
this.applicationId = null;
80-
81-
this.sendDigits = "1234";
82-
this.ifMachine = IfMachine.HANGUP;
83-
this.timeout = 16;
84-
85-
this.options = new CallOptions();
86-
this.options.setSendDigits(this.sendDigits);
87-
this.options.setIfMachine(this.ifMachine);
88-
this.options.setTimeout(this.timeout);
89-
90-
this.request = new CreateCallRequest(this.to, this.from, this.callConnectUrl, this.statusCallbackUrl, this.options);
91-
}
92-
9353
@Then("^check that it set all fields correctly.$")
9454
public void checkToField() {
9555
assertThat(this.request.to, is(this.to));
9656
assertThat(this.request.from, is(this.from));
9757
assertThat(this.request.applicationId, is(this.applicationId));
98-
assertThat(this.request.callConnectUrl, is(this.callConnectUrl));
99-
assertThat(this.request.statusCallbackUrl, is(this.statusCallbackUrl));
10058
assertThat(this.request.options, is(this.options));
10159
}
10260

103-
@Then("^check that it can produce JSON from the applicationId based object.$")
104-
public void checkJsonAppIdNoOptions() {
61+
@Then("^check that it can produce JSON from the base object.$")
62+
public void checkJson() {
10563
String json = "{\"to\":\""+this.request.to+"\",\"from\":\""+this.request.from+"\",\"applicationId\":\""+this.request.applicationId+"\"}";
10664
assertThat(this.request.toJson(), is(json));
10765
}
10866

109-
@Then("^check that it can produce JSON from the url based object with options.$")
110-
public void checkJsonUrlWithOptions() {
111-
String json = "{\"to\":\""+this.request.to+"\",\"from\":\""+this.request.from+"\",\"callConnectUrl\":\""+this.request.callConnectUrl+"\",\"statusCallbackUrl\":\""+this.request.statusCallbackUrl+"\",\"sendDigits\":\""+this.sendDigits+"\",\"ifMachine\":\"hangup\",\"timeout\":"+this.timeout+"}";
112-
assertThat(this.request.toJson(), is(json));
113-
}
114-
11567
}

0 commit comments

Comments
 (0)