Class: Fortnox::API::Repository::Base
- Inherits:
-
Object
- Object
- Fortnox::API::Repository::Base
- Includes:
- Loaders, Savers, Fortnox::API::RequestHandling, HTTParty
- Defined in:
- lib/fortnox/api/repositories/base.rb
Constant Summary collapse
- HTTP_METHODS =
%i[get put post delete].freeze
Instance Attribute Summary collapse
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#keys_filtered_on_save ⇒ Object
readonly
Returns the value of attribute keys_filtered_on_save.
-
#mapper ⇒ Object
readonly
Returns the value of attribute mapper.
Class Method Summary collapse
-
.set_headers(headers = {}) ⇒ Object
rubocop:disable Naming/AccessorMethodName.
Instance Method Summary collapse
- #access_tokens ⇒ Object
- #check_access_tokens!(tokens) ⇒ Object
-
#initialize(keys_filtered_on_save: [:url], token_store: :default) ⇒ Base
constructor
A new instance of Base.
- #next_access_token ⇒ Object
Methods included from Savers
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], token_store: :default) ⇒ Base
Returns a new instance of Base.
46 47 48 49 50 |
# File 'lib/fortnox/api/repositories/base.rb', line 46 def initialize(keys_filtered_on_save: [:url], token_store: :default) @keys_filtered_on_save = keys_filtered_on_save @token_store = token_store @mapper = Registry[Mapper::Base.canonical_name_sym(self.class::MODEL)].new end |
Instance Attribute Details
#headers ⇒ Object
Returns the value of attribute headers.
26 27 28 |
# File 'lib/fortnox/api/repositories/base.rb', line 26 def headers @headers end |
#keys_filtered_on_save ⇒ Object (readonly)
Returns the value of attribute keys_filtered_on_save.
27 28 29 |
# File 'lib/fortnox/api/repositories/base.rb', line 27 def keys_filtered_on_save @keys_filtered_on_save end |
#mapper ⇒ Object (readonly)
Returns the value of attribute mapper.
27 28 29 |
# File 'lib/fortnox/api/repositories/base.rb', line 27 def mapper @mapper end |
Class Method Details
.set_headers(headers = {}) ⇒ Object
rubocop:disable Naming/AccessorMethodName
29 30 31 |
# File 'lib/fortnox/api/repositories/base.rb', line 29 def self.set_headers(headers = {}) # rubocop:disable Naming/AccessorMethodName self.headers.merge!(headers) end |
Instance Method Details
#access_tokens ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/fortnox/api/repositories/base.rb', line 64 def access_tokens begin tokens = config.token_store.fetch(@token_store) rescue KeyError token_store_not_found!(@token_store.inspect) end check_access_tokens!(tokens) tokens end |
#check_access_tokens!(tokens) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/fortnox/api/repositories/base.rb', line 57 def check_access_tokens!(tokens) tokens_present = !(tokens.nil? || tokens.empty?) return if tokens_present = "You have not provided any access tokens in token store #{@token_store.inspect}." raise MissingConfiguration, end |
#next_access_token ⇒ Object
52 53 54 55 |
# File 'lib/fortnox/api/repositories/base.rb', line 52 def next_access_token @access_tokens ||= CircularQueue.new(*access_tokens) @access_tokens.next end |