Skip to content

Commit 07676d9

Browse files
author
Steve Crow
committed
Add update number example.
1 parent 3b4ccd0 commit 07676d9

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright (c) 2011-2017 Nexmo Inc
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*/
22+
package com.nexmo.quickstart.numbers;
23+
24+
import com.nexmo.client.NexmoClient;
25+
import com.nexmo.client.NexmoClientException;
26+
import com.nexmo.client.NexmoResponseParseException;
27+
import com.nexmo.client.numbers.NumbersClient;
28+
import com.nexmo.client.numbers.UpdateNumberRequest;
29+
30+
import static com.nexmo.quickstart.Util.configureLogging;
31+
import static com.nexmo.quickstart.Util.envVar;
32+
33+
public class UpdateNumber {
34+
private static final String NEXMO_API_KEY = envVar("NEXMO_API_KEY");
35+
private static final String NEXMO_API_SECRET = envVar("NEXMO_API_SECRET");
36+
private static final String COUNTRY_CODE = envVar("COUNTRY_CODE");
37+
private static final String NEXMO_NUMBER = envVar("NEXMO_NUMBER");
38+
private static final String SMS_CALLBACK_URL = envVar("SMS_CALLBACK_URL");
39+
private static final UpdateNumberRequest.CallbackType VOICE_CALLBACK_TYPE = UpdateNumberRequest.CallbackType.valueOf(envVar("VOICE_CALLBACK_TYPE"));
40+
private static final String VOICE_CALLBACK_VALUE = envVar("VOICE_CALLBACK_VALUE");
41+
private static final String VOICE_STATUS_URL = envVar("VOICE_STATUS_URL");
42+
43+
public static void main(String[] args) {
44+
configureLogging();
45+
46+
NexmoClient client = NexmoClient.builder()
47+
.apiKey(NEXMO_API_KEY)
48+
.apiSecret(NEXMO_API_SECRET)
49+
.build();
50+
51+
NumbersClient numbersClient = client.getNumbersClient();
52+
53+
UpdateNumberRequest request = new UpdateNumberRequest(NEXMO_NUMBER, COUNTRY_CODE);
54+
request.setVoiceCallbackType(VOICE_CALLBACK_TYPE);
55+
request.setVoiceCallbackValue(VOICE_CALLBACK_VALUE);
56+
request.setVoiceStatusCallback(VOICE_STATUS_URL);
57+
request.setMoHttpUrl(SMS_CALLBACK_URL);
58+
59+
try {
60+
numbersClient.updateNumber(request);
61+
} catch (NexmoClientException | NexmoResponseParseException e) {
62+
System.out.println("Error updating number.");
63+
}
64+
65+
System.out.println("Number updated.");
66+
}
67+
}

0 commit comments

Comments
 (0)