Class: Warrant::Object
- Inherits:
-
Object
- Object
- Warrant::Object
- Defined in:
- lib/warrant/models/object.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#object_id ⇒ Object
readonly
Returns the value of attribute object_id.
-
#object_type ⇒ Object
readonly
Returns the value of attribute object_type.
Class Method Summary collapse
-
.batch_create(objects, options = {}) ⇒ Array<Object>
Batch creates multiple objects with given parameters.
-
.batch_delete(objects, options = {}) ⇒ nil
Batch deletes multiple objects with given parameters.
-
.create(params = {}, options = {}) ⇒ Object
Creates an object with the given parameters.
-
.delete(object_type, object_id, options = {}) ⇒ nil
Deletes a object with given object type and id.
-
.get(object_type, object_id, options = {}) ⇒ Object
Get a object with the given object_type and object_id.
-
.list(filters = {}, options = {}) ⇒ Array<Object>
Lists all objects for your organization and environment.
-
.update(object_type, object_id, meta, options = {}) ⇒ Object
Updates a object with the given object_type and object_id and params.
Instance Method Summary collapse
-
#update(meta, options = {}) ⇒ Object
Updates a object with the given object_type and object_id and params.
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
5 6 7 |
# File 'lib/warrant/models/object.rb', line 5 def created_at @created_at end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
5 6 7 |
# File 'lib/warrant/models/object.rb', line 5 def @meta end |
#object_id ⇒ Object (readonly)
Returns the value of attribute object_id.
5 6 7 |
# File 'lib/warrant/models/object.rb', line 5 def object_id @object_id end |
#object_type ⇒ Object (readonly)
Returns the value of attribute object_type.
5 6 7 |
# File 'lib/warrant/models/object.rb', line 5 def object_type @object_type end |
Class Method Details
.batch_create(objects, options = {}) ⇒ Array<Object>
Batch creates multiple objects with given parameters
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/warrant/models/object.rb', line 62 def self.batch_create(objects, = {}) res = APIOperations.post(URI.parse("#{::Warrant.config.api_base}/v2/objects"), params: Util.normalize_params(objects), options: ) case res when Net::HTTPSuccess objects = JSON.parse(res.body, symbolize_names: true) objects.map{ |object| Object.new(object[:objectType], object[:objectId], object[:meta], object[:createdAt]) } else APIOperations.raise_error(res) end end |
.batch_delete(objects, options = {}) ⇒ nil
Batch deletes multiple objects with given parameters
114 115 116 117 118 119 120 121 122 123 |
# File 'lib/warrant/models/object.rb', line 114 def self.batch_delete(objects, = {}) res = APIOperations.delete(URI.parse("#{::Warrant.config.api_base}/v2/objects"), params: Util.normalize_params(objects), options: ) case res when Net::HTTPSuccess return res['Warrant-Token'] else APIOperations.raise_error(res) end end |
.create(params = {}, options = {}) ⇒ Object
Creates an object with the given parameters
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/warrant/models/object.rb', line 32 def self.create(params = {}, = {}) res = APIOperations.post(URI.parse("#{::Warrant.config.api_base}/v2/objects"), params: Util.normalize_params(params), options: ) case res when Net::HTTPSuccess res_json = JSON.parse(res.body, symbolize_names: true) Object.new(res_json[:objectType], res_json[:objectId], res_json[:meta], res_json[:createdAt]) else APIOperations.raise_error(res) end end |
.delete(object_type, object_id, options = {}) ⇒ nil
Deletes a object with given object type and id
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/warrant/models/object.rb', line 88 def self.delete(object_type, object_id, = {}) res = APIOperations.delete(URI.parse("#{::Warrant.config.api_base}/v2/objects/#{object_type}/#{object_id}"), options: ) case res when Net::HTTPSuccess return res['Warrant-Token'] else APIOperations.raise_error(res) end end |
.get(object_type, object_id, options = {}) ⇒ Object
Get a object with the given object_type and object_id
168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/warrant/models/object.rb', line 168 def self.get(object_type, object_id, = {}) res = APIOperations.get(URI.parse("#{::Warrant.config.api_base}/v2/objects/#{object_type}/#{object_id}"), options: ) case res when Net::HTTPSuccess object = JSON.parse(res.body, symbolize_names: true) Object.new(object[:objectType], object[:objectId], object[:meta], object[:createdAt]) else APIOperations.raise_error(res) end end |
.list(filters = {}, options = {}) ⇒ Array<Object>
Lists all objects for your organization and environment
145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/warrant/models/object.rb', line 145 def self.list(filters = {}, = {}) res = APIOperations.get(URI.parse("#{::Warrant.config.api_base}/v2/objects"), params: Util.normalize_params(filters), options: ) case res when Net::HTTPSuccess list_result = JSON.parse(res.body, symbolize_names: true) objects = list_result[:results].map{ |object| Object.new(object[:objectType], object[:objectId], object[:meta], object[:createdAt]) } return ListResponse.new(objects, list_result[:prevCursor], list_result[:nextCursor]) else APIOperations.raise_error(res) end end |
.update(object_type, object_id, meta, options = {}) ⇒ Object
Updates a object with the given object_type and object_id and params
196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/warrant/models/object.rb', line 196 def self.update(object_type, object_id, , = {}) params = { meta: , } res = APIOperations.put(URI.parse("#{::Warrant.config.api_base}/v2/objects/#{object_type}/#{object_id}"), params: Util.normalize_params(params), options: ) case res when Net::HTTPSuccess res_json = JSON.parse(res.body, symbolize_names: true) Object.new(res_json[:objectType], res_json[:objectId], res_json[:meta], res_json[:createdAt]) else APIOperations.raise_error(res) end end |