Class: WinewooCore::Repositories::Mongo::WinewooUserDevicesMongoRepo

Inherits:
Object
  • Object
show all
Defined in:
lib/winewoo_core/repositories/mongo/winewoo_user_devices_mongo_repo.rb

Instance Method Summary collapse

Instance Method Details

#create(user, params) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/winewoo_core/repositories/mongo/winewoo_user_devices_mongo_repo.rb', line 9

def create(user, params)
  user_agent = params.user_agent
  push_token = params.device_push_token

  device = user.winewoo_user_devices.find_by(device_push_token: push_token) if push_token

  unless device
    device = user.winewoo_user_devices.create(device_model: user_agent.device_model,
                                              device_os: user_agent.device_os,
                                              device_os_version: user_agent.device_os_version,
                                              device_lang: user_agent.device_lang,
                                              device_screen_width: user_agent.device_screen_width,
                                              device_screen_height: user_agent.device_screen_height,
                                              device_push_token: push_token)
    device.destroy if device.errors.any?
  end

  user.current_device_id = device.id if device
  return device
end

#get(user, device_id) ⇒ Object



4
5
6
# File 'lib/winewoo_core/repositories/mongo/winewoo_user_devices_mongo_repo.rb', line 4

def get(user, device_id)
  user.winewoo_user_devices.find(device_id)
end

#update(user, device_id, params) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/winewoo_core/repositories/mongo/winewoo_user_devices_mongo_repo.rb', line 31

def update(user, device_id, params)
  user_agent = params.user_agent
  push_token = params.device_push_token
  device = self.get(user, device_id)
  return unless device
  device.update_attributes(device_model: user_agent.device_model,
                           device_os: user_agent.device_os,
                           device_os_version: user_agent.device_os_version,
                           device_lang: user_agent.device_lang,
                           device_screen_width: user_agent.device_screen_width,
                           device_screen_height: user_agent.device_screen_height,
                           device_push_token: push_token)
  return device
end