Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adding organization domain spec file in examples to fix java test failure #590

Merged
merged 6 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/java/src/main/java/com/twilio/Domains.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ public enum Domains {
API("api"),
FLEXAPI("flex-api"),
VERSIONLESS("versionless"),
MESSAGING("messaging");
MESSAGING("messaging"),
PREVIEWIAM("preview-iam");

private final String value;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
/*
* This code was generated by
* ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
* | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
* | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
*
* Organization Public API
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* NOTE: This class is auto generated by OpenAPI Generator.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

package com.twilio.rest.previewiam.organizations;

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.noauth.Resource;
import com.twilio.converter.Converter;
import java.util.Currency;
import com.twilio.converter.DateConverter;
import com.twilio.converter.Promoter;
import com.twilio.converter.PrefixedCollapsibleMap;
import com.twilio.converter.CurrencyDeserializer;
import com.twilio.exception.ApiConnectionException;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

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;

import lombok.ToString;

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.time.ZonedDateTime;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.Map;
import java.time.LocalDate;
import java.math.BigDecimal;
import com.twilio.type.PhoneNumberCapabilities;
import com.twilio.type.FeedbackIssue;
import com.twilio.type.IceServer;
import com.twilio.type.InboundCallPrice;
import com.twilio.type.OutboundPrefixPriceWithOrigin;
import com.twilio.type.OutboundPrefixPrice;
import com.twilio.type.OutboundCallPriceWithOrigin;
import com.twilio.type.PhoneNumberPrice;
import com.twilio.type.InboundSmsPrice;
import com.twilio.type.OutboundSmsPrice;
import com.twilio.type.OutboundCallPrice;
import com.twilio.type.RecordingRule;
import com.twilio.type.SubscribeRule;

@JsonIgnoreProperties(ignoreUnknown = true)
@ToString
public class Token extends Resource {
private static final long serialVersionUID = 258139119277894L;



public static TokenCreator creator(final String grantType, final String clientId){
return new TokenCreator(grantType, clientId);
}

/**
* Converts a JSON String into a Token object using the provided ObjectMapper.
*
* @param json Raw JSON String
* @param objectMapper Jackson ObjectMapper
* @return Token object represented by the provided JSON
*/
public static Token fromJson(final String json, final ObjectMapper objectMapper) {
// Convert all checked exceptions to Runtime
try {
return objectMapper.readValue(json, Token.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 Token object using the provided
* ObjectMapper.
*
* @param json Raw JSON InputStream
* @param objectMapper Jackson ObjectMapper
* @return Token object represented by the provided JSON
*/
public static Token fromJson(final InputStream json, final ObjectMapper objectMapper) {
// Convert all checked exceptions to Runtime
try {
return objectMapper.readValue(json, Token.class);
} catch (final JsonMappingException | JsonParseException e) {
throw new ApiException(e.getMessage(), e);
} catch (final IOException e) {
throw new ApiConnectionException(e.getMessage(), e);
}
}

private final String accessToken;
private final String refreshToken;
private final String idToken;
private final String tokenType;
private final Long expiresIn;

@JsonCreator
private Token(
@JsonProperty("access_token")
final String accessToken,

@JsonProperty("refresh_token")
final String refreshToken,

@JsonProperty("id_token")
final String idToken,

@JsonProperty("token_type")
final String tokenType,

@JsonProperty("expires_in")
final Long expiresIn
) {
this.accessToken = accessToken;
this.refreshToken = refreshToken;
this.idToken = idToken;
this.tokenType = tokenType;
this.expiresIn = expiresIn;
}

public final String getAccessToken() {
return this.accessToken;
}
public final String getRefreshToken() {
return this.refreshToken;
}
public final String getIdToken() {
return this.idToken;
}
public final String getTokenType() {
return this.tokenType;
}
public final Long getExpiresIn() {
return this.expiresIn;
}

@Override
public boolean equals(final Object o) {
if (this==o) {
return true;
}

if (o == null || getClass() != o.getClass()) {
return false;
}

Token other = (Token) o;

return Objects.equals(accessToken, other.accessToken) && Objects.equals(refreshToken, other.refreshToken) && Objects.equals(idToken, other.idToken) && Objects.equals(tokenType, other.tokenType) && Objects.equals(expiresIn, other.expiresIn) ;
}

@Override
public int hashCode() {
return Objects.hash(accessToken, refreshToken, idToken, tokenType, expiresIn);
}


}

Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/*
* This code was generated by
* ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
* | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
* | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
*
* Organization Public API
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* NOTE: This class is auto generated by OpenAPI Generator.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

package com.twilio.rest.previewiam.organizations;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.twilio.constant.EnumConstants;
import com.twilio.converter.Promoter;
import com.twilio.exception.ApiConnectionException;
import com.twilio.converter.PrefixedCollapsibleMap;
import com.twilio.converter.Converter;
import com.twilio.exception.ApiException;
import com.twilio.exception.RestException;
import com.twilio.http.HttpMethod;
import com.twilio.http.Response;
import com.twilio.rest.Domains;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.time.LocalDate;
import com.twilio.converter.Converter;
import java.time.ZonedDateTime;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.net.URI;
import java.time.format.DateTimeFormatter;
import com.twilio.converter.DateConverter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;

import lombok.ToString;

import java.net.URI;

import com.twilio.base.noauth.Creator;
import com.twilio.http.noauth.NoAuthRequest;
import com.twilio.http.noauth.NoAuthTwilioRestClient;

public class TokenCreator extends Creator<Token>{
private String grantType;
private String clientId;
private String clientSecret;
private String code;
private String redirectUri;
private String audience;
private String refreshToken;
private String scope;

public TokenCreator(final String grantType, final String clientId) {
this.grantType = grantType;
this.clientId = clientId;
}

public TokenCreator setGrantType(final String grantType){
this.grantType = grantType;
return this;
}
public TokenCreator setClientId(final String clientId){
this.clientId = clientId;
return this;
}
public TokenCreator setClientSecret(final String clientSecret){
this.clientSecret = clientSecret;
return this;
}
public TokenCreator setCode(final String code){
this.code = code;
return this;
}
public TokenCreator setRedirectUri(final String redirectUri){
this.redirectUri = redirectUri;
return this;
}
public TokenCreator setAudience(final String audience){
this.audience = audience;
return this;
}
public TokenCreator setRefreshToken(final String refreshToken){
this.refreshToken = refreshToken;
return this;
}
public TokenCreator setScope(final String scope){
this.scope = scope;
return this;
}

@Override
public Token create(final NoAuthTwilioRestClient client){
String path = "/v1/token";

path = path.replace("{"+"grant_type"+"}", this.grantType.toString());
path = path.replace("{"+"client_id"+"}", this.clientId.toString());

NoAuthRequest request = new NoAuthRequest(
HttpMethod.POST,
Domains.PREVIEWIAM.toString(),
path
);
request.setContentType(EnumConstants.ContentType.FORM_URLENCODED);
addPostParams(request);
Response response = client.request(request);
if (response == null) {
throw new ApiConnectionException("Token creation failed: Unable to connect to server");
} else if (!NoAuthTwilioRestClient.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 Token.fromJson(response.getStream(), client.getObjectMapper());
}
private void addPostParams(final NoAuthRequest request) {
if (grantType != null) {
request.addPostParam("grant_type", grantType);

}
if (clientId != null) {
request.addPostParam("client_id", clientId);

}
if (clientSecret != null) {
request.addPostParam("client_secret", clientSecret);

}
if (code != null) {
request.addPostParam("code", code);

}
if (redirectUri != null) {
request.addPostParam("redirect_uri", redirectUri);

}
if (audience != null) {
request.addPostParam("audience", audience);

}
if (refreshToken != null) {
request.addPostParam("refresh_token", refreshToken);

}
if (scope != null) {
request.addPostParam("scope", scope);

}
}
}
Loading
Loading