Class: ThisData::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/this_data/rule.rb

Class Method Summary collapse

Class Method Details

.all(options = {}) ⇒ Object

Fetch an array of Rules from the ThisData API Available options can be found at

http://help.thisdata.com/docs/v1rules

Returns: Array of OpenStruct Rule objects



23
24
25
26
27
28
# File 'lib/this_data/rule.rb', line 23

def self.all(options={})
  response = ThisData::Client.new.get(ThisData::RULES_ENDPOINT, query: options)
  response.parsed_response.collect do |rule_hash|
    OpenStruct.new(rule_hash)
  end
end

.create(rule, options = {}) ⇒ Object

Create a new rule on the ThisData API Available options can be found at

http://help.thisdata.com/docs/v1rules-1

Returns: OpenStruct Rule object



35
36
37
38
# File 'lib/this_data/rule.rb', line 35

def self.create(rule, options={})
  response = ThisData::Client.new.post(ThisData::RULES_ENDPOINT, body: JSON.generate(rule), query: options)
  OpenStruct.new(response.parsed_response)
end

.destroy(id, options = {}) ⇒ Object

Delete a rule on the ThisData API Available options can be found at

http://help.thisdata.com/docs/v1rulesid-2

Returns: OpenStruct Rule object



56
57
58
59
# File 'lib/this_data/rule.rb', line 56

def self.destroy(id, options={})
  response = ThisData::Client.new.delete("#{ThisData::RULES_ENDPOINT}/#{id}", query: options)
  response.code.eql?(204)
end

.find(id, options = {}) ⇒ Object

Fetch an array of Rules from the ThisData API Available options can be found at

http://help.thisdata.com/docs/v1rules

Returns: Array of OpenStruct Rule objects



13
14
15
16
# File 'lib/this_data/rule.rb', line 13

def self.find(id, options={})
  response = ThisData::Client.new.get("#{ThisData::RULES_ENDPOINT}/#{id}", query: options)
  OpenStruct.new( response.parsed_response)
end

.update(rule, options = {}) ⇒ Object

Update a rule on the ThisData API Available options can be found at

http://help.thisdata.com/docs/v1rulesid-1

Returns: OpenStruct Rule object



45
46
47
48
49
# File 'lib/this_data/rule.rb', line 45

def self.update(rule, options={})
  rule_id = OpenStruct.new(rule).id
  response = ThisData::Client.new.post("#{ThisData::RULES_ENDPOINT}/#{rule_id}", body: JSON.generate(rule), query: options)
  OpenStruct.new(response.parsed_response)
end