Skip to content

Commit

Permalink
adding token class files
Browse files Browse the repository at this point in the history
  • Loading branch information
AsabuHere committed Jun 14, 2024
1 parent f690533 commit 9acfcaa
Showing 1 changed file with 173 additions and 1 deletion.
174 changes: 173 additions & 1 deletion src/main/java/com/twilio/rest/previewiam/organizations/Token.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,181 @@

package com.twilio.rest.previewiam.organizations;

import com.twilio.base.noauth.Resource;
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.converter.Converter;
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);
}


}

0 comments on commit 9acfcaa

Please sign in to comment.