Class: Fortnox::Resource
- Inherits:
-
RestEasy::Resource
- Object
- RestEasy::Resource
- Fortnox::Resource
show all
- Includes:
- Types
- Defined in:
- lib/fortnox/resource.rb
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 Method Summary
collapse
Class Method Details
.find(id_or_hash) ⇒ Object
68
69
70
71
72
|
# File 'lib/fortnox/resource.rb', line 68
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
79
80
81
82
|
# File 'lib/fortnox/resource.rb', line 79
def find_all_by(hash)
response = get(path: config.path.to_s, params: hash)
parse(response)
end
|
.find_one_by(id) ⇒ Object
74
75
76
77
|
# File 'lib/fortnox/resource.rb', line 74
def find_one_by(id)
response = get(path: "#{config.path}/#{id}")
parse(response)
end
|
.only(filter) ⇒ Object
57
58
59
60
|
# File 'lib/fortnox/resource.rb', line 57
def only(filter)
response = get(path: config.path, params: { filter: })
parse(response)
end
|
.parse(response) ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/fortnox/resource.rb', line 41
def parse(response)
with_translated_errors do
= (response)
result = super
result.is_a?(Array) ? Collection.new(result, **) : result
end
end
|
.save(instance) ⇒ Object
53
54
55
|
# File 'lib/fortnox/resource.rb', line 53
def save(instance)
with_translated_errors { super }
end
|
.search(hash) ⇒ Object
62
63
64
65
66
|
# File 'lib/fortnox/resource.rb', line 62
def search(hash)
attribute, value = hash.first
response = get(path: config.path, params: { attribute => value })
parse(response)
end
|
.stub(**model_data) ⇒ Object
49
50
51
|
# File 'lib/fortnox/resource.rb', line 49
def stub(**model_data)
with_translated_errors { super }
end
|