class ShipEngine::Carrier

A carrier object that represents a provider such as UPS, USPS, DHL, etc that has been tied to the current account.

Attributes

account_number[RW]

The account number that the carrier is connected to.

balance[RW]

Current available balance

carrier_code[RW]

A string that uniquely identifies the carrier.

carrier_id[RW]

A string that uniquely identifies the carrier.

friendly_name[RW]

Screen readable name

has_multi_package_supporting_services[RW]

Carrier supports multiple packages per shipment

nickname[RW]

Nickname given to the account when initially setting up the carrier.

options[RW]

A list of options that are available to that carrier

packages[RW]

A list of package types that are supported by the carrier

primary[RW]

Is this the primary carrier that is used by default when no carrier is specified in label/shipment creation

requires_funded_amount[RW]

Indicates whether the carrier requires funding to use its services

services[RW]

A list of services that are offered by the carrier

supports_label_messages[RW]

The carrier supports adding custom label messages to an order.

Public Class Methods

attribute_map() click to toggle source

Attribute mapping from ruby-style variable name to JSON key.

# File lib/ship_engine/models/carrier.rb, line 58
def self.attribute_map
  {
    :'carrier_id' => :'carrier_id',
    :'carrier_code' => :'carrier_code',
    :'account_number' => :'account_number',
    :'requires_funded_amount' => :'requires_funded_amount',
    :'balance' => :'balance',
    :'nickname' => :'nickname',
    :'friendly_name' => :'friendly_name',
    :'primary' => :'primary',
    :'has_multi_package_supporting_services' => :'has_multi_package_supporting_services',
    :'supports_label_messages' => :'supports_label_messages',
    :'services' => :'services',
    :'packages' => :'packages',
    :'options' => :'options'
  }
end
build_from_hash(attributes) click to toggle source

Builds the object from hash @param [Hash] attributes Model attributes in the form of hash @return [Object] Returns the model itself

# File lib/ship_engine/models/carrier.rb, line 281
def self.build_from_hash(attributes)
  new.build_from_hash(attributes)
end
new(attributes = {}) click to toggle source

Initializes the object @param [Hash] attributes Model attributes in the form of hash

# File lib/ship_engine/models/carrier.rb, line 103
def initialize(attributes = {})
  if (!attributes.is_a?(Hash))
    fail ArgumentError, "The input argument (attributes) must be a hash in `ShipEngine::Carrier` initialize method"
  end

  # check to see if the attribute exists and convert string to symbol for hash key
  attributes = attributes.each_with_object({}) { |(k, v), h|

    h[k.to_sym] = v
  }

  if attributes.key?(:'carrier_id')
    self.carrier_id = attributes[:'carrier_id']
  end

  if attributes.key?(:'carrier_code')
    self.carrier_code = attributes[:'carrier_code']
  end

  if attributes.key?(:'account_number')
    self.account_number = attributes[:'account_number']
  end

  if attributes.key?(:'requires_funded_amount')
    self.requires_funded_amount = attributes[:'requires_funded_amount']
  end

  if attributes.key?(:'balance')
    self.balance = attributes[:'balance']
  end

  if attributes.key?(:'nickname')
    self.nickname = attributes[:'nickname']
  end

  if attributes.key?(:'friendly_name')
    self.friendly_name = attributes[:'friendly_name']
  end

  if attributes.key?(:'primary')
    self.primary = attributes[:'primary']
  end

  if attributes.key?(:'has_multi_package_supporting_services')
    self.has_multi_package_supporting_services = attributes[:'has_multi_package_supporting_services']
  end

  if attributes.key?(:'supports_label_messages')
    self.supports_label_messages = attributes[:'supports_label_messages']
  end

  if attributes.key?(:'services')
    if (value = attributes[:'services']).is_a?(Array)
      self.services = value
    end
  end

  if attributes.key?(:'packages')
    if (value = attributes[:'packages']).is_a?(Array)
      self.packages = value
    end
  end

  if attributes.key?(:'options')
    if (value = attributes[:'options']).is_a?(Array)
      self.options = value
    end
  end
end
openapi_nullable() click to toggle source

List of attributes with nullable: true

# File lib/ship_engine/models/carrier.rb, line 96
def self.openapi_nullable
  Set.new([
  ])
end
openapi_types() click to toggle source

Attribute type mapping.

# File lib/ship_engine/models/carrier.rb, line 77
def self.openapi_types
  {
    :'carrier_id' => :'String',
    :'carrier_code' => :'String',
    :'account_number' => :'String',
    :'requires_funded_amount' => :'Boolean',
    :'balance' => :'Float',
    :'nickname' => :'String',
    :'friendly_name' => :'String',
    :'primary' => :'Boolean',
    :'has_multi_package_supporting_services' => :'Boolean',
    :'supports_label_messages' => :'Boolean',
    :'services' => :'Array<Service>',
    :'packages' => :'Array<PackageType>',
    :'options' => :'Array<CarrierAdvancedOption>'
  }
end

Public Instance Methods

==(o) click to toggle source

Checks equality by comparing each attribute. @param [Object] Object to be compared

# File lib/ship_engine/models/carrier.rb, line 248
def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      carrier_id == o.carrier_id &&
      carrier_code == o.carrier_code &&
      account_number == o.account_number &&
      requires_funded_amount == o.requires_funded_amount &&
      balance == o.balance &&
      nickname == o.nickname &&
      friendly_name == o.friendly_name &&
      primary == o.primary &&
      has_multi_package_supporting_services == o.has_multi_package_supporting_services &&
      supports_label_messages == o.supports_label_messages &&
      services == o.services &&
      packages == o.packages &&
      options == o.options
end
_deserialize(type, value) click to toggle source

Deserializes the data based on type @param string type Data type @param string value Value to be deserialized @return [Object] Deserialized data

# File lib/ship_engine/models/carrier.rb, line 309
def _deserialize(type, value)
  case type.to_sym
  when :DateTime
    DateTime.parse(value)
  when :Date
    Date.parse(value)
  when :String
    value.to_s
  when :Integer
    value.to_i
  when :Float
    value.to_f
  when :Boolean
    if value.to_s =~ /\A(true|t|yes|y|1)\z/i
      true
    else
      false
    end
  when :Object
    # generic object (usually a Hash), return directly
    value
  when /\AArray<(?<inner_type>.+)>\z/
    inner_type = Regexp.last_match[:inner_type]
    value.map { |v| _deserialize(inner_type, v) }
  when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
    k_type = Regexp.last_match[:k_type]
    v_type = Regexp.last_match[:v_type]
    {}.tap do |hash|
      value.each do |k, v|
        hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
      end
    end
  else # model
    ShipEngine.const_get(type).build_from_hash(value)
  end
end
_to_hash(value) click to toggle source

Outputs non-array value in the form of hash For object, use to_hash. Otherwise, just return the value @param [Object] value Any valid value @return [Hash] Returns the value in the form of hash

# File lib/ship_engine/models/carrier.rb, line 378
def _to_hash(value)
  if value.is_a?(Array)
    value.compact.map { |v| _to_hash(v) }
  elsif value.is_a?(Hash)
    {}.tap do |hash|
      value.each { |k, v| hash[k] = _to_hash(v) }
    end
  elsif value.respond_to? :to_hash
    value.to_hash
  else
    value
  end
end
account_number=(account_number) click to toggle source

Custom attribute writer method with validation @param [Object] account_number Value to be assigned

# File lib/ship_engine/models/carrier.rb, line 208
def account_number=(account_number)
  if !account_number.nil? && account_number.to_s.length < 1
    fail ArgumentError, 'invalid value for "account_number", the character length must be great than or equal to 1.'
  end

  @account_number = account_number
end
balance=(balance) click to toggle source

Custom attribute writer method with validation @param [Object] balance Value to be assigned

# File lib/ship_engine/models/carrier.rb, line 218
def balance=(balance)
  if !balance.nil? && balance < 0
    fail ArgumentError, 'invalid value for "balance", must be greater than or equal to 0.'
  end

  @balance = balance
end
build_from_hash(attributes) click to toggle source

Builds the object from hash @param [Hash] attributes Model attributes in the form of hash @return [Object] Returns the model itself

# File lib/ship_engine/models/carrier.rb, line 288
def build_from_hash(attributes)
  return nil unless attributes.is_a?(Hash)
  self.class.openapi_types.each_pair do |key, type|
    if type =~ /\AArray<(.*)>/i
      # check to ensure the input is an array given that the attribute
      # is documented as an array but the input is not
      if attributes[self.class.attribute_map[key]].is_a?(Array)
        self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
      end
    elsif !attributes[self.class.attribute_map[key]].nil?
      self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
    end # or else data not found in attributes(hash), not an issue as the data can be optional
  end

  self
end
eql?(o) click to toggle source

@see the `==` method @param [Object] Object to be compared

# File lib/ship_engine/models/carrier.rb, line 268
def eql?(o)
  self == o
end
friendly_name=(friendly_name) click to toggle source

Custom attribute writer method with validation @param [Object] friendly_name Value to be assigned

# File lib/ship_engine/models/carrier.rb, line 238
def friendly_name=(friendly_name)
  if !friendly_name.nil? && friendly_name.to_s.length < 1
    fail ArgumentError, 'invalid value for "friendly_name", the character length must be great than or equal to 1.'
  end

  @friendly_name = friendly_name
end
hash() click to toggle source

Calculates hash code according to all attributes. @return [Integer] Hash code

# File lib/ship_engine/models/carrier.rb, line 274
def hash
  [carrier_id, carrier_code, account_number, requires_funded_amount, balance, nickname, friendly_name, primary, has_multi_package_supporting_services, supports_label_messages, services, packages, options].hash
end
list_invalid_properties() click to toggle source

Show invalid properties with the reasons. Usually used together with valid? @return Array for valid properties with the reasons

# File lib/ship_engine/models/carrier.rb, line 175
def list_invalid_properties
  invalid_properties = Array.new
  if !@account_number.nil? && @account_number.to_s.length < 1
    invalid_properties.push('invalid value for "account_number", the character length must be great than or equal to 1.')
  end

  if !@balance.nil? && @balance < 0
    invalid_properties.push('invalid value for "balance", must be greater than or equal to 0.')
  end

  if !@nickname.nil? && @nickname.to_s.length < 1
    invalid_properties.push('invalid value for "nickname", the character length must be great than or equal to 1.')
  end

  if !@friendly_name.nil? && @friendly_name.to_s.length < 1
    invalid_properties.push('invalid value for "friendly_name", the character length must be great than or equal to 1.')
  end

  invalid_properties
end
nickname=(nickname) click to toggle source

Custom attribute writer method with validation @param [Object] nickname Value to be assigned

# File lib/ship_engine/models/carrier.rb, line 228
def nickname=(nickname)
  if !nickname.nil? && nickname.to_s.length < 1
    fail ArgumentError, 'invalid value for "nickname", the character length must be great than or equal to 1.'
  end

  @nickname = nickname
end
to_body() click to toggle source

to_body is an alias to to_hash (backward compatibility) @return [Hash] Returns the object in the form of hash

# File lib/ship_engine/models/carrier.rb, line 354
def to_body
  to_hash
end
to_hash() click to toggle source

Returns the object in the form of hash @return [Hash] Returns the object in the form of hash

# File lib/ship_engine/models/carrier.rb, line 360
def to_hash
  hash = {}
  self.class.attribute_map.each_pair do |attr, param|
    value = self.send(attr)
    if value.nil?
      is_nullable = self.class.openapi_nullable.include?(attr)
      next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
    end

    hash[param] = _to_hash(value)
  end
  hash
end
to_s() click to toggle source

Returns the string representation of the object @return [String] String presentation of the object

# File lib/ship_engine/models/carrier.rb, line 348
def to_s
  to_hash.to_s
end
valid?() click to toggle source

Check to see if the all the properties in the model are valid @return true if the model is valid

# File lib/ship_engine/models/carrier.rb, line 198
def valid?
  return false if !@account_number.nil? && @account_number.to_s.length < 1
  return false if !@balance.nil? && @balance < 0
  return false if !@nickname.nil? && @nickname.to_s.length < 1
  return false if !@friendly_name.nil? && @friendly_name.to_s.length < 1
  true
end