Class: CirroIO::Client::Base

Inherits:
JsonApiClient::Resource
  • Object
show all
Defined in:
lib/cirro_io/client/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Base

HACK: github.com/JsonApiClient/json_api_client/issues/390 waiting for json_api_client to release a new version with the fix github.com/JsonApiClient/json_api_client/pull/398 rubocop:disable all



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/cirro_io/client/base.rb', line 36

def initialize(params = {})
  params = params.with_indifferent_access
  @persisted = nil
  @destroyed = nil
  self.links = self.class.linker.new(params.delete(:links) || {})
  self.relationships = self.class.relationship_linker.new(self.class, params.delete(:relationships) || {})
  self.attributes = self.class.default_attributes.merge params.except(*self.class.prefix_params)
  self.forget_change!(:type)
  self.__belongs_to_params = params.slice(*self.class.prefix_params)

  setup_default_properties

  self.request_params = self.class.request_params_class.new(self.class)
end

Class Method Details

.custom_connectionObject



23
24
25
26
27
28
29
30
# File 'lib/cirro_io/client/base.rb', line 23

def self.custom_connection
  Faraday.new(url: "#{CirroIO::Client.configuration.site}/#{CirroIO::Client.configuration.api_version}") do |conn|
    conn.request :json
    conn.response :json
    conn.use CirroIO::Client::JwtAuthentication
    conn.use JsonApiClient::Middleware::Status, {}
  end
end

.custom_post(endpoint, payload) ⇒ Object



19
20
21
# File 'lib/cirro_io/client/base.rb', line 19

def self.custom_post(endpoint, payload)
  custom_connection.post(endpoint, payload.to_json)
end

.site=(url) ⇒ Object

HACK: github.com/JsonApiClient/json_api_client/issues/215 Used for initialization as well



9
10
11
12
13
14
15
16
17
# File 'lib/cirro_io/client/base.rb', line 9

def self.site=(url)
  super.tap do
    connection true do |connection|
      connection.use JwtAuthentication
      connection.use Faraday::Response::Logger
      # connection.use ResponseDebuggingMiddleware # for debugging or while adding new specs
    end
  end
end