class DarujmeCz::Base
Attributes
id[R]
Public Class Methods
all(**params)
click to toggle source
@param [Hash] params @option params [Integer] organization_id (nil) ID of organization
# File lib/darujme_cz/base.rb, line 11 def self.all(**params) where params end
base_path(params = {})
click to toggle source
# File lib/darujme_cz/base.rb, line 28 def self.base_path(params = {}) org = params.delete(:organization_id) || DarujmeCz.config.organization_id raise ArgumentError, "Missing organization ID" if org.nil? "organization/#{org}" end
connection(params = {})
click to toggle source
# File lib/darujme_cz/base.rb, line 20 def self.connection(params = {}) credentials = params.delete(:connection) || { app_id: DarujmeCz.config.app_id, api_key: DarujmeCz.config.app_secret } Connection.new credentials end
endpoint()
click to toggle source
@abstract Define name of endpoint, which is also name of root element
# File lib/darujme_cz/base.rb, line 5 def self.endpoint raise NotImplementedError end
new(attributes)
click to toggle source
@param [Hash] attributes
# File lib/darujme_cz/base.rb, line 38 def initialize(attributes) @source = attributes end
where(**params)
click to toggle source
# File lib/darujme_cz/base.rb, line 15 def self.where(**params) data = connection(params).get "#{base_path(params)}/#{endpoint}-by-filter", params data[endpoint].map { |i| new(i) } end
Private Class Methods
define_attributes(list)
click to toggle source
@param [Array<String>] list
# File lib/darujme_cz/base.rb, line 45 def self.define_attributes(list) list.each do |attribute| define_method attribute.underscore do @source[attribute] end end end