Method: Watchmob::Watchlist#initialize

Defined in:
lib/watchmob/watchlist.rb

#initialize(json) ⇒ Watchlist

Returns a new instance of Watchlist.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/watchmob/watchlist.rb', line 14

def initialize(json)
  @phones = []

  phone_threads = json.map do |phone_json|
    params = if phone_json.is_a? Array
      {"aukro" => phone_json[0], "phone" => phone_json[1]}
    else
      phone_json
    end

    Thread.new do
      Thread.current.abort_on_exception = true
      @phones << Smartphone.find(params) 
    end
  end

  Timeout.timeout(PHONE_TIMEOUT) do
    phone_threads.each(&:join)
  end
end