Module: Fortnox::API::Types

Defined in:
lib/fortnox/api/types.rb,
lib/fortnox/api/types/enums.rb,
lib/fortnox/api/types/model.rb,
lib/fortnox/api/types/sized.rb,
lib/fortnox/api/types/nullable.rb,
lib/fortnox/api/types/required.rb,
lib/fortnox/api/types/defaulted.rb,
lib/fortnox/api/types/order_row.rb,
lib/fortnox/api/types/invoice_row.rb,
lib/fortnox/api/types/document_row.rb,
lib/fortnox/api/types/edi_information.rb,
lib/fortnox/api/types/default_templates.rb,
lib/fortnox/api/types/email_information.rb,
lib/fortnox/api/types/shim/country_string.rb,
lib/fortnox/api/types/default_delivery_types.rb

Defined Under Namespace

Modules: Defaulted, EnumConstructors, Nullable, Required, Sized Classes: CountryString, DefaultDeliveryTypes, DefaultTemplates, DocumentRow, EDIInformation, EmailInformation, InvoiceRow, Model, OrderRow

Constant Summary collapse

THE_TRUTH =
{ true => true, 'true' => true, false => false, 'false' => false }.freeze
AccountNumber =
Strict::Int
.constrained(gteq: 0, lteq: 9999)
.optional
.constructor do |value|
  next nil if value.nil? || value == ''
  value
end
ArticleType =
Strict::String
.constrained(included_in: ArticleTypes.values)
.optional
.constructor(EnumConstructors.default)
Country =
Strict::String
.optional
.constructor do |value|
  next value if value.nil? || value == ''

  # Fortnox only supports Swedish translation of Sweden
  next CountryString.new('SE') if value =~ /^s(e$|we|ve)/i

  country = ::ISO3166::Country[value] ||
            ::ISO3166::Country.find_country_by_name(value) ||
            ::ISO3166::Country.find_country_by_translated_names(value)

  raise Dry::Types::ConstraintError.new('value violates constraints', value) if country.nil?

  CountryString.new(country.alpha2)
end
CountryCode =
Strict::String
.optional
.constructor do |value|
  next value if value.nil? || value == ''

  country = ::ISO3166::Country[value]

  raise Dry::Types::ConstraintError.new('value violates constraints', value) if country.nil?

  country.alpha2
end
Currency =
Strict::String
.constrained(included_in: Currencies.values)
.optional
.constructor(EnumConstructors.sized(3))
CustomerType =
Strict::String
.constrained(included_in: CustomerTypes.values)
.optional
.constructor(EnumConstructors.default)
DiscountType =
Strict::String
.constrained(included_in: DiscountTypes.values)
.optional
.constructor(EnumConstructors.default)
Email =
Strict::String
.constrained(max_size: 1024, format: /^$|\A[[[:alnum:]]+-_.]+@[\w+-_.]+\.[a-z]+\z/i)
.optional
.constructor { |v| v.to_s.downcase unless v.nil? }
HouseworkType =
Strict::String
.constrained(included_in: HouseworkTypes.values)
.optional
.constructor(EnumConstructors.default)
VATType =
Strict::String
.constrained(included_in: VATTypes.values)
.optional
.constructor(EnumConstructors.default)
DefaultDeliveryType =
Strict::String
.constrained(included_in: DefaultDeliveryTypeValues.values)
.optional
.constructor(EnumConstructors.default)
ProjectStatusType =
Strict::String
.constrained(included_in: ProjectStatusTypes.values)
.optional
.constructor(EnumConstructors.default)
ArticleTypes =
Types::Strict::String.enum(
  'SERVICE', 'STOCK'
)
DiscountTypes =
Types::Strict::String.enum(
  'AMOUNT', 'PERCENT'
)
CURRENT_HOUSEWORK_TYPES =
%w[
  CONSTRUCTION ELECTRICITY GLASSMETALWORK GROUNDDRAINAGEWORK
  MASONRY PAINTINGWALLPAPERING HVAC MAJORAPPLIANCEREPAIR
  MOVINGSERVICES ITSERVICES CLEANING TEXTILECLOTHING
  SNOWPLOWING GARDENING BABYSITTING OTHERCARE OTHERCOSTS
].freeze
LEGACY_HOUSEWORK_TYPES =
%w[COOKING TUTORING].freeze
HouseworkTypes =
Types::Strict::String.enum(
  *(CURRENT_HOUSEWORK_TYPES + LEGACY_HOUSEWORK_TYPES)
)
Currencies =
Types::Strict::String.enum(
  'AED', 'AFN', 'ALL', 'AMD', 'ANG', 'AOA', 'ARS', 'AUD', 'AWG', 'AZN',
  'BAM', 'BBD', 'BDT', 'BGN', 'BHD', 'BIF', 'BMD', 'BND', 'BOB', 'BOV',
  'BRL', 'BSD', 'BTN', 'BWP', 'BYR', 'BZD', 'CAD', 'CDF', 'CHE', 'CHF',
  'CHW', 'CLF', 'CLP', 'CNY', 'COP', 'COU', 'CRC', 'CUP', 'CVE', 'CZK',
  'DJF', 'DKK', 'DOP', 'DZD', 'EGP', 'ERN', 'ETB', 'EUR', 'FJD', 'FKP',
  'GBP', 'GEL', 'GHS', 'GIP', 'GMD', 'GNF', 'GTQ', 'GYD', 'HKD', 'HNL',
  'HRK', 'HTG', 'HUF', 'IDR', 'ILS', 'INR', 'IQD', 'IRR', 'ISK', 'JMD',
  'JOD', 'JPY', 'KES', 'KGS', 'KHR', 'KUR', 'KMF', 'KPW', 'KRW', 'KWD',
  'KYD', 'KZT', 'LAK', 'LBP', 'LKR', 'LRD', 'LSL', 'LYD', 'MAD', 'MDL',
  'MGA', 'MKD', 'MMK', 'MNT', 'MOP', 'MRO', 'MUR', 'MVR', 'MWK', 'MXN',
  'MXV', 'MYR', 'MZN', 'NAD', 'NGN', 'NIO', 'NOK', 'NPR', 'NZD', 'OMR',
  'PAB', 'PEN', 'PGK', 'PHP', 'PKR', 'PLN', 'PYG', 'QAR', 'RON', 'RSD',
  'RUB', 'RWF', 'SAR', 'SBD', 'SCR', 'SDG', 'SEK', 'SGD', 'SHP', 'SLL',
  'SOS', 'SRD', 'SSP', 'STD', 'SYP', 'SZL', 'THB', 'TJS', 'TMM', 'TND',
  'TOP', 'TRY', 'TTD', 'TWD', 'TZS', 'UAH', 'UGX', 'USD', 'USN', 'USS',
  'UYU', 'UZS', 'VEF', 'VND', 'VUV', 'WST', 'XAF', 'XAG', 'XAU', 'XBA',
  'XBB', 'XBC', 'XBD', 'XCD', 'XDR', 'XFU', 'XOF', 'XPD', 'XPF', 'XPT',
  'XTS', 'XXX', 'YER', 'ZAR', 'ZMK', 'ZWD'
)
CustomerTypes =
Types::Strict::String.enum(
  'PRIVATE', 'COMPANY'
)
VATTypes =
Types::Strict::String.enum(
  'SEVAT', 'SEREVERSEDVAT', 'EUREVERSEDVAT', 'EUVAT', 'EXPORT'
)
DefaultDeliveryTypeValues =
Types::Strict::String.enum(
  'PRINT', 'EMAIL', 'PRINTSERVICE'
)
ProjectStatusTypes =
Types::Strict::String.enum(
  'NOTSTARTED', 'ONGOING', 'COMPLETED'
)