Class: Infusionsoft::Api::Model::Base
- Inherits:
-
Object
- Object
- Infusionsoft::Api::Model::Base
show all
- Defined in:
- lib/infusionsoft/api/models/base.rb
Instance Method Summary
collapse
Constructor Details
#initialize(client, model_name) ⇒ Base
Returns a new instance of Base.
6
7
8
9
|
# File 'lib/infusionsoft/api/models/base.rb', line 6
def initialize(client, model_name)
@client = client
@model_name = model_name || 'Base'
end
|
Instance Method Details
#all(query = {}, paginate = true, page_number = 0) ⇒ Object
11
12
13
14
|
# 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 = {}) ⇒ Object
20
21
22
23
|
# 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) ⇒ Object
25
26
27
28
29
30
31
|
# 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 ⇒ Object
37
38
39
|
# File 'lib/infusionsoft/api/models/base.rb', line 37
def fields
[]
end
|
#first(query = {}) ⇒ Object
16
17
18
|
# File 'lib/infusionsoft/api/models/base.rb', line 16
def first(query = {})
self.all(query, false)[0]
end
|
#table_name ⇒ Object
33
34
35
|
# File 'lib/infusionsoft/api/models/base.rb', line 33
def table_name
@model_name
end
|