Class: Malartu::Tracking::Data
- Inherits:
-
MalartuObject
- Object
- MalartuObject
- Malartu::Tracking::Data
- Defined in:
- lib/malartu/tracking/data.rb
Overview
Tracking::Data lets you store data is the Malartu system
Instance Attribute Summary
Attributes inherited from MalartuObject
Class Method Summary collapse
- .create(topic: nil, value: 1) ⇒ Object
- .find(id) ⇒ Object
- .list(starting:, ending:, page: 1, paginate: false, topic: nil) ⇒ Object
- .update(id, topic: nil, value: 1) ⇒ Object
Methods inherited from MalartuObject
Constructor Details
This class inherits a constructor from Malartu::MalartuObject
Class Method Details
.create(topic: nil, value: 1) ⇒ Object
5 6 7 8 9 |
# File 'lib/malartu/tracking/data.rb', line 5 def self.create(topic: nil, value: 1) fail 'No topic' if topic.nil? res = Malartu.request('post', '/kpi/tracking/data', topic: topic, value: value) Malartu::Tracking::Data.new(res) end |
.find(id) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/malartu/tracking/data.rb', line 11 def self.find(id) fail 'No ID given' if id.nil? path = "/kpi/tracking/data/#{id}" res = Malartu.request('get', path) Malartu::Tracking::Data.new(res) end |
.list(starting:, ending:, page: 1, paginate: false, topic: nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/malartu/tracking/data.rb', line 18 def self.list(starting:, ending:, page: 1, paginate: false, topic: nil) params = { starting: starting, ending: ending, topic: topic, page: page }.select { |_, value| !value.nil? } res = Malartu.request('get', '/kpi/tracking/data', params) data = res['data'].map do |datum| Malartu::Tracking::Data.new(datum) end page = res["page"].to_i return data unless paginate?(res) # Paginated requests res = Malartu.request('get', '/kpi/tracking/data', params.merge(page: page + 1)) data + res['data'] end |
.update(id, topic: nil, value: 1) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/malartu/tracking/data.rb', line 31 def self.update(id, topic: nil, value: 1) fail 'No Topic' if topic.nil? params = {} params[:topic] = topic unless topic.nil? params[:value] = value unless value.nil? fail 'No parameters to send' if params == {} path = "/kpi/tracking/data/#{id}" res = Malartu.request('patch', path, params) Malartu::Tracking::Data.new(res) end |