|
1 | 1 | package com.twilio.example; |
2 | 2 |
|
3 | 3 |
|
4 | | -import com.twilio.Twilio; |
5 | 4 | import com.twilio.http.TwilioRestClient; |
6 | 5 | import com.twilio.http.ValidationClient; |
7 | 6 | import com.twilio.rest.accounts.v1.credential.PublicKey; |
@@ -37,32 +36,31 @@ public static void main(String[] args) throws Exception { |
37 | 36 | TwilioRestClient client = |
38 | 37 | new TwilioRestClient.Builder(ACCOUNT_SID, AUTH_TOKEN) |
39 | 38 | .build(); |
40 | | - Twilio.setRestClient(client); |
41 | 39 |
|
42 | 40 | // Create a public key and signing key using the default client |
43 | 41 | PublicKey key = PublicKey.creator( |
44 | 42 | Base64.encodeBase64String(pk.getEncoded()) |
45 | | - ).setFriendlyName("Public Key").create(); |
46 | | - NewSigningKey signingKey = NewSigningKey.creator().create(); |
| 43 | + ).setFriendlyName("Public Key").create(client); |
| 44 | + |
| 45 | + NewSigningKey signingKey = NewSigningKey.creator().create(client); |
47 | 46 |
|
48 | 47 | // Switch to validation client as the default client |
49 | | - client = new TwilioRestClient.Builder(signingKey.getSid(), signingKey.getSecret()) |
| 48 | + TwilioRestClient validationClient = new TwilioRestClient.Builder(signingKey.getSid(), signingKey.getSecret()) |
50 | 49 | .accountSid(ACCOUNT_SID) |
51 | 50 | .httpClient(new ValidationClient(ACCOUNT_SID, key.getSid(), signingKey.getSid(), pair.getPrivate())) |
52 | 51 | .build(); |
53 | | - Twilio.setRestClient(client); |
54 | 52 |
|
55 | 53 | // Make REST API requests |
56 | | - Iterable<Message> messages = Message.reader().read(); |
| 54 | + Iterable<Message> messages = Message.reader().read(validationClient); |
57 | 55 | for (Message m : messages) { |
58 | 56 | System.out.println(m.getBody()); |
59 | 57 | } |
60 | 58 |
|
61 | 59 | Message m = Message.creator( |
62 | | - new PhoneNumber("+11234567890"), |
63 | | - new PhoneNumber("+10987654321"), |
| 60 | + new PhoneNumber("+1XXXXXXXXXX"), |
| 61 | + new PhoneNumber("+1XXXXXXXXXX"), |
64 | 62 | "Asymmetric Auth Test" |
65 | | - ).create(); |
| 63 | + ).create(validationClient); |
66 | 64 | System.out.println(m.getSid()); |
67 | 65 |
|
68 | 66 | } |
|
0 commit comments