Skip to content

Commit

Permalink
preview branch
Browse files Browse the repository at this point in the history
  • Loading branch information
AsabuHere committed Jun 26, 2024
1 parent 2b32a89 commit afaeea5
Show file tree
Hide file tree
Showing 17 changed files with 1,883 additions and 70 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
<version>1.18.30</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
182 changes: 182 additions & 0 deletions src/main/java/com/twilio/rest/previewiam/organizations/Account.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/*
* 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.JsonProperty;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.twilio.base.bearertoken.Resource;
import com.twilio.converter.DateConverter;
import com.twilio.converter.Promoter;
import com.twilio.exception.ApiConnectionException;

import com.twilio.exception.ApiException;

import lombok.ToString;

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

import java.util.Objects;

import lombok.ToString;


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



public static AccountFetcher fetcher(final String pathOrganizationSid, final String pathAccountSid){
return new AccountFetcher(pathOrganizationSid, pathAccountSid);
}

public static AccountReader reader(final String pathOrganizationSid){
return new AccountReader(pathOrganizationSid);
}

/**
* Converts a JSON String into a Account object using the provided ObjectMapper.
*
* @param json Raw JSON String
* @param objectMapper Jackson ObjectMapper
* @return Account object represented by the provided JSON
*/
public static Account fromJson(final String json, final ObjectMapper objectMapper) {
// Convert all checked exceptions to Runtime
try {
return objectMapper.readValue(json, Account.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 Account object using the provided
* ObjectMapper.
*
* @param json Raw JSON InputStream
* @param objectMapper Jackson ObjectMapper
* @return Account object represented by the provided JSON
*/
public static Account fromJson(final InputStream json, final ObjectMapper objectMapper) {
// Convert all checked exceptions to Runtime
try {
return objectMapper.readValue(json, Account.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 accountSid;
private final String friendlyName;
private final Account.StatusEnum status;
private final String ownerSid;
private final ZonedDateTime dateCreated;

@JsonCreator
private Account(
@JsonProperty("account_sid")
final String accountSid,

@JsonProperty("friendly_name")
final String friendlyName,

@JsonProperty("status")
final Account.StatusEnum status,

@JsonProperty("owner_sid")
final String ownerSid,

@JsonProperty("date_created")
final String dateCreated
) {
this.accountSid = accountSid;
this.friendlyName = friendlyName;
this.status = status;
this.ownerSid = ownerSid;
this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated);
}

public final String getAccountSid() {
return this.accountSid;
}
public final String getFriendlyName() {
return this.friendlyName;
}
public final Account.StatusEnum getStatus() {
return this.status;
}
public final String getOwnerSid() {
return this.ownerSid;
}
public final ZonedDateTime getDateCreated() {
return this.dateCreated;
}

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

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

Account other = (Account) o;

return Objects.equals(accountSid, other.accountSid) && Objects.equals(friendlyName, other.friendlyName) && Objects.equals(status, other.status) && Objects.equals(ownerSid, other.ownerSid) && Objects.equals(dateCreated, other.dateCreated) ;
}

@Override
public int hashCode() {
return Objects.hash(accountSid, friendlyName, status, ownerSid, dateCreated);
}

public enum StatusEnum {
ACTIVE("active"),
SUSPENDED("suspended"),
PENDING_CLOSURE("pending_closure"),
CLOSED("closed");

private final String value;

private StatusEnum(final String value) {
this.value = value;
}

public String toString() {
return value;
}

@JsonCreator
public static StatusEnum forValue(final String value) {
return Promoter.enumFromString(value, StatusEnum.values());
}
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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.twilio.exception.ApiConnectionException;
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 com.twilio.base.bearertoken.Fetcher;
import com.twilio.http.bearertoken.BearerTokenRequest;
import com.twilio.http.bearertoken.BearerTokenTwilioRestClient;

public class AccountFetcher extends Fetcher<Account> {
private String pathOrganizationSid;
private String pathAccountSid;

public AccountFetcher(final String pathOrganizationSid, final String pathAccountSid){
this.pathOrganizationSid = pathOrganizationSid;
this.pathAccountSid = pathAccountSid;
}


@Override
public Account fetch(final BearerTokenTwilioRestClient client) {
String path = "/Organizations/{organizationSid}/Accounts/{accountSid}";

path = path.replace("{"+"organizationSid"+"}", this.pathOrganizationSid.toString());
path = path.replace("{"+"accountSid"+"}", this.pathAccountSid.toString());

BearerTokenRequest request = new BearerTokenRequest(
HttpMethod.GET,
Domains.PREVIEWIAM.toString(),
path
);
Response response = client.request(request);

if (response == null) {
throw new ApiConnectionException("Account 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 Account.fromJson(response.getStream(), client.getObjectMapper());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* 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.twilio.exception.ApiConnectionException;
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 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 AccountReader extends Reader<Account> {
private String pathOrganizationSid;
private Integer pageSize;

public AccountReader(final String pathOrganizationSid){
this.pathOrganizationSid = pathOrganizationSid;
}

public AccountReader setPageSize(final Integer pageSize){
this.pageSize = pageSize;
return this;
}

@Override
public ResourceSet<Account> read(final BearerTokenTwilioRestClient client) {
return new ResourceSet<>(this, client, firstPage(client));
}

public Page<Account> firstPage(final BearerTokenTwilioRestClient client) {
String path = "/Organizations/{organizationSid}/Accounts";
path = path.replace("{"+"organizationSid"+"}", this.pathOrganizationSid.toString());

BearerTokenRequest request = new BearerTokenRequest(
HttpMethod.GET,
Domains.PREVIEWIAM.toString(),
path
);

addQueryParams(request);
return pageForRequest(client, request);
}

private Page<Account> pageForRequest(final BearerTokenTwilioRestClient client, final BearerTokenRequest request) {
Response response = client.request(request);

if (response == null) {
throw new ApiConnectionException("Account 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(
"content",
response.getContent(),
Account.class,
client.getObjectMapper()
);
}

@Override
public Page<Account> previousPage(final Page<Account> page, final BearerTokenTwilioRestClient client) {
BearerTokenRequest request = new BearerTokenRequest(
HttpMethod.GET,
page.getPreviousPageUrl(Domains.PREVIEWIAM.toString())
);
return pageForRequest(client, request);
}


@Override
public Page<Account> nextPage(final Page<Account> page, final BearerTokenTwilioRestClient client) {
BearerTokenRequest request = new BearerTokenRequest(
HttpMethod.GET,
page.getNextPageUrl(Domains.PREVIEWIAM.toString())
);
return pageForRequest(client, request);
}

@Override
public Page<Account> 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 (pageSize != null) {

request.addQueryParam("PageSize", pageSize.toString());
}

if(getPageSize() != null) {
request.addQueryParam("PageSize", Integer.toString(getPageSize()));
}
}
}
Loading

0 comments on commit afaeea5

Please sign in to comment.