user.rb 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. class User < ActiveRecord::Base
  2. include Redis::Objects
  3. counter :api_credits, :start => 10000
  4. counter :crawl_credits, :start => 150
  5. counter :contact_credits, :start => 500
  6. counter :mileage, :start => 0, :expiration => 1.minute
  7. counter :active_engines, :start => 0, :expiration => 15.minutes
  8. counter :bandwidth_used
  9. counter :target_count
  10. counter :search_count
  11. counter :email_count
  12. counter :phone_count
  13. counter :social_count
  14. set :job_ids
  15. set :batch_ids
  16. set :quicklist
  17. set :email_addresses
  18. set :phone_numbers
  19. set :social_media_profiles
  20. set :pages_crawled, :expiration => 1.minute
  21. set :notifications, :expiration => 60.minutes
  22. has_many :websites
  23. has_many :email_leads,:through => :websites
  24. has_many :phone_leads,:through => :websites
  25. has_many :social_leads,:through => :websites
  26. enum role: [:user, :admin, :trial, :basic, :advantage, :enterprise]
  27. def available_engines
  28. self.max_engines - self.active_engines.value
  29. end
  30. def add_to_prospects(record)
  31. self.quicklist << record
  32. end
  33. def prospects(record)
  34. self.quicklist.members
  35. end
  36. def total_contacts
  37. (self.email_leads.count + self.phone_leads.count + self.social_leads.count)
  38. end
  39. def current_plan
  40. if self.subscription and self.subscription.plan_id
  41. self.subscription.plan_id
  42. else
  43. 0
  44. end
  45. end
  46. def max_targets
  47. plan = self.current_plan
  48. case plan
  49. when 0
  50. 50
  51. when 1
  52. 500
  53. when 2
  54. 2000
  55. when 3
  56. 10000
  57. when 4
  58. 9999999999
  59. else
  60. 50
  61. end
  62. end
  63. def max_engines
  64. plan = self.current_plan
  65. case plan
  66. when 0
  67. 4
  68. when 1
  69. 8
  70. when 2
  71. 16
  72. when 3
  73. 32
  74. else
  75. 4
  76. end
  77. end
  78. def max_searches
  79. plan = self.current_plan
  80. case plan
  81. when 0
  82. 5
  83. when 1
  84. 250
  85. when 2
  86. 1000
  87. when 3
  88. 5000
  89. when 4
  90. 9999999999
  91. else
  92. 5
  93. end
  94. end
  95. def max_pages
  96. plan = self.current_plan
  97. case plan
  98. when 0
  99. 1000
  100. when 1
  101. 20000
  102. when 2
  103. 100000
  104. when 3
  105. 1000000
  106. when 4
  107. 10000000
  108. else
  109. 1000
  110. end
  111. end
  112. def max_validations
  113. plan = self.current_plan
  114. case plan
  115. when 0
  116. 10
  117. when 1
  118. 200
  119. when 2
  120. 1000
  121. when 3
  122. 10000
  123. when 4
  124. 9999999999
  125. else
  126. 10
  127. end
  128. end
  129. def max_bandwidth
  130. plan = self.current_plan
  131. case plan
  132. when 0
  133. 10000000
  134. when 1
  135. 100000000
  136. when 2
  137. 1000000000
  138. when 3
  139. 10000000000
  140. when 4
  141. 100000000000
  142. else
  143. 10000000
  144. end
  145. end
  146. def max_contacts
  147. plan = self.current_plan
  148. case plan
  149. when 0
  150. 150
  151. when 1
  152. 500
  153. when 2
  154. 5000
  155. when 3
  156. 10000
  157. when 4
  158. 9999999999
  159. else
  160. 150
  161. end
  162. end
  163. def contacts
  164. [self.email_leads, self.phone_leads, self.social_leads].flatten
  165. end
  166. ##########
  167. # BENCHMARK US!
  168. def facebook_leads
  169. self.social_leads.sort { |x| x.social_network == "facebook"}
  170. end
  171. # VERSUS...
  172. def twitter_leads
  173. SocialLead.by_user(self.id).where(:social_network => "twitter")
  174. end
  175. ##########
  176. def pinterest_leads
  177. SocialLead.by_user(self.id).where(:social_network => "pinterest")
  178. end
  179. def linkedin_leads
  180. SocialLead.by_user(self.id).where(:social_network => "linkedin")
  181. end
  182. def google_leads
  183. SocialLead.by_user(self.id).where(:social_network => "google")
  184. end
  185. def github_leads
  186. SocialLead.by_user(self.id).where(:social_network => "github")
  187. end
  188. def instagram_leads
  189. SocialLead.by_user(self.id).where(:social_network => "instagram")
  190. end
  191. def new_record?
  192. self.id.nil?
  193. end
  194. end