Class: FrederickAPI::V2::Resource

Inherits:
JsonApiClient::Resource
  • Object
show all
Includes:
Helpers::HasMany
Defined in:
lib/frederick_api/v2/resource.rb

Overview

Class from which Frederick V2 Resources inherit Inherits functionality from JsonApiClient::Resource

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Resource

Returns a new instance of Resource.



17
18
19
20
# File 'lib/frederick_api/v2/resource.rb', line 17

def initialize(params = {})
  self.custom_headers = self.class.custom_headers
  super
end

Instance Attribute Details

#custom_headersObject

Returns the value of attribute custom_headers.



15
16
17
# File 'lib/frederick_api/v2/resource.rb', line 15

def custom_headers
  @custom_headers
end

Class Method Details

._header_storeObject



57
58
59
# File 'lib/frederick_api/v2/resource.rb', line 57

def self._header_store
  Thread.current['frederick_api_header_store'] ||= {}
end

.all_recordsObject



26
27
28
# File 'lib/frederick_api/v2/resource.rb', line 26

def self.all_records
  self.all.pages.all_records
end

.custom_headersObject



53
54
55
# File 'lib/frederick_api/v2/resource.rb', line 53

def self.custom_headers
  super.merge(x_api_key: top_level_namespace.config.api_key)
end

.siteObject



34
35
36
# File 'lib/frederick_api/v2/resource.rb', line 34

def self.site
  "#{top_level_namespace.config.base_url}/v2/"
end

.top_level_namespaceObject



30
31
32
# File 'lib/frederick_api/v2/resource.rb', line 30

def self.top_level_namespace
  @top_level_namespace ||= self.to_s.split('::').first.constantize
end

.with_access_token(token) ⇒ Object



38
39
40
41
42
# File 'lib/frederick_api/v2/resource.rb', line 38

def self.with_access_token(token)
  with_access_token_and_headers(token) do
    yield
  end
end

.with_access_token_and_headers(token, headers = {}) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/frederick_api/v2/resource.rb', line 44

def self.with_access_token_and_headers(token, headers = {})
  with_headers(
    authorization: "Bearer #{token}",
    **headers
  ) do
    yield
  end
end

Instance Method Details

#has_errors?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/frederick_api/v2/resource.rb', line 22

def has_errors?
  self.errors.present?
end