module Evvnt::ClassTemplateMethods

Internal: Template methods to provide default behaviour for API actions.

These are defined on Evvnt::Base subclasses where required to map the Evvnt API actions.

Constants

PARAM_REGEX

Regular expression for params in URL strings

Public Instance Methods

create(**params) click to toggle source

Template method for creating a new record on the API.

params - A Hash of params to send to the API.

Returns {Evvnt::Base} subclass

# File lib/evvnt/class_template_methods.rb, line 18
def create(**params)
  path = nest_path_within_parent(plural_resource_path, params)
  api_request(:post, path, params: params)
end
index(**params) click to toggle source

Template method for fetching an index of record from the API.

params - A Hash of params to send to the API.

Returns Array

# File lib/evvnt/class_template_methods.rb, line 28
def index(**params)
  params.stringify_keys!
  path = nest_path_within_parent(plural_resource_path, params)
  api_request(:get, path, params: params)
end
mine(**params) click to toggle source

Template method for fetching mine records from the API.

params - A Hash of params to send to the API.

Returns Array

# File lib/evvnt/class_template_methods.rb, line 81
def mine(**params)
  path = File.join(plural_resource_path, "mine").to_s
  api_request(:get, path, params: params)
end
ours(record_id = nil, **params) click to toggle source

Template method for fetching mine records from the API.

record_id - An Integer or String representing the record ID on the API (optional). params - A Hash of params to send to the API.

Returns Array Returns {Evvnt::Base}

# File lib/evvnt/class_template_methods.rb, line 69
def ours(record_id = nil, **params)
  id_segment = record_id.to_s
  segments   = [plural_resource_path, "ours", id_segment].select(&:present?)
  path       = File.join(*segments).to_s
  api_request(:get, path, params: params)
end
show(record_id = nil, **params) click to toggle source

Template method for creating a given record

record_id - An Integer or String representing the record ID on the API. params - A Hash of params to send to the API.

Returns {Evvnt::Base} subclass

# File lib/evvnt/class_template_methods.rb, line 40
def show(record_id = nil, **params)
  if record_id.nil? && !singular_resource?
    raise ArgumentError, "record_id cannot be nil"
  end
  path = nest_path_within_parent(singular_path_for_record(record_id, params), params)
  api_request(:get, path, params: params)
end
update(record_id, **params) click to toggle source

Template method for updating a given record

record_id - An Integer or String representing the record ID on the API. params - A Hash of params to send to the API.

Returns {Evvnt::Base} subclass

# File lib/evvnt/class_template_methods.rb, line 54
def update(record_id, **params)
  if record_id.nil? && !singular_resource?
    raise ArgumentError, "record_id cannot be nil"
  end
  path = nest_path_within_parent(singular_path_for_record(record_id, params), params)
  api_request(:put, path, params: params)
end