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.



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

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

Instance Attribute Details

#custom_headersObject

Returns the value of attribute custom_headers.



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

def custom_headers
  @custom_headers
end

Class Method Details

._header_storeObject



47
48
49
# File 'lib/frederick_api/v2/resource.rb', line 47

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

.all_recordsObject



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

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

.custom_headersObject



43
44
45
# File 'lib/frederick_api/v2/resource.rb', line 43

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

.siteObject



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

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

.top_level_namespaceObject



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

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

.with_access_token(token) ⇒ Object



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

def self.with_access_token(token)
  with_headers(authorization: "Bearer #{token}") do
    yield
  end
end

Instance Method Details

#has_errors?Boolean

Returns:

  • (Boolean)


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

def has_errors?
  self.errors.present?
end