Class: Mass::Request

Inherits:
BlackStack::Base
  • Object
show all
Defined in:
lib/base-line/request.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.object_nameObject



3
4
5
# File 'lib/base-line/request.rb', line 3

def self.object_name
  'request'
end

Instance Method Details

#perform(l) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/base-line/request.rb', line 7

def perform(l)
  if self.desc['state'] == 'online'
    self.start_browser(l)
  elsif self.desc['state'] == 'idle'
    self.stop_browser(l)
  else
    raise "Unknown or unsupported request state: #{self.desc['state'].to_s}."
  end
end

#start_browser(l = nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/base-line/request.rb', line 17

def start_browser(l=nil)
  l = BlackStack::DummyLogger.new(nil) if l.nil?
  #raise "Profile is not waiting to start" if self.desc['profile']['state'].to_sym != :starting
  # start browser
  p = Mass::ProfileRPA.new(self.desc['profile'])
  p.driver
  # update profile state
  p.desc['state'] = :scraping_inbox
  p.upsert
end

#stop_browser(l = nil) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/base-line/request.rb', line 28

def stop_browser(l=nil)
  l = BlackStack::DummyLogger.new(nil) if l.nil?
  #raise "Profile is not waiting to stop" if self.desc['profile']['state'].to_sym != :stopping
  c = AdsPowerClient.new(key: ADSPOWER_API_KEY)
  c.stop(self.desc['profile']['ads_power_id']) if c.check(self.desc['profile']['ads_power_id'])
  # get the profile for updating
  p = Mass::Profile.new(self.desc['profile'])
  p.desc['state'] = :idle
  p.upsert
end