Class: Courier::Users::Tokens::UserToken
- Inherits:
-
Object
- Object
- Courier::Users::Tokens::UserToken
- Defined in:
- lib/trycourier/users/tokens/types/user_token.rb
Instance Attribute Summary collapse
-
#additional_properties ⇒ Object
readonly
Returns the value of attribute additional_properties.
-
#device ⇒ Object
readonly
Returns the value of attribute device.
-
#expiry_date ⇒ Object
readonly
Returns the value of attribute expiry_date.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#provider_key ⇒ Object
readonly
Returns the value of attribute provider_key.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#tracking ⇒ Object
readonly
Returns the value of attribute tracking.
Class Method Summary collapse
-
.from_json(json_object:) ⇒ Users::Tokens::UserToken
Deserialize a JSON object to an instance of UserToken.
-
.validate_raw(obj:) ⇒ Void
Leveraged for Union-type generation, validate_raw attempts to parse the given hash and check each fields type against the current object’s property definitions.
Instance Method Summary collapse
- #initialize(provider_key:, token: nil, expiry_date: nil, properties: nil, device: nil, tracking: nil, additional_properties: nil) ⇒ Users::Tokens::UserToken constructor
-
#to_json(*_args) ⇒ JSON
Serialize an instance of UserToken to a JSON object.
Constructor Details
#initialize(provider_key:, token: nil, expiry_date: nil, properties: nil, device: nil, tracking: nil, additional_properties: nil) ⇒ Users::Tokens::UserToken
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/trycourier/users/tokens/types/user_token.rb', line 23 def initialize(provider_key:, token: nil, expiry_date: nil, properties: nil, device: nil, tracking: nil, additional_properties: nil) # @type [String] Full body of the token. Must match token in URL. @token = token # @type [Users::Tokens::ProviderKey] @provider_key = provider_key # @type [Users::Tokens::ExpiryDate] ISO 8601 formatted date the token expires. Defaults to 2 months. Set to false to disable expiration. @expiry_date = expiry_date # @type [Object] Properties sent to the provider along with the token @properties = properties # @type [Users::Tokens::Device] Information about the device the token is associated with. @device = device # @type [Users::Tokens::Tracking] Information about the device the token is associated with. @tracking = tracking # @type [OpenStruct] Additional properties unmapped to the current class definition @additional_properties = additional_properties end |
Instance Attribute Details
#additional_properties ⇒ Object (readonly)
Returns the value of attribute additional_properties.
13 14 15 |
# File 'lib/trycourier/users/tokens/types/user_token.rb', line 13 def additional_properties @additional_properties end |
#device ⇒ Object (readonly)
Returns the value of attribute device.
13 14 15 |
# File 'lib/trycourier/users/tokens/types/user_token.rb', line 13 def device @device end |
#expiry_date ⇒ Object (readonly)
Returns the value of attribute expiry_date.
13 14 15 |
# File 'lib/trycourier/users/tokens/types/user_token.rb', line 13 def expiry_date @expiry_date end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
13 14 15 |
# File 'lib/trycourier/users/tokens/types/user_token.rb', line 13 def properties @properties end |
#provider_key ⇒ Object (readonly)
Returns the value of attribute provider_key.
13 14 15 |
# File 'lib/trycourier/users/tokens/types/user_token.rb', line 13 def provider_key @provider_key end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
13 14 15 |
# File 'lib/trycourier/users/tokens/types/user_token.rb', line 13 def token @token end |
#tracking ⇒ Object (readonly)
Returns the value of attribute tracking.
13 14 15 |
# File 'lib/trycourier/users/tokens/types/user_token.rb', line 13 def tracking @tracking end |
Class Method Details
.from_json(json_object:) ⇒ Users::Tokens::UserToken
Deserialize a JSON object to an instance of UserToken
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/trycourier/users/tokens/types/user_token.rb', line 45 def self.from_json(json_object:) struct = JSON.parse(json_object, object_class: OpenStruct) parsed_json = JSON.parse(json_object) token = struct.token provider_key = struct.provider_key if parsed_json["expiry_date"].nil? expiry_date = nil else expiry_date = parsed_json["expiry_date"].to_json expiry_date = Users::Tokens::ExpiryDate.from_json(json_object: expiry_date) end properties = struct.properties if parsed_json["device"].nil? device = nil else device = parsed_json["device"].to_json device = Users::Tokens::Device.from_json(json_object: device) end if parsed_json["tracking"].nil? tracking = nil else tracking = parsed_json["tracking"].to_json tracking = Users::Tokens::Tracking.from_json(json_object: tracking) end new(token: token, provider_key: provider_key, expiry_date: expiry_date, properties: properties, device: device, tracking: tracking, additional_properties: struct) end |
.validate_raw(obj:) ⇒ Void
Leveraged for Union-type generation, validate_raw attempts to parse the given hash and check each fields type against the current object’s property definitions.
91 92 93 94 95 96 97 98 |
# File 'lib/trycourier/users/tokens/types/user_token.rb', line 91 def self.validate_raw(obj:) obj.token&.is_a?(String) != false || raise("Passed value for field obj.token is not the expected type, validation failed.") obj.provider_key.is_a?(Users::Tokens::ProviderKey) != false || raise("Passed value for field obj.provider_key is not the expected type, validation failed.") obj.expiry_date.nil? || Users::Tokens::ExpiryDate.validate_raw(obj: obj.expiry_date) obj.properties&.is_a?(Object) != false || raise("Passed value for field obj.properties is not the expected type, validation failed.") obj.device.nil? || Users::Tokens::Device.validate_raw(obj: obj.device) obj.tracking.nil? || Users::Tokens::Tracking.validate_raw(obj: obj.tracking) end |
Instance Method Details
#to_json(*_args) ⇒ JSON
Serialize an instance of UserToken to a JSON object
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/trycourier/users/tokens/types/user_token.rb', line 76 def to_json(*_args) { "token": @token, "provider_key": @provider_key, "expiry_date": @expiry_date, "properties": @properties, "device": @device, "tracking": @tracking }.to_json end |