Class: Fortnox::API::Repository::Base

Inherits:
Object
  • Object
show all
Includes:
Loaders, Savers, Fortnox::API::RequestHandling, HTTParty
Defined in:
lib/fortnox/api/repositories/base.rb

Direct Known Subclasses

Article, Customer, Invoice, Order, Project, TermsOfPayment, Unit

Constant Summary collapse

HTTP_METHODS =
%i[get put post delete].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Savers

#save

Methods included from Loaders

#all, #escape, #find, #find_all_by, #find_one_by, #only, #search, #to_query

Constructor Details

#initialize(keys_filtered_on_save: [:url]) ⇒ Base

Returns a new instance of Base.

Raises:



51
52
53
54
55
56
57
58
59
# File 'lib/fortnox/api/repositories/base.rb', line 51

def initialize(keys_filtered_on_save: [:url])
  @keys_filtered_on_save = keys_filtered_on_save
  @mapper = Registry[Mapper::Base.canonical_name_sym(self.class::MODEL)].new
  return unless access_token.nil?

  raise MissingAccessToken,
        'No Access Token provided! You need to provide an Access Token: ' \
        'Fortnox::API.access_token = token'
end

Instance Attribute Details

#headersObject

Returns the value of attribute headers.



29
30
31
# File 'lib/fortnox/api/repositories/base.rb', line 29

def headers
  @headers
end

#keys_filtered_on_saveObject (readonly)

Returns the value of attribute keys_filtered_on_save.



30
31
32
# File 'lib/fortnox/api/repositories/base.rb', line 30

def keys_filtered_on_save
  @keys_filtered_on_save
end

#mapperObject (readonly)

Returns the value of attribute mapper.



30
31
32
# File 'lib/fortnox/api/repositories/base.rb', line 30

def mapper
  @mapper
end

Class Method Details

.set_headers(headers = {}) ⇒ Object



32
33
34
# File 'lib/fortnox/api/repositories/base.rb', line 32

def self.set_headers(headers = {})
  self.headers.merge!(headers)
end