Skip to content

Commit 2cd87f6

Browse files
author
Steve Crow
committed
Missing code snippits.
1 parent 07676d9 commit 2cd87f6

File tree

12 files changed

+497
-5
lines changed

12 files changed

+497
-5
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ repositories {
1515
dependencies {
1616
testCompile 'junit:junit:4.12'
1717

18-
compile 'com.nexmo:client:5.0.0'
18+
compile 'com.nexmo:client:5.1.0'
1919
compile "com.sparkjava:spark-core:2.6.0"
2020
compile 'javax.xml.bind:jaxb-api:2.3.0'
2121
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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.account;
23+
24+
import com.nexmo.client.NexmoClient;
25+
import com.nexmo.client.account.AccountClient;
26+
import com.nexmo.client.account.SettingsResponse;
27+
28+
import static com.nexmo.quickstart.Util.envVar;
29+
30+
public class ConfigureAccount {
31+
private static final String NEXMO_API_KEY = envVar("NEXMO_API_KEY");
32+
private static final String NEXMO_API_SECRET = envVar("NEXMO_API_SECRET");
33+
private static final String SMS_CALLBACK_URL = envVar("SMS_CALLBACK_URL");
34+
35+
public static void main(String[] args) throws Exception {
36+
NexmoClient client = NexmoClient.builder()
37+
.apiKey(NEXMO_API_KEY)
38+
.apiSecret(NEXMO_API_SECRET)
39+
.build();
40+
41+
AccountClient accountClient = client.getAccountClient();
42+
43+
SettingsResponse response = accountClient.updateSmsIncomingUrl(SMS_CALLBACK_URL);
44+
System.out.println("SMS Callback URL is now " + response.getIncomingSmsUrl());
45+
}
46+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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.account;
23+
24+
import com.nexmo.client.NexmoClient;
25+
import com.nexmo.client.account.AccountClient;
26+
import com.nexmo.client.account.SecretResponse;
27+
28+
import static com.nexmo.quickstart.Util.envVar;
29+
30+
public class CreateSecret {
31+
private static final String NEXMO_API_KEY = envVar("NEXMO_API_KEY");
32+
private static final String NEXMO_API_SECRET = envVar("NEXMO_API_SECRET");
33+
private static final String NEW_SECRET = envVar("NEW_SECRET");
34+
35+
public static void main(String[] args) {
36+
NexmoClient client = NexmoClient.builder()
37+
.apiKey(NEXMO_API_KEY)
38+
.apiSecret(NEXMO_API_SECRET)
39+
.build();
40+
41+
AccountClient accountClient = client.getAccountClient();
42+
43+
SecretResponse response = accountClient.createSecret(NEXMO_API_KEY, NEW_SECRET);
44+
System.out.println(response.getId() + " created at " + response.getCreated());
45+
}
46+
}

src/main/java/com/nexmo/quickstart/account/GetBalance.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,24 @@
2222
package com.nexmo.quickstart.account;
2323

2424
import com.nexmo.client.NexmoClient;
25+
import com.nexmo.client.account.AccountClient;
2526
import com.nexmo.client.account.BalanceResponse;
2627

2728
import static com.nexmo.quickstart.Util.envVar;
2829

2930
public class GetBalance {
31+
private static final String NEXMO_API_KEY = envVar("NEXMO_API_KEY");
32+
private static final String NEXMO_API_SECRET = envVar("NEXMO_API_SECRET");
3033

3134
public static void main(String[] args) throws Exception {
32-
String NEXMO_API_KEY = envVar("NEXMO_API_KEY");
33-
String NEXMO_API_SECRET = envVar("NEXMO_API_SECRET");
35+
NexmoClient client = NexmoClient.builder()
36+
.apiKey(NEXMO_API_KEY)
37+
.apiSecret(NEXMO_API_SECRET)
38+
.build();
3439

35-
NexmoClient client = NexmoClient.builder().apiKey(NEXMO_API_KEY).apiSecret(NEXMO_API_SECRET).build();
40+
AccountClient accountClient = client.getAccountClient();
3641

37-
BalanceResponse response = client.getAccountClient().getBalance();
42+
BalanceResponse response = accountClient.getBalance();
3843
System.out.printf("Balance: %s EUR\n", response.getValue());
3944
System.out.printf("Auto-reload Enabled: %s\n", response.isAutoReload());
4045
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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.account;
23+
24+
import com.nexmo.client.NexmoClient;
25+
import com.nexmo.client.account.AccountClient;
26+
import com.nexmo.client.account.SecretResponse;
27+
28+
import static com.nexmo.quickstart.Util.envVar;
29+
30+
public class GetSecret {
31+
private static final String NEXMO_API_KEY = envVar("NEXMO_API_KEY");
32+
private static final String NEXMO_API_SECRET = envVar("NEXMO_API_SECRET");
33+
private static final String NEXMO_SECRET_ID = envVar("NEXMO_SECRET_ID");
34+
35+
public static void main(String[] args) {
36+
NexmoClient client = NexmoClient.builder()
37+
.apiKey(NEXMO_API_KEY)
38+
.apiSecret(NEXMO_API_SECRET)
39+
.build();
40+
41+
AccountClient accountClient = client.getAccountClient();
42+
43+
SecretResponse response = accountClient.getSecret(NEXMO_API_KEY, NEXMO_SECRET_ID);
44+
System.out.println(response.getId() + " created at " + response.getCreated());
45+
}
46+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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.account;
23+
24+
import com.nexmo.client.NexmoClient;
25+
import com.nexmo.client.account.AccountClient;
26+
import com.nexmo.client.account.ListSecretsResponse;
27+
28+
import static com.nexmo.quickstart.Util.envVar;
29+
30+
public class ListSecrets {
31+
private static final String NEXMO_API_KEY = envVar("NEXMO_API_KEY");
32+
private static final String NEXMO_API_SECRET = envVar("NEXMO_API_SECRET");
33+
34+
public static void main(String[] args) {
35+
NexmoClient client = NexmoClient.builder()
36+
.apiKey(NEXMO_API_KEY)
37+
.apiSecret(NEXMO_API_SECRET)
38+
.build();
39+
40+
AccountClient accountClient = client.getAccountClient();
41+
42+
ListSecretsResponse response = accountClient.listSecrets(NEXMO_API_KEY);
43+
response.getSecrets().forEach(
44+
it -> System.out.println(it.getId() + " created at " + it.getCreated())
45+
);
46+
}
47+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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.account;
23+
24+
import com.nexmo.client.NexmoClient;
25+
import com.nexmo.client.account.AccountClient;
26+
27+
import static com.nexmo.quickstart.Util.envVar;
28+
29+
public class RevokeSecret {
30+
private static final String NEXMO_API_KEY = envVar("NEXMO_API_KEY");
31+
private static final String NEXMO_API_SECRET = envVar("NEXMO_API_SECRET");
32+
private static final String NEXMO_SECRET_ID = envVar("NEXMO_SECRET_ID");
33+
34+
public static void main(String[] args) throws Exception {
35+
NexmoClient client = NexmoClient.builder()
36+
.apiKey(NEXMO_API_KEY)
37+
.apiSecret(NEXMO_API_SECRET)
38+
.build();
39+
40+
AccountClient accountClient = client.getAccountClient();
41+
42+
accountClient.revokeSecret(NEXMO_API_KEY, NEXMO_SECRET_ID);
43+
}
44+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2011-2019 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.insight;
23+
24+
import com.nexmo.client.NexmoClient;
25+
import com.nexmo.client.insight.AdvancedInsightRequest;
26+
import com.nexmo.client.insight.InsightClient;
27+
28+
import static com.nexmo.quickstart.Util.envVar;
29+
30+
public class AdvancedInsightAsync {
31+
private static final String NEXMO_API_KEY = envVar("NEXMO_API_KEY");
32+
private static final String NEXMO_API_SECRET = envVar("NEXMO_API_SECRET");
33+
private static final String INSIGHT_NUMBER = envVar("INSIGHT_NUMBER");
34+
private static final String ASYNC_CALLBACK_URL = envVar("ASYNC_CALLBACK_URL");
35+
36+
public static void main(String... args) {
37+
NexmoClient client = NexmoClient.builder()
38+
.apiKey(NEXMO_API_KEY)
39+
.apiSecret(NEXMO_API_SECRET)
40+
.build();
41+
42+
InsightClient insightClient = client.getInsightClient();
43+
44+
AdvancedInsightRequest request = AdvancedInsightRequest.builder(INSIGHT_NUMBER)
45+
.async(true)
46+
.callback(ASYNC_CALLBACK_URL)
47+
.build();
48+
insightClient.getAdvancedNumberInsight(request);
49+
}
50+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2011-2019 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.insight;
23+
24+
import com.nexmo.client.insight.AdvancedInsightResponse;
25+
import spark.Spark;
26+
27+
import static spark.Spark.port;
28+
29+
public class AsyncInsightTrigger {
30+
public static void main(String... args) {
31+
port(3000);
32+
Spark.post("/webhooks/insight", (req, res) -> {
33+
AdvancedInsightResponse response = AdvancedInsightResponse.fromJson(req.body());
34+
System.out.println("Country: " + response.getCountryName());
35+
36+
res.status(204);
37+
return "";
38+
});
39+
}
40+
}

0 commit comments

Comments
 (0)