Class: AngelApiGem::AngelApi::Startup
- Inherits:
-
Object
- Object
- AngelApiGem::AngelApi::Startup
- Defined in:
- app/models/angel_api_gem/angel_api.rb
Class Method Summary collapse
Class Method Details
.roles(startup_id) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/models/angel_api_gem/angel_api.rb', line 63 def self.roles(startup_id) mutex = Mutex.new @threads = [] all_roles = [] page = 0 last_page = nil until page == last_page do @threads << Thread.new(startup_id) { mutex.synchronize do page += 1 roles = AngelApiGem::AngelApi::Api.new.startup_roles(startup_id,page) last_page = roles["last_page"] if roles["startup_roles"] roles["startup_roles"].each do |role| all_roles << Role.new(role) end end end } @threads.each { |aThread| aThread.join } end return all_roles end |
.where(params = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/models/angel_api_gem/angel_api.rb', line 40 def self.where( params = {} ) angel = AngelApi::Api.new @threads = [] @details = [] startup_ids = params.values.inject([]) do |ids, v| next if v.blank? ids += angel.search(v,params.keys.first).collect{ |s| s['id'] } end return nil if startup_ids.blank? # if no good search results yet don't try anything # multithreaded this to speed up the return of startup details # needed startup details to get the company url from the Angel API. startup_ids.each do |id| @threads << Thread.new(id) { |id| angel = AngelApi::Api.new @details << angel.startup_detail(id) } end @threads.each { |aThread| aThread.join } @details.flatten.uniq end |