Class: User
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- User
- Defined in:
- app/models/user.rb
Instance Method Summary collapse
- #add_device(endpoint_arn, device_type, device_token) ⇒ Object
- #generate_endpoint_arn(token, device_type) ⇒ Object
- #name ⇒ Object
- #role ⇒ Object
- #valid_device_token(device_token, device_type) ⇒ Object
Instance Method Details
#add_device(endpoint_arn, device_type, device_token) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'app/models/user.rb', line 92 def add_device(endpoint_arn, device_type, device_token) begin customer_device = CustomerDevice.find_or_initialize_by(endpoint_arn: endpoint_arn) customer_device.endpoint_arn = endpoint_arn customer_device.device_type = device_type customer_device.device_token = device_token customer_device.user_id = self.id customer_device.save return true rescue Exception => e return false end end |
#generate_endpoint_arn(token, device_type) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'app/models/user.rb', line 57 def generate_endpoint_arn(token, device_type) sns = Aws::SNS::Client.new begin if self.role =='agent' if device_type == "Android" endpoint = sns.create_platform_endpoint( platform_application_arn:'arn:aws:sns:us-west-2:126524593432:app/GCM/Agento_Floortime', token:token) else endpoint = sns.create_platform_endpoint( platform_application_arn:'arn:aws:sns:us-west-2:126524593432:app/APNS_SANDBOX/Agento_Floortime_iOS', token: token) end elsif self.role =='customer' if device_type == "Android" endpoint = sns.create_platform_endpoint( platform_application_arn:'arn:aws:sns:us-west-2:126524593432:app/GCM/Agento_Customer', token:token) else endpoint = sns.create_platform_endpoint( platform_application_arn:'arn:aws:sns:us-west-2:126524593432:app/APNS_SANDBOX/Agento_Customer_iOS', token: token) end else p "unknown" end rescue Exception => e p e return false end return endpoint.endpoint_arn end |
#name ⇒ Object
26 27 28 |
# File 'app/models/user.rb', line 26 def name "#{email}" end |
#role ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'app/models/user.rb', line 30 def role if self.customer.present? return I18n.t 'customer' elsif self.agent.present? return I18n.t 'agent' else return 'admin' end end |
#valid_device_token(device_token, device_type) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/models/user.rb', line 40 def valid_device_token(device_token, device_type) device_verified=false; #return device_verified; if(device_type && device_type && !device_type.blank? && !device_token.blank?) customer_devices = self.customer_devices.where(:device_type => device_type, :device_token =>device_token) if customer_devices.count > 0 device_verified=true; else customer = self.customer; #return customer.id; customer.update_attributes(:phone_verified => false) device_verified =false; end end return device_verified; end |