Class: SimpleMDM::Base

Inherits:
Hashie::Mash
  • Object
show all
Defined in:
lib/simplemdm/base.rb

Direct Known Subclasses

App, AppGroup, Device, DeviceGroup, InstalledApp

Class Method Summary collapse

Class Method Details

.build(hash = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/simplemdm/base.rb', line 8

def self.build(hash = nil)
  if hash
    attrs = {}

    if hash['id']
      attrs[:id] = hash['id']
    end

    if hash['attributes']
      attrs.merge!(hash['attributes'])
    end

    if hash['relationships']
      if hash['relationships']['device_group']
        attrs['device_group_id'] = hash['relationships']['device_group']['data']['id']
      end

      if hash['relationships']['device_groups']
        attrs['device_group_ids'] = hash['relationships']['device_groups']['data'].collect { |o| o['id'] }
      end

      if hash['relationships']['devices']
        attrs['device_ids'] = hash['relationships']['devices']['data'].collect { |o| o['id'] }
      end

      if hash['relationships']['apps']
        attrs['app_ids'] = hash['relationships']['apps']['data'].collect { |o| o['id'] }
      end
    end

    new attrs
  end
end