class Infusionsoft::Api::Model::Base

Public Class Methods

new(client, model_name) click to toggle source
# File lib/infusionsoft/api/models/base.rb, line 6
def initialize(client, model_name)
  @client     = client
  @model_name = model_name || 'Base'
end

Public Instance Methods

all(query = {}, paginate = true, page_number = 0) click to toggle source
# File lib/infusionsoft/api/models/base.rb, line 11
def all(query = {}, paginate = true, page_number = 0)
  results = @client.connection.call('DataService.query', @client.api_key, self.table_name, 1000, page_number, query, self.fields)
  results.length > 0 && paginate ? results + self.all(query, true, page_number + 1) : results
end
create(data = {}) click to toggle source
# File lib/infusionsoft/api/models/base.rb, line 20
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/infusionsoft/api/models/base.rb, line 25
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/infusionsoft/api/models/base.rb, line 37
def fields
  []
end
first(query = {}) click to toggle source
# File lib/infusionsoft/api/models/base.rb, line 16
def first(query = {})
  self.all(query, false)[0]
end
table_name() click to toggle source
# File lib/infusionsoft/api/models/base.rb, line 33
def table_name
  @model_name
end