Class: XeroKiwi::Accounting::Organisation
- Inherits:
-
Object
- Object
- XeroKiwi::Accounting::Organisation
- Defined in:
- lib/xero_kiwi/accounting/organisation.rb
Overview
Represents a Xero Organisation (tenant) returned by the Accounting API.
See: developer.xero.com/documentation/api/accounting/organisation
Constant Summary collapse
- ATTRIBUTES =
{ organisation_id: "OrganisationID", api_key: "APIKey", name: "Name", legal_name: "LegalName", pays_tax: "PaysTax", version: "Version", organisation_type: "OrganisationType", base_currency: "BaseCurrency", country_code: "CountryCode", is_demo_company: "IsDemoCompany", organisation_status: "OrganisationStatus", registration_number: "RegistrationNumber", employer_identification_number: "EmployerIdentificationNumber", tax_number: "TaxNumber", financial_year_end_day: "FinancialYearEndDay", financial_year_end_month: "FinancialYearEndMonth", sales_tax_basis: "SalesTaxBasis", sales_tax_period: "SalesTaxPeriod", default_sales_tax: "DefaultSalesTax", default_purchases_tax: "DefaultPurchasesTax", period_lock_date: "PeriodLockDate", end_of_year_lock_date: "EndOfYearLockDate", created_date_utc: "CreatedDateUTC", timezone: "Timezone", organisation_entity_type: "OrganisationEntityType", short_code: "ShortCode", organisation_class: "Class", edition: "Edition", line_of_business: "LineOfBusiness", addresses: "Addresses", phones: "Phones", external_links: "ExternalLinks", payment_terms: "PaymentTerms" }.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #demo_company? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(attrs) ⇒ Organisation
constructor
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength.
- #inspect ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(attrs) ⇒ Organisation
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/xero_kiwi/accounting/organisation.rb', line 58 def initialize(attrs) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength attrs = attrs.transform_keys(&:to_s) @organisation_id = attrs["OrganisationID"] @api_key = attrs["APIKey"] @name = attrs["Name"] @legal_name = attrs["LegalName"] @pays_tax = attrs["PaysTax"] @version = attrs["Version"] @organisation_type = attrs["OrganisationType"] @base_currency = attrs["BaseCurrency"] @country_code = attrs["CountryCode"] @is_demo_company = attrs["IsDemoCompany"] @organisation_status = attrs["OrganisationStatus"] @registration_number = attrs["RegistrationNumber"] @employer_identification_number = attrs["EmployerIdentificationNumber"] @tax_number = attrs["TaxNumber"] @financial_year_end_day = attrs["FinancialYearEndDay"] @financial_year_end_month = attrs["FinancialYearEndMonth"] @sales_tax_basis = attrs["SalesTaxBasis"] @sales_tax_period = attrs["SalesTaxPeriod"] @default_sales_tax = attrs["DefaultSalesTax"] @default_purchases_tax = attrs["DefaultPurchasesTax"] @period_lock_date = parse_time(attrs["PeriodLockDate"]) @end_of_year_lock_date = parse_time(attrs["EndOfYearLockDate"]) @created_date_utc = parse_time(attrs["CreatedDateUTC"]) @timezone = attrs["Timezone"] @organisation_entity_type = attrs["OrganisationEntityType"] @short_code = attrs["ShortCode"] @organisation_class = attrs["Class"] @edition = attrs["Edition"] @line_of_business = attrs["LineOfBusiness"] @addresses = (attrs["Addresses"] || []).map { |a| Address.new(a) } @phones = (attrs["Phones"] || []).map { |p| Phone.new(p) } @external_links = (attrs["ExternalLinks"] || []).map { |l| ExternalLink.new(l) } @payment_terms = PaymentTerms.from_hash(attrs["PaymentTerms"]) end |
Class Method Details
.from_response(payload) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/xero_kiwi/accounting/organisation.rb', line 49 def self.from_response(payload) return nil if payload.nil? items = payload["Organisations"] return nil if items.nil? || items.empty? new(items.first) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
101 102 103 |
# File 'lib/xero_kiwi/accounting/organisation.rb', line 101 def ==(other) other.is_a?(Organisation) && other.organisation_id == organisation_id end |
#demo_company? ⇒ Boolean
95 |
# File 'lib/xero_kiwi/accounting/organisation.rb', line 95 def demo_company? = is_demo_company == true |
#hash ⇒ Object
106 |
# File 'lib/xero_kiwi/accounting/organisation.rb', line 106 def hash = [self.class, organisation_id].hash |
#inspect ⇒ Object
108 109 110 111 |
# File 'lib/xero_kiwi/accounting/organisation.rb', line 108 def inspect "#<#{self.class} organisation_id=#{organisation_id.inspect} " \ "name=#{name.inspect} organisation_type=#{organisation_type.inspect}>" end |
#to_h ⇒ Object
97 98 99 |
# File 'lib/xero_kiwi/accounting/organisation.rb', line 97 def to_h ATTRIBUTES.keys.to_h { |key| [key, public_send(key)] } end |