Sha256: b1034df3b015708a9525b52d220fb7f3f7ebe242d4a4235313eb191cc7bd00c0
Contents?: true
Size: 1.23 KB
Versions: 3
Compression:
Stored size: 1.23 KB
Contents
# frozen_string_literal: true module ActiveCampaign class Model # :nodoc: include ActiveModel::Model include ActiveModel::Dirty include ActiveCampaign::ApiHttp include ActiveCampaign::Attributes class << self def all get endpoint end def filter(args = {}) query = args.map { |k, v| "filters[#{k}]=#{v}" }.join "&" get "#{endpoint}?#{query}" end def find_by(args = {}) filter(args).last end def find(id) get "#{endpoint}/#{id}" end def save(**args) new(args).save end def create(**args) new(args).create end end def save return update if defined?(id) && id.present? create end def update return nil unless changed? result = self.class.put "#{self.class.endpoint}/#{id}", only_changes_to_params assign_attributes result.to_params.first.last changes_applied self end def create result = self.class.post self.class.endpoint, to_params assign_attributes result.to_params.first.last changes_applied self end def destroy self.class.delete "#{self.class.endpoint}/#{id}" end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
ractive_campaign-0.1.6 | lib/active_campaign/models/model.rb |
ractive_campaign-0.1.5 | lib/active_campaign/models/model.rb |
ractive_campaign-0.1.4 | lib/active_campaign/models/model.rb |