Class: KakaxiParse::FarmManagerUser
Constant Summary
Constants inherited
from BaseModel
BaseModel::DEFUALT_LIMIT
Instance Attribute Summary
Attributes inherited from BaseModel
#created_at, #id, #name, #updated_at
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from BaseModel
#delete, demodulize, find, order, #update
Constructor Details
#initialize(id: nil, devices: nil, updated_at: nil, created_at: nil) ⇒ FarmManagerUser
Returns a new instance of FarmManagerUser.
3
4
5
6
|
# File 'lib/kakaxi_parse/farm_manager_user.rb', line 3
def initialize(id: nil, devices: nil, updated_at: nil, created_at: nil)
@devices = devices
super(id, nil, updated_at, created_at)
end
|
Class Method Details
.all(limit: DEFUALT_LIMIT) ⇒ Object
12
13
14
|
# File 'lib/kakaxi_parse/farm_manager_user.rb', line 12
def self.all(limit: DEFUALT_LIMIT)
to_objects(API.new("classes/#{self.demodulize}", params: { limit: limit }).get)
end
|
.short_name ⇒ Object
8
9
10
|
# File 'lib/kakaxi_parse/farm_manager_user.rb', line 8
def self.short_name
'farm_manager_user'
end
|
.where(hash, limit: DEFUALT_LIMIT) ⇒ Object
16
17
18
|
# File 'lib/kakaxi_parse/farm_manager_user.rb', line 16
def self.where(hash, limit: DEFUALT_LIMIT)
to_objects(super(self, hash, limit)) if valid_key?(hash)
end
|
Instance Method Details
#add_device(id) ⇒ Object
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/kakaxi_parse/farm_manager_user.rb', line 26
def add_device(id)
params = Datatype::AddRelation.new(KakaxiDevice, [id]).to_hash
result = API.new("classes/#{ self.class.demodulize }/#{ self.id }", params: params).put
if result.has_key? 'updatedAt'
self.updated_at = DateTime.strptime(result['updatedAt'], '%Y-%m-%dT%H:%M:%S.%LZ')
true
else
false
end
end
|
#remove_device(id) ⇒ Object
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/kakaxi_parse/farm_manager_user.rb', line 37
def remove_device(id)
params = Datatype::RemoveRelation.new(KakaxiDevice, [id]).to_hash
result = API.new("classes/#{ self.class.demodulize }/#{ self.id }", params: params).put
if result.has_key? 'updatedAt'
self.updated_at = DateTime.strptime(result['updatedAt'], '%Y-%m-%dT%H:%M:%S.%LZ')
true
else
false
end
end
|
#save ⇒ Object
20
21
22
23
24
|
# File 'lib/kakaxi_parse/farm_manager_user.rb', line 20
def save
params = {}
params = Datatype::AddRelation.new(KakaxiDevice, @devices.map(&:id)).to_hash if @devices
id ? false : super(self, params)
end
|