-
Notifications
You must be signed in to change notification settings - Fork 434
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into voice-v2-fix
- Loading branch information
Showing
6 changed files
with
623 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,261 @@ | ||
/* | ||
* This code was generated by | ||
* ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ | ||
* | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ | ||
* | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ | ||
* | ||
* Twilio API definition for public-api voice | ||
* Powers Twilio public-api voice | ||
* | ||
* NOTE: This class is auto generated by OpenAPI Generator. | ||
* https://openapi-generator.tech | ||
* Do not edit the class manually. | ||
*/ | ||
|
||
package com.twilio.rest.voice.v2; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.core.JsonParseException; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.JsonMappingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.twilio.base.Resource; | ||
import com.twilio.exception.ApiConnectionException; | ||
import com.twilio.exception.ApiException; | ||
import com.twilio.http.HttpMethod; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.URI; | ||
import java.util.Objects; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
import lombok.ToString; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
@ToString | ||
public class Client extends Resource { | ||
|
||
private static final long serialVersionUID = 20407420146524L; | ||
|
||
@ToString | ||
public static class VoiceV2ClientConfigurationResponseConfigurationCallnotification { | ||
|
||
@JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
@JsonProperty("url") | ||
@Getter | ||
@Setter | ||
private URI url; | ||
|
||
@JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
@JsonProperty("method") | ||
@Getter | ||
@Setter | ||
private HttpMethod method; | ||
|
||
public static VoiceV2ClientConfigurationResponseConfigurationCallnotification fromJson( | ||
String jsonString, | ||
ObjectMapper mapper | ||
) throws IOException { | ||
return mapper.readValue( | ||
jsonString, | ||
VoiceV2ClientConfigurationResponseConfigurationCallnotification.class | ||
); | ||
} | ||
} | ||
|
||
@ToString | ||
public static class VoiceV2ClientConfigurationResponseConfiguration { | ||
|
||
@JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
@JsonProperty("callnotification") | ||
@Getter | ||
@Setter | ||
private VoiceV2ClientConfigurationResponseConfigurationCallnotification callnotification; | ||
|
||
public static VoiceV2ClientConfigurationResponseConfiguration fromJson( | ||
String jsonString, | ||
ObjectMapper mapper | ||
) throws IOException { | ||
return mapper.readValue( | ||
jsonString, | ||
VoiceV2ClientConfigurationResponseConfiguration.class | ||
); | ||
} | ||
} | ||
|
||
@ToString | ||
public static class VoiceV2ClientConfigurationRequest { | ||
|
||
@JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
@JsonProperty("friendly_name") | ||
@Getter | ||
@Setter | ||
private String friendlyName; | ||
|
||
@JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
@JsonProperty("description") | ||
@Getter | ||
@Setter | ||
private String description; | ||
|
||
@JsonInclude(JsonInclude.Include.NON_EMPTY) | ||
@JsonProperty("configuration") | ||
@Getter | ||
@Setter | ||
private VoiceV2ClientConfigurationResponseConfiguration configuration; | ||
|
||
public VoiceV2ClientConfigurationRequest() {} | ||
|
||
public static VoiceV2ClientConfigurationRequest fromJson( | ||
String jsonString, | ||
ObjectMapper mapper | ||
) throws IOException { | ||
return mapper.readValue( | ||
jsonString, | ||
VoiceV2ClientConfigurationRequest.class | ||
); | ||
} | ||
} | ||
|
||
public static ClientCreator creator() { | ||
return new ClientCreator(); | ||
} | ||
|
||
public static ClientDeleter deleter(final String pathIdOrFriendlyName) { | ||
return new ClientDeleter(pathIdOrFriendlyName); | ||
} | ||
|
||
/** | ||
* Converts a JSON String into a Client object using the provided ObjectMapper. | ||
* | ||
* @param json Raw JSON String | ||
* @param objectMapper Jackson ObjectMapper | ||
* @return Client object represented by the provided JSON | ||
*/ | ||
public static Client fromJson( | ||
final String json, | ||
final ObjectMapper objectMapper | ||
) { | ||
// Convert all checked exceptions to Runtime | ||
try { | ||
return objectMapper.readValue(json, Client.class); | ||
} catch (final JsonMappingException | JsonParseException e) { | ||
throw new ApiException(e.getMessage(), e); | ||
} catch (final IOException e) { | ||
throw new ApiConnectionException(e.getMessage(), e); | ||
} | ||
} | ||
|
||
/** | ||
* Converts a JSON InputStream into a Client object using the provided | ||
* ObjectMapper. | ||
* | ||
* @param json Raw JSON InputStream | ||
* @param objectMapper Jackson ObjectMapper | ||
* @return Client object represented by the provided JSON | ||
*/ | ||
public static Client fromJson( | ||
final InputStream json, | ||
final ObjectMapper objectMapper | ||
) { | ||
// Convert all checked exceptions to Runtime | ||
try { | ||
return objectMapper.readValue(json, Client.class); | ||
} catch (final JsonMappingException | JsonParseException e) { | ||
throw new ApiException(e.getMessage(), e); | ||
} catch (final IOException e) { | ||
throw new ApiConnectionException(e.getMessage(), e); | ||
} | ||
} | ||
|
||
public static String toJson(Object object, ObjectMapper mapper) { | ||
try { | ||
return mapper.writeValueAsString(object); | ||
} catch (final JsonMappingException e) { | ||
throw new ApiException(e.getMessage(), e); | ||
} catch (JsonProcessingException e) { | ||
throw new ApiException(e.getMessage(), e); | ||
} catch (final IOException e) { | ||
throw new ApiConnectionException(e.getMessage(), e); | ||
} | ||
} | ||
|
||
private final String id; | ||
private final String accountSid; | ||
private final String friendlyName; | ||
private final String description; | ||
private final VoiceV2ClientConfigurationResponseConfiguration configuration; | ||
|
||
@JsonCreator | ||
private Client( | ||
@JsonProperty("id") final String id, | ||
@JsonProperty("account_sid") final String accountSid, | ||
@JsonProperty("friendly_name") final String friendlyName, | ||
@JsonProperty("description") final String description, | ||
@JsonProperty( | ||
"configuration" | ||
) final VoiceV2ClientConfigurationResponseConfiguration configuration | ||
) { | ||
this.id = id; | ||
this.accountSid = accountSid; | ||
this.friendlyName = friendlyName; | ||
this.description = description; | ||
this.configuration = configuration; | ||
} | ||
|
||
public final String getId() { | ||
return this.id; | ||
} | ||
|
||
public final String getAccountSid() { | ||
return this.accountSid; | ||
} | ||
|
||
public final String getFriendlyName() { | ||
return this.friendlyName; | ||
} | ||
|
||
public final String getDescription() { | ||
return this.description; | ||
} | ||
|
||
public final VoiceV2ClientConfigurationResponseConfiguration getConfiguration() { | ||
return this.configuration; | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
|
||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
|
||
Client other = (Client) o; | ||
|
||
return ( | ||
Objects.equals(id, other.id) && | ||
Objects.equals(accountSid, other.accountSid) && | ||
Objects.equals(friendlyName, other.friendlyName) && | ||
Objects.equals(description, other.description) && | ||
Objects.equals(configuration, other.configuration) | ||
); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash( | ||
id, | ||
accountSid, | ||
friendlyName, | ||
description, | ||
configuration | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* This code was generated by | ||
* ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ | ||
* | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ | ||
* | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ | ||
* | ||
* Twilio API definition for public-api voice | ||
* Powers Twilio public-api voice | ||
* | ||
* NOTE: This class is auto generated by OpenAPI Generator. | ||
* https://openapi-generator.tech | ||
* Do not edit the class manually. | ||
*/ | ||
|
||
package com.twilio.rest.voice.v2; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.twilio.base.Creator; | ||
import com.twilio.constant.EnumConstants; | ||
import com.twilio.exception.ApiConnectionException; | ||
import com.twilio.exception.ApiException; | ||
import com.twilio.exception.RestException; | ||
import com.twilio.http.HttpMethod; | ||
import com.twilio.http.Request; | ||
import com.twilio.http.Response; | ||
import com.twilio.http.TwilioRestClient; | ||
import com.twilio.rest.Domains; | ||
|
||
public class ClientCreator extends Creator<Client> { | ||
|
||
private Client.VoiceV2ClientConfigurationRequest voiceV2ClientConfigurationRequest; | ||
|
||
public ClientCreator() {} | ||
|
||
public ClientCreator setVoiceV2ClientConfigurationRequest( | ||
final Client.VoiceV2ClientConfigurationRequest voiceV2ClientConfigurationRequest | ||
) { | ||
this.voiceV2ClientConfigurationRequest = | ||
voiceV2ClientConfigurationRequest; | ||
return this; | ||
} | ||
|
||
@Override | ||
public Client create(final TwilioRestClient client) { | ||
String path = "/v2/Configurations/Client"; | ||
|
||
Request request = new Request( | ||
HttpMethod.POST, | ||
Domains.VOICE.toString(), | ||
path | ||
); | ||
request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); | ||
addPostParams(request, client); | ||
Response response = client.request(request); | ||
if (response == null) { | ||
throw new ApiConnectionException( | ||
"Client creation failed: Unable to connect to server" | ||
); | ||
} else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { | ||
RestException restException = RestException.fromJson( | ||
response.getStream(), | ||
client.getObjectMapper() | ||
); | ||
if (restException == null) { | ||
throw new ApiException( | ||
"Server Error, no content", | ||
response.getStatusCode() | ||
); | ||
} | ||
throw new ApiException(restException); | ||
} | ||
|
||
return Client.fromJson(response.getStream(), client.getObjectMapper()); | ||
} | ||
|
||
private void addPostParams(final Request request, TwilioRestClient client) { | ||
ObjectMapper objectMapper = client.getObjectMapper(); | ||
if (voiceV2ClientConfigurationRequest != null) { | ||
request.setBody( | ||
Client.toJson(voiceV2ClientConfigurationRequest, objectMapper) | ||
); | ||
} | ||
} | ||
} |
Oops, something went wrong.