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.



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

def password
  @password
end

#password_requiredObject

Returns the value of attribute password_required.



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

def password_required
  @password_required
end

Class Method Details

.confirm(token) ⇒ Object



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

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



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

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



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

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



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

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

#company_nameObject



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

def company_name
  return organization.name if organization
  return company
end

#dealsObject



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

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

#email_addressObject



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

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

#merge_in(account_id) ⇒ Object



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

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)


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

def password_required?
  @password_required != false
end

#paying?Boolean

Returns:

  • (Boolean)


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

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

#phoneObject



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

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

#propertiesObject



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

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

#referral?Boolean

Returns:

  • (Boolean)


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

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

#regionsObject



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

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

#regions_attributes=(regions_attrs) ⇒ Object



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

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)


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

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

#send_confirmation_email(url) ⇒ Object



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

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



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

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)


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

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

#unlimited?Boolean

Returns:

  • (Boolean)


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

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