Class: BlackStack::NextBot::RemoteCommand

Inherits:
BaseRemoteObject show all
Includes:
BaseCommand
Defined in:
lib/remotecommand.rb

Overview

The “remote” (or API class) that will be receive the data from an API call.

Constant Summary

Constants included from BaseCommand

BaseCommand::STATUS_CANCELED, BaseCommand::STATUS_FAILURE, BaseCommand::STATUS_ONGOING, BaseCommand::STATUS_PENDING, BaseCommand::STATUS_SUCCESS, BaseCommand::TYPE_CLOSE, BaseCommand::TYPE_GOTO, BaseCommand::TYPE_LOGIN, BaseCommand::TYPE_START_BOT, BaseCommand::TYPE_TRAFFIC

Instance Attribute Summary collapse

Attributes inherited from BaseRemoteObject

#descriptor

Instance Method Summary collapse

Methods included from BaseCommand

statusColor, statusDescription, statuses, typeDescription, types

Constructor Details

#initialize(the_browser = nil) ⇒ RemoteCommand

browser: is a browser created from the BrowserFactory class.



70
71
72
# File 'lib/remotecommand.rb', line 70

def initialize(the_browser=nil)
  self.browser = the_browser
end

Instance Attribute Details

#browserObject

:browser: is the browser where the bot will operate.



12
13
14
# File 'lib/remotecommand.rb', line 12

def browser
  @browser
end

#idObject

:id is the ID of the record in the “routine” table. :params is an array of RemoteParam objects. :steps is an array of RemoteSteps objects.



17
18
19
# File 'lib/remotecommand.rb', line 17

def id
  @id
end

#id_workerObject

:id is the ID of the record in the “routine” table. :params is an array of RemoteParam objects. :steps is an array of RemoteSteps objects.



17
18
19
# File 'lib/remotecommand.rb', line 17

def id_worker
  @id_worker
end

#param_goto_urlObject

:id is the ID of the record in the “routine” table. :params is an array of RemoteParam objects. :steps is an array of RemoteSteps objects.



17
18
19
# File 'lib/remotecommand.rb', line 17

def param_goto_url
  @param_goto_url
end

#param_login_id_domainObject

:id is the ID of the record in the “routine” table. :params is an array of RemoteParam objects. :steps is an array of RemoteSteps objects.



17
18
19
# File 'lib/remotecommand.rb', line 17

def 
  @param_login_id_domain
end

#param_start_id_lnuserObject

:id is the ID of the record in the “routine” table. :params is an array of RemoteParam objects. :steps is an array of RemoteSteps objects.



17
18
19
# File 'lib/remotecommand.rb', line 17

def param_start_id_lnuser
  @param_start_id_lnuser
end

#param_start_usernameObject

:id is the ID of the record in the “routine” table. :params is an array of RemoteParam objects. :steps is an array of RemoteSteps objects.



17
18
19
# File 'lib/remotecommand.rb', line 17

def param_start_username
  @param_start_username
end

#param_traffic_id_proxyObject

Returns the value of attribute param_traffic_id_proxy.



18
19
20
# File 'lib/remotecommand.rb', line 18

def param_traffic_id_proxy
  @param_traffic_id_proxy
end

#param_traffic_number_of_visitsObject

Returns the value of attribute param_traffic_number_of_visits.



18
19
20
# File 'lib/remotecommand.rb', line 18

def param_traffic_number_of_visits
  @param_traffic_number_of_visits
end

#param_traffic_proxy_ipObject

Returns the value of attribute param_traffic_proxy_ip.



19
20
21
# File 'lib/remotecommand.rb', line 19

def param_traffic_proxy_ip
  @param_traffic_proxy_ip
end

#param_traffic_proxy_portObject

Returns the value of attribute param_traffic_proxy_port.



19
20
21
# File 'lib/remotecommand.rb', line 19

def param_traffic_proxy_port
  @param_traffic_proxy_port
end

#param_traffic_urlObject

Returns the value of attribute param_traffic_url.



18
19
20
# File 'lib/remotecommand.rb', line 18

def param_traffic_url
  @param_traffic_url
end

#param_traffic_visit_min_secondsObject

Returns the value of attribute param_traffic_visit_min_seconds.



18
19
20
# File 'lib/remotecommand.rb', line 18

def param_traffic_visit_min_seconds
  @param_traffic_visit_min_seconds
end

#param_traffic_visit_random_additional_secondsObject

Returns the value of attribute param_traffic_visit_random_additional_seconds.



18
19
20
# File 'lib/remotecommand.rb', line 18

def param_traffic_visit_random_additional_seconds
  @param_traffic_visit_random_additional_seconds
end

#typeObject

:id is the ID of the record in the “routine” table. :params is an array of RemoteParam objects. :steps is an array of RemoteSteps objects.



17
18
19
# File 'lib/remotecommand.rb', line 17

def type
  @type
end

Instance Method Details

#build(h) ⇒ Object

generate all the hierarchy of the bot (routines, steps,

> params) from a hash descriptor.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/remotecommand.rb', line 23

def build(h)
  super(h)
  self.id = h['id']
  self.id_worker = h['id_worker']
  self.type = h['type']
  # start command params
  self.param_start_id_lnuser = h['param_start_id_lnuser']
  self.param_start_username = h['param_start_username']
  # login command params
  self. = h['param_login_id_domain']
  # goto command params
  self.param_goto_url = h['param_goto_url']
  # traffic command params
  self.param_traffic_url = h['param_traffic_url']
  self.param_traffic_id_proxy = h['param_traffic_id_proxy']
  self.param_traffic_proxy_ip = h['param_traffic_proxy_ip']
  self.param_traffic_proxy_port = h['param_traffic_proxy_port']
  self.param_traffic_number_of_visits = h['param_traffic_number_of_visits']
  self.param_traffic_visit_min_seconds = h['param_traffic_visit_min_seconds']
  self.param_traffic_visit_random_additional_seconds = h['param_traffic_visit_random_additional_seconds']
  # TODO: map here all the other attributes of the record in the "command" table, 
  # regarding every one of the possible "type" of steps. 
end

#create_childObject

based on the “type” attribute, create an instance of the

> regarding child class, to invoke the “run” method of

> such child class.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/remotecommand.rb', line 50

def create_child()
  return RemoteStepStartBot.new(self.browser).build(self.descritor) if self.type == TYPE_START_BOT
  return RemoteStepLogin.new(self.browser).build(self.descritor) if self.type == TYPE_LOGIN
  return RemoteStepGoto.new(self.browser).build(self.descritor) if self.type == TYPE_GOTO
  
  # TODO: add RemoteStepStartScraper
  # TODO: add RemoteStepTraffic
  
  #return RemoteStepFind.new(self.browser).build(self.descritor) if self.type == TYPE_FIND
  #return RemoteStepMouse.new(self.browser).build(self.descritor) if self.type == TYPE_MOUSE
  #return RemoteStepWrite.new(self.browser).build(self.descritor) if self.type == TYPE_WRITE
  #return RemoteStepDelay.new(self.browser).build(self.descritor) if self.type == TYPE_DELAY
  #return RemoteStepCall.new(self.browser).build(self.descritor) if self.type == TYPE_CALL
  #return RemoteStepIf.new(self.browser).build(self.descritor) if self.type == TYPE_IF
  #return RemoteStepExists.new(self.browser).build(self.descritor) if self.type == TYPE_EXISTS
  #return RemoteStepEach.new(self.browser).build(self.descritor) if self.type == TYPE_EACH
  return RemoteStepClose.new(self.browser).build(self.descritor) if self.type == TYPE_CLOSE
end

#runObject

run the specified operation for this “type” of “step”



75
76
77
# File 'lib/remotecommand.rb', line 75

def run()
  raise 'This is an abstract method. Each child of the RemoteCommand class will code its own "run" method.'
end