class LegacyInfusionsoftApi::Model::Base
Public Class Methods
new(client, model_name)
click to toggle source
# File lib/legacy_infusionsoft_api/models/base.rb, line 3 def initialize(client, model_name) @client = client @model_name = model_name || "Base" end
Public Instance Methods
all(query = {}, paginate = true, per_page = 1000, page_number = 0)
click to toggle source
# File lib/legacy_infusionsoft_api/models/base.rb, line 8 def all(query = {}, paginate = true, per_page = 1000, page_number = 0) per_page = [per_page, 1000].min results = @client.connection.call("DataService.query", @client.api_key, self.table_name, per_page, page_number, query, self.fields) results.length > 0 && paginate ? results + self.all(query, true, per_page, page_number + 1) : results end
count(query={})
click to toggle source
# File lib/legacy_infusionsoft_api/models/base.rb, line 43 def count(query={}) @client.connection.call("DataService.count", @client.api_key, self.table_name, query) end
create(data = {})
click to toggle source
# File lib/legacy_infusionsoft_api/models/base.rb, line 30 def create(data = {}) data["Id"] = @client.connection.call("DataService.add", @client.api_key, self.table_name, data) data end
delete(query)
click to toggle source
# File lib/legacy_infusionsoft_api/models/base.rb, line 35 def delete(query) if query.is_a?(Hash) self.all(query).each { |data| self.delete(data["Id"]) } else @client.connection.call("DataService.delete", @client.api_key, self.table_name, query) end end
fields()
click to toggle source
# File lib/legacy_infusionsoft_api/models/base.rb, line 51 def fields [] end
find_each(query = {}, paginate = true, per_page = 1000, page_number = 0) { |results| ... }
click to toggle source
# File lib/legacy_infusionsoft_api/models/base.rb, line 14 def find_each(query = {}, paginate = true, per_page = 1000, page_number = 0, &block) per_page = [per_page, 1000].min results = @client.connection.call("DataService.query", @client.api_key, self.table_name, per_page, page_number, query, self.fields) yield results return self.find_each(query, true, per_page, page_number + 1, &block) if results.length > 0 && paginate true end
first(query = {})
click to toggle source
# File lib/legacy_infusionsoft_api/models/base.rb, line 26 def first(query = {}) self.all(query, false, 1)[0] end
load(id)
click to toggle source
# File lib/legacy_infusionsoft_api/models/base.rb, line 22 def load(id) @client.connection.call("DataService.load", @client.api_key, self.table_name, id, self.fields) end
table_name()
click to toggle source
# File lib/legacy_infusionsoft_api/models/base.rb, line 47 def table_name @model_name end