diff --git a/examples/java/src/main/java/com/twilio/Domains.java b/examples/java/src/main/java/com/twilio/Domains.java index 131c530f9..c4a2fe4b5 100644 --- a/examples/java/src/main/java/com/twilio/Domains.java +++ b/examples/java/src/main/java/com/twilio/Domains.java @@ -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; diff --git a/examples/java/src/main/java/com/twilio/rest/previewiam/organizations/Token.java b/examples/java/src/main/java/com/twilio/rest/previewiam/organizations/Token.java new file mode 100644 index 000000000..1102d5c7e --- /dev/null +++ b/examples/java/src/main/java/com/twilio/rest/previewiam/organizations/Token.java @@ -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); + } + + +} + diff --git a/examples/java/src/main/java/com/twilio/rest/previewiam/organizations/TokenCreator.java b/examples/java/src/main/java/com/twilio/rest/previewiam/organizations/TokenCreator.java new file mode 100644 index 000000000..134cd0f9c --- /dev/null +++ b/examples/java/src/main/java/com/twilio/rest/previewiam/organizations/TokenCreator.java @@ -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{ + 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); + + } + } +} diff --git a/examples/java/src/main/java/com/twilio/rest/previewiam/organizations/User.java b/examples/java/src/main/java/com/twilio/rest/previewiam/organizations/User.java new file mode 100644 index 000000000..d18a27e28 --- /dev/null +++ b/examples/java/src/main/java/com/twilio/rest/previewiam/organizations/User.java @@ -0,0 +1,382 @@ +/* + * 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.bearertoken.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 User extends Resource { + private static final long serialVersionUID = 281207691925540L; + + + @ToString + static public class ScimName { + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("givenName") + @Getter @Setter private String givenName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("familyName") + @Getter @Setter private String familyName; + + + public static ScimName fromJson(String jsonString, ObjectMapper mapper) throws IOException { + return mapper.readValue(jsonString, ScimName.class); + } + } + @ToString + static public class ScimEmailAddress { + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("primary") + @Getter @Setter private Boolean primary; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("value") + @Getter @Setter private String value; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter @Setter private String type; + + + public static ScimEmailAddress fromJson(String jsonString, ObjectMapper mapper) throws IOException { + return mapper.readValue(jsonString, ScimEmailAddress.class); + } + } + @ToString + static public class ScimMeta { + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("resourceType") + @Getter @Setter private String resourceType; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("created") + @Getter @Setter private ZonedDateTime created; + public String getCreated() { + return created.toInstant().toString(); + } + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("lastModified") + @Getter @Setter private ZonedDateTime lastModified; + public String getLastModified() { + return lastModified.toInstant().toString(); + } + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("version") + @Getter @Setter private String version; + + + public static ScimMeta fromJson(String jsonString, ObjectMapper mapper) throws IOException { + return mapper.readValue(jsonString, ScimMeta.class); + } + } + @ToString + static public class ScimUser { + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter @Setter private String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("externalId") + @Getter @Setter private String externalId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("userName") + @Getter @Setter private String userName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("displayName") + @Getter @Setter private String displayName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter @Setter private ScimName name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("emails") + @Getter @Setter private List emails; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("active") + @Getter @Setter private Boolean active; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("locale") + @Getter @Setter private String locale; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("timezone") + @Getter @Setter private String timezone; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("schemas") + @Getter @Setter private List schemas; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("meta") + @Getter @Setter private ScimMeta meta; + + public ScimUser(final String userName ) { + this.userName = userName; + } + + public static ScimUser fromJson(String jsonString, ObjectMapper mapper) throws IOException { + return mapper.readValue(jsonString, ScimUser.class); + } + } + + public static UserCreator creator(final String pathOrganizationSid, final User.ScimUser scimUser){ + return new UserCreator(pathOrganizationSid, scimUser); + } + + public static UserDeleter deleter(final String pathOrganizationSid, final String pathUserSid){ + return new UserDeleter(pathOrganizationSid, pathUserSid); + } + + public static UserFetcher fetcher(final String pathOrganizationSid, final String pathUserSid){ + return new UserFetcher(pathOrganizationSid, pathUserSid); + } + + public static UserReader reader(final String pathOrganizationSid){ + return new UserReader(pathOrganizationSid); + } + + public static UserUpdater updater(final String pathOrganizationSid, final String pathUserSid, final User.ScimUser scimUser){ + return new UserUpdater(pathOrganizationSid, pathUserSid, scimUser); + } + + /** + * Converts a JSON String into a User object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return User object represented by the provided JSON + */ + public static User fromJson(final String json, final ObjectMapper objectMapper) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, User.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 User object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return User object represented by the provided JSON + */ + public static User fromJson(final InputStream json, final ObjectMapper objectMapper) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, User.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 externalId; + private final String userName; + private final String displayName; + private final ScimName name; + private final List emails; + private final Boolean active; + private final String locale; + private final String timezone; + private final List schemas; + private final ScimMeta meta; + + @JsonCreator + private User( + @JsonProperty("id") + final String id, + + @JsonProperty("external_id") + final String externalId, + + @JsonProperty("user_name") + final String userName, + + @JsonProperty("display_name") + final String displayName, + + @JsonProperty("name") + final ScimName name, + + @JsonProperty("emails") + final List emails, + + @JsonProperty("active") + final Boolean active, + + @JsonProperty("locale") + final String locale, + + @JsonProperty("timezone") + final String timezone, + + @JsonProperty("schemas") + final List schemas, + + @JsonProperty("meta") + final ScimMeta meta + ) { + this.id = id; + this.externalId = externalId; + this.userName = userName; + this.displayName = displayName; + this.name = name; + this.emails = emails; + this.active = active; + this.locale = locale; + this.timezone = timezone; + this.schemas = schemas; + this.meta = meta; + } + + public final String getId() { + return this.id; + } + public final String getExternalId() { + return this.externalId; + } + public final String getUserName() { + return this.userName; + } + public final String getDisplayName() { + return this.displayName; + } + public final ScimName getName() { + return this.name; + } + public final List getEmails() { + return this.emails; + } + public final Boolean getActive() { + return this.active; + } + public final String getLocale() { + return this.locale; + } + public final String getTimezone() { + return this.timezone; + } + public final List getSchemas() { + return this.schemas; + } + public final ScimMeta getMeta() { + return this.meta; + } + + @Override + public boolean equals(final Object o) { + if (this==o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + User other = (User) o; + + return Objects.equals(id, other.id) && Objects.equals(externalId, other.externalId) && Objects.equals(userName, other.userName) && Objects.equals(displayName, other.displayName) && Objects.equals(name, other.name) && Objects.equals(emails, other.emails) && Objects.equals(active, other.active) && Objects.equals(locale, other.locale) && Objects.equals(timezone, other.timezone) && Objects.equals(schemas, other.schemas) && Objects.equals(meta, other.meta) ; + } + + @Override + public int hashCode() { + return Objects.hash(id, externalId, userName, displayName, name, emails, active, locale, timezone, schemas, meta); + } + + +} + diff --git a/examples/java/src/main/java/com/twilio/rest/previewiam/organizations/UserCreator.java b/examples/java/src/main/java/com/twilio/rest/previewiam/organizations/UserCreator.java new file mode 100644 index 000000000..6bdca6548 --- /dev/null +++ b/examples/java/src/main/java/com/twilio/rest/previewiam/organizations/UserCreator.java @@ -0,0 +1,103 @@ +/* + * 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.bearertoken.Creator; +import com.twilio.http.bearertoken.BearerTokenRequest; +import com.twilio.http.bearertoken.BearerTokenTwilioRestClient; + +public class UserCreator extends Creator{ + private String pathOrganizationSid; + private User.ScimUser scimUser; + + public UserCreator(final String pathOrganizationSid, final User.ScimUser scimUser) { + this.pathOrganizationSid = pathOrganizationSid; + this.scimUser = scimUser; + } + + public UserCreator setScimUser(final User.ScimUser scimUser){ + this.scimUser = scimUser; + return this; + } + + @Override + public User create(final BearerTokenTwilioRestClient client){ + String path = "/Organizations/{organizationSid}/scim/Users"; + + path = path.replace("{"+"organizationSid"+"}", this.pathOrganizationSid.toString()); + path = path.replace("{"+"ScimUser"+"}", this.scimUser.toString()); + + BearerTokenRequest request = new BearerTokenRequest( + HttpMethod.POST, + Domains.PREVIEWIAM.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request, client); + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException("User creation failed: Unable to connect to server"); + } else if (!BearerTokenTwilioRestClient.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 User.fromJson(response.getStream(), client.getObjectMapper()); + } + private void addPostParams(final BearerTokenRequest request, BearerTokenTwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (scimUser != null) { + request.setBody(User.toJson(scimUser, objectMapper)); + } + } +} diff --git a/examples/java/src/main/java/com/twilio/rest/previewiam/organizations/UserDeleter.java b/examples/java/src/main/java/com/twilio/rest/previewiam/organizations/UserDeleter.java new file mode 100644 index 000000000..261caefb2 --- /dev/null +++ b/examples/java/src/main/java/com/twilio/rest/previewiam/organizations/UserDeleter.java @@ -0,0 +1,85 @@ +/* + * 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.converter.Promoter; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.converter.PrefixedCollapsibleMap; +import com.twilio.exception.ApiException; +import com.twilio.converter.Converter; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Response; +import com.twilio.rest.Domains; +import java.time.LocalDate; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigDecimal; +import java.net.URI; +import java.time.ZonedDateTime; +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 lombok.ToString; + +import com.twilio.base.bearertoken.Deleter; +import com.twilio.http.bearertoken.BearerTokenRequest; +import com.twilio.http.bearertoken.BearerTokenTwilioRestClient; + +public class UserDeleter extends Deleter { + private String pathOrganizationSid; + private String pathUserSid; + + public UserDeleter(final String pathOrganizationSid, final String pathUserSid){ + this.pathOrganizationSid = pathOrganizationSid; + this.pathUserSid = pathUserSid; + } + + + @Override + public boolean delete(final BearerTokenTwilioRestClient client) { + String path = "/Organizations/{organizationSid}/scim/Users/{userSid}"; + + path = path.replace("{"+"organizationSid"+"}", this.pathOrganizationSid.toString()); + path = path.replace("{"+"userSid"+"}", this.pathUserSid.toString()); + + BearerTokenRequest request = new BearerTokenRequest( + HttpMethod.DELETE, + Domains.PREVIEWIAM.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException("User delete failed: Unable to connect to server"); + } else if (!BearerTokenTwilioRestClient.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 response.getStatusCode() == 204; + } +} diff --git a/examples/java/src/main/java/com/twilio/rest/previewiam/organizations/UserFetcher.java b/examples/java/src/main/java/com/twilio/rest/previewiam/organizations/UserFetcher.java new file mode 100644 index 000000000..afeab006a --- /dev/null +++ b/examples/java/src/main/java/com/twilio/rest/previewiam/organizations/UserFetcher.java @@ -0,0 +1,87 @@ +/* + * 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.io.IOException; +import java.io.InputStream; +import java.math.BigDecimal; +import java.net.URI; +import java.time.ZonedDateTime; +import java.time.LocalDate; +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 lombok.ToString; + +import com.twilio.base.bearertoken.Fetcher; +import com.twilio.http.bearertoken.BearerTokenRequest; +import com.twilio.http.bearertoken.BearerTokenTwilioRestClient; + +public class UserFetcher extends Fetcher { + private String pathOrganizationSid; + private String pathUserSid; + + public UserFetcher(final String pathOrganizationSid, final String pathUserSid){ + this.pathOrganizationSid = pathOrganizationSid; + this.pathUserSid = pathUserSid; + } + + + @Override + public User fetch(final BearerTokenTwilioRestClient client) { + String path = "/Organizations/{organizationSid}/scim/Users/{userSid}"; + + path = path.replace("{"+"organizationSid"+"}", this.pathOrganizationSid.toString()); + path = path.replace("{"+"userSid"+"}", this.pathUserSid.toString()); + + BearerTokenRequest request = new BearerTokenRequest( + HttpMethod.GET, + Domains.PREVIEWIAM.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException("User fetch failed: Unable to connect to server"); + } else if (!BearerTokenTwilioRestClient.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 User.fromJson(response.getStream(), client.getObjectMapper()); + } +} diff --git a/examples/java/src/main/java/com/twilio/rest/previewiam/organizations/UserReader.java b/examples/java/src/main/java/com/twilio/rest/previewiam/organizations/UserReader.java new file mode 100644 index 000000000..c99291016 --- /dev/null +++ b/examples/java/src/main/java/com/twilio/rest/previewiam/organizations/UserReader.java @@ -0,0 +1,143 @@ +/* + * 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.time.LocalDate; +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 lombok.ToString; + +import com.twilio.base.bearertoken.Page; +import com.twilio.base.bearertoken.Reader; +import com.twilio.base.bearertoken.ResourceSet; +import com.twilio.http.bearertoken.BearerTokenRequest; +import com.twilio.http.bearertoken.BearerTokenTwilioRestClient; + +public class UserReader extends Reader { + private String pathOrganizationSid; + private String filter; + + public UserReader(final String pathOrganizationSid){ + this.pathOrganizationSid = pathOrganizationSid; + } + + public UserReader setFilter(final String filter){ + this.filter = filter; + return this; + } + + @Override + public ResourceSet read(final BearerTokenTwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final BearerTokenTwilioRestClient client) { + String path = "/Organizations/{organizationSid}/scim/Users"; + path = path.replace("{"+"organizationSid"+"}", this.pathOrganizationSid.toString()); + + BearerTokenRequest request = new BearerTokenRequest( + HttpMethod.GET, + Domains.PREVIEWIAM.toString(), + path + ); + + addQueryParams(request); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + return pageForRequest(client, request); + } + + private Page pageForRequest(final BearerTokenTwilioRestClient client, final BearerTokenRequest request) { + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException("User read failed: Unable to connect to server"); + } else if (!BearerTokenTwilioRestClient.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 Page.fromJson( + "Resources", + response.getContent(), + User.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage(final Page page, final BearerTokenTwilioRestClient client) { + BearerTokenRequest request = new BearerTokenRequest( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.PREVIEWIAM.toString()) + ); + return pageForRequest(client, request); + } + + + @Override + public Page nextPage(final Page page, final BearerTokenTwilioRestClient client) { + BearerTokenRequest request = new BearerTokenRequest( + HttpMethod.GET, + page.getNextPageUrl(Domains.PREVIEWIAM.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage(final String targetUrl, final BearerTokenTwilioRestClient client) { + BearerTokenRequest request = new BearerTokenRequest( + HttpMethod.GET, + targetUrl + ); + + return pageForRequest(client, request); + } + private void addQueryParams(final BearerTokenRequest request) { + if (filter != null) { + + request.addQueryParam("filter", filter); + } + + if(getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/examples/java/src/main/java/com/twilio/rest/previewiam/organizations/UserUpdater.java b/examples/java/src/main/java/com/twilio/rest/previewiam/organizations/UserUpdater.java new file mode 100644 index 000000000..5e5e82f58 --- /dev/null +++ b/examples/java/src/main/java/com/twilio/rest/previewiam/organizations/UserUpdater.java @@ -0,0 +1,114 @@ +/* + * 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.time.format.DateTimeFormatter; +import com.twilio.converter.DateConverter; + +import java.io.IOException; +import java.io.InputStream; +import java.math.BigDecimal; +import java.net.URI; +import java.time.ZonedDateTime; +import java.time.LocalDate; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +import lombok.ToString; + +import com.twilio.base.bearertoken.Updater; +import com.twilio.http.bearertoken.BearerTokenRequest; +import com.twilio.http.bearertoken.BearerTokenTwilioRestClient; + + +public class UserUpdater extends Updater{ + private String pathOrganizationSid; + private String pathUserSid; + private User.ScimUser scimUser; + private String ifMatch; + + public UserUpdater(final String pathOrganizationSid, final String pathUserSid, final User.ScimUser scimUser){ + this.pathOrganizationSid = pathOrganizationSid; + this.pathUserSid = pathUserSid; + this.scimUser = scimUser; + } + + public UserUpdater setScimUser(final User.ScimUser scimUser){ + this.scimUser = scimUser; + return this; + } + public UserUpdater setIfMatch(final String ifMatch){ + this.ifMatch = ifMatch; + return this; + } + + @Override + public User update(final BearerTokenTwilioRestClient client){ + String path = "/Organizations/{organizationSid}/scim/Users/{userSid}"; + + path = path.replace("{"+"organizationSid"+"}", this.pathOrganizationSid.toString()); + path = path.replace("{"+"userSid"+"}", this.pathUserSid.toString()); + path = path.replace("{"+"ScimUser"+"}", this.scimUser.toString()); + + BearerTokenRequest request = new BearerTokenRequest( + HttpMethod.PUT, + Domains.PREVIEWIAM.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request, client); + addHeaderParams(request); + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException("User update failed: Unable to connect to server"); + } else if (!BearerTokenTwilioRestClient.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 User.fromJson(response.getStream(), client.getObjectMapper()); + } + + private void addPostParams(final BearerTokenRequest request, BearerTokenTwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (scimUser != null) { + request.setBody(User.toJson(scimUser, objectMapper)); + } + } + private void addHeaderParams(final BearerTokenRequest request) { + if (ifMatch != null) { + request.addHeaderParam("If-Match", ifMatch); + + } + } +} diff --git a/examples/twilio_iam_organizations.yaml b/examples/spec/twilio_iam_organizations.yaml similarity index 100% rename from examples/twilio_iam_organizations.yaml rename to examples/spec/twilio_iam_organizations.yaml