Class: ThisData::Rule
- Inherits:
-
Object
- Object
- ThisData::Rule
- Defined in:
- lib/this_data/rule.rb
Class Method Summary collapse
-
.all(options = {}) ⇒ Object
Fetch an array of Rules from the ThisData API Available options can be found at help.thisdata.com/docs/v1rules.
-
.create(rule, options = {}) ⇒ Object
Create a new rule on the ThisData API Available options can be found at help.thisdata.com/docs/v1rules-1.
-
.destroy(id, options = {}) ⇒ Object
Delete a rule on the ThisData API Available options can be found at help.thisdata.com/docs/v1rulesid-2.
-
.find(id, options = {}) ⇒ Object
Fetch an array of Rules from the ThisData API Available options can be found at help.thisdata.com/docs/v1rules.
-
.update(rule, options = {}) ⇒ Object
Update a rule on the ThisData API Available options can be found at help.thisdata.com/docs/v1rulesid-1.
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(={}) response = ThisData::Client.new.get(ThisData::RULES_ENDPOINT, query: ) 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, ={}) response = ThisData::Client.new.post(ThisData::RULES_ENDPOINT, body: JSON.generate(rule), query: ) 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, ={}) response = ThisData::Client.new.delete("#{ThisData::RULES_ENDPOINT}/#{id}", query: ) 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, ={}) response = ThisData::Client.new.get("#{ThisData::RULES_ENDPOINT}/#{id}", query: ) 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, ={}) rule_id = OpenStruct.new(rule).id response = ThisData::Client.new.post("#{ThisData::RULES_ENDPOINT}/#{rule_id}", body: JSON.generate(rule), query: ) OpenStruct.new(response.parsed_response) end |