Class: Account

Inherits:
MLS::Model show all
Includes:
MLS::Avatar, MLS::Slugger
Defined in:
lib/mls/models/account.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#passwordObject

Returns the value of attribute password.



59
60
61
# File 'lib/mls/models/account.rb', line 59

def password
  @password
end

#password_requiredObject

Returns the value of attribute password_required.



59
60
61
# File 'lib/mls/models/account.rb', line 59

def password_required
  @password_required
end

Class Method Details

.confirm(token) ⇒ Object



156
157
158
159
160
161
162
163
# File 'lib/mls/models/account.rb', line 156

def self.confirm(token)
  req = Net::HTTP::Post.new("/accounts/confirm")
  req.body = { token: token }.to_json
  Account.connection.instance_variable_get(:@connection).send_request(req)
  return true
rescue Sunstone::Exception::NotFound
  return false
end

.send_reset_password_email(url, email_address) ⇒ Object



140
141
142
143
144
# File 'lib/mls/models/account.rb', line 140

def self.send_reset_password_email(url, email_address)
  req = Net::HTTP::Post.new("/accounts/password")
  req.body = { email_address: email_address, url: url }.to_json
  Account.connection.instance_variable_get(:@connection).send_request(req)
end

.update_password(token, password, password_confirmation) ⇒ Object



146
147
148
149
150
151
152
153
154
# File 'lib/mls/models/account.rb', line 146

def self.update_password(token, password, password_confirmation)
  req = Net::HTTP::Put.new("/accounts/password")
  req.body = {
    token: token,
    password: password,
    password_confirmation: password_confirmation
  }.to_json
  Account.connection.instance_variable_get(:@connection).send_request(req)
end

Instance Method Details

#city_regionsObject



70
71
72
# File 'lib/mls/models/account.rb', line 70

def city_regions
  advertised_regions.filter(type: Region::CITY_TYPES).order(listings_count: :desc)
end

#company_nameObject



126
127
128
129
# File 'lib/mls/models/account.rb', line 126

def company_name
  return organization.name if organization
  return company
end

#dealsObject



38
39
40
# File 'lib/mls/models/account.rb', line 38

def deals
  Search.filter([{manager_id: self.id}, "OR", {broker_id: self.id}])
end

#email_addressObject



103
104
105
# File 'lib/mls/models/account.rb', line 103

def email_address
  email_addresses.to_a.find{|p| p.primary }.try(:address)
end

#merge_in(account_id) ⇒ Object



131
132
133
134
135
136
137
138
# File 'lib/mls/models/account.rb', line 131

def merge_in()
  req = Net::HTTP::Put.new("/accounts/#{self.id}/merge")
  req.body = { account_id:  }.to_json
  Account.connection.instance_variable_get(:@connection).send_request(req)
  return true
rescue Sunstone::Exception::NotFound
  return false
end

#password_required?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/mls/models/account.rb', line 94

def password_required?
  @password_required != false
end

#paying?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/mls/models/account.rb', line 90

def paying?
  subscriptions.map{|x| x.services.filter(status: "active").count}.sum > 0
end

#phoneObject



117
118
119
# File 'lib/mls/models/account.rb', line 117

def phone
  (phones.to_a.find{|p| p.primary } || phones.first).try(:number)
end

#propertiesObject



74
75
76
# File 'lib/mls/models/account.rb', line 74

def properties
  Property.where(listings: {ownerships: {account_id: self.id}})
end

#referral?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/mls/models/account.rb', line 86

def referral?
  subscriptions.map{|x| x.services.filter(status: "active", type: "referral").count}.sum > 0
end

#regionsObject



66
67
68
# File 'lib/mls/models/account.rb', line 66

def regions
  Region.filter(id: {in: self.advertised_region_ids})
end

#regions_attributes=(regions_attrs) ⇒ Object



107
108
109
110
111
112
113
114
115
# File 'lib/mls/models/account.rb', line 107

def regions_attributes=(regions_attrs)
  # regions.clear was trying to destroy all regions going to "/accounts_regions/" method = Destroy
  AccountsRegion.where(:agent_id => self.id).destroy_all
  return if regions_attrs.nil?
  regions_attrs.each do |attrs|
    region = Region.find(attrs["id"])
    regions.push(region)
  end
end

#role?(*compare_roles) ⇒ Boolean Also known as: roles?

Returns:

  • (Boolean)


121
122
123
# File 'lib/mls/models/account.rb', line 121

def role?(*compare_roles)
  (roles & compare_roles).any?
end

#send_confirmation_email(url) ⇒ Object



165
166
167
168
169
# File 'lib/mls/models/account.rb', line 165

def send_confirmation_email(url)
  req = Net::HTTP::Post.new("/accounts/#{self.id}/confirm")
  req.body = {url: url}.to_json
  Account.connection.instance_variable_get(:@connection).send_request(req)
end

#set_confirmation_tokenObject



171
172
173
174
175
# File 'lib/mls/models/account.rb', line 171

def set_confirmation_token
  req = Net::HTTP::Get.new("/accounts/#{self.id}/confirm")
  response = Account.connection.instance_variable_get(:@connection).send_request(req)
  self.confirmation_token = response.body
end

#tim_alerts?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/mls/models/account.rb', line 78

def tim_alerts?
  subscriptions.map{|x| x.services.filter(status: "active", type: "tim_alerts").count}.sum > 0
end

#unlimited?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/mls/models/account.rb', line 82

def unlimited?
  subscriptions.map{|x| x.services.filter(status: "active", type: "unlimited").count}.sum > 0
end