Class: Fortnox::Resource

Inherits:
RestEasy::Resource
  • Object
show all
Includes:
Types
Defined in:
lib/fortnox/resource.rb

Direct Known Subclasses

Article, Customer, Document, Label, Project, TermsOfPayment, Unit

Constant Summary

Constants included from Types

Types::AccountNumber, Types::AccountingMethods, Types::ArticleTypes, Types::CURRENT_HOUSEWORK_TYPES, Types::Currencies, Types::CustomerTypes, Types::DefaultDeliveryTypeValues, Types::DeliveryStates, Types::DiscountTypes, Types::Email, Types::HouseworkTypes, Types::InvoiceTypes, Types::LEGACY_HOUSEWORK_TYPES, Types::PaymentWays, Types::ProjectStatusTypes, Types::THE_TRUTH, Types::TaxReductionTypes, Types::VATTypes

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.registered_resourcesObject (readonly)

Returns the value of attribute registered_resources.



44
45
46
# File 'lib/fortnox/resource.rb', line 44

def registered_resources
  @registered_resources
end

Class Method Details

.find(id_or_hash) ⇒ Object



78
79
80
81
82
# File 'lib/fortnox/resource.rb', line 78

def find(id_or_hash)
  return find_all_by(id_or_hash) if id_or_hash.is_a? Hash

  find_one_by(id_or_hash)
end

.find_all_by(hash) ⇒ Object



89
90
91
92
# File 'lib/fortnox/resource.rb', line 89

def find_all_by(hash)
  response = get(path: config.path.to_s, params: hash)
  parse(response)
end

.find_one_by(id) ⇒ Object



84
85
86
87
# File 'lib/fortnox/resource.rb', line 84

def find_one_by(id)
  response = get(path: "#{config.path}/#{id}")
  parse(response)
end

.inherited(subclass) ⇒ Object



46
47
48
49
# File 'lib/fortnox/resource.rb', line 46

def inherited(subclass)
  super
  Fortnox::Resource.registered_resources << subclass
end

.only(filter) ⇒ Object



67
68
69
70
# File 'lib/fortnox/resource.rb', line 67

def only(filter)
  response = get(path: config.path, params: { filter: })
  parse(response)
end

.parse(response) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/fortnox/resource.rb', line 51

def parse(response)
  with_translated_errors do
    pagination = extract_pagination(response)
    result = super
    result.is_a?(Array) ? Collection.new(result, **pagination) : result
  end
end

.save(instance) ⇒ Object



63
64
65
# File 'lib/fortnox/resource.rb', line 63

def save(instance)
  with_translated_errors { super }
end

.search(hash) ⇒ Object



72
73
74
75
76
# File 'lib/fortnox/resource.rb', line 72

def search(hash)
  attribute, value = hash.first
  response = get(path: config.path, params: { attribute => value })
  parse(response)
end

.stub(**model_data) ⇒ Object



59
60
61
# File 'lib/fortnox/resource.rb', line 59

def stub(**model_data)
  with_translated_errors { super }
end