Class: Mass::Profile

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

Direct Known Subclasses

ProfileAPI, ProfileMTA, ProfileRPA

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(h) ⇒ Profile

Returns a new instance of Profile.



9
10
11
12
# File 'lib/base-line/profile.rb', line 9

def initialize(h)
    super(h)
    self.type = Mass::ProfileType.new(h['profile_type_desc']).child_class_instance
end

Instance Attribute Details

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

Class Method Details

.object_nameObject



5
6
7
# File 'lib/base-line/profile.rb', line 5

def self.object_name
    'profile'
end

Instance Method Details

#child_class_instanceObject

crate an instance of the profile type using the class defined in the ‘desc` attribute. override the base method



23
24
25
26
27
28
29
# File 'lib/base-line/profile.rb', line 23

def child_class_instance
    profile_type = self.desc['profile_type']
    key = self.class_name_from_profile_type
    raise "Source code of profile type #{profile_type} not found. Create a class #{key} in the folder `/lib` of your mass-sdk." unless Kernel.const_defined?(key)
    ret = Kernel.const_get(key).new(self.desc)
    return ret
end

#class_name_from_profile_typeObject

convert the profile_type into the ruby class to create an instance. example: Apollo –> Mass::ApolloAPI



16
17
18
19
# File 'lib/base-line/profile.rb', line 16

def class_name_from_profile_type
    profile_type = self.desc['profile_type']
    "Mass::#{profile_type}" 
end

#connectioncheck(limit: 100, logger: nil) ⇒ Object

Scrape the inbox of the profile. Return a an array of hash descriptors of outreach records.

Parameters:

  • limit: the maximum number of connections to scrape. Default: 100.

  • logger: a logger object to log the process. Default: nil.

Example of a hash descritor into the returned array: “‘

# a scraped message is always a :performed message
'status' => :performed,
# what is the outreach type?
# e.g.: :LinkedIn_ConnectionRequest
# decide this in the child class.
'outreach_type' => nil,
# hash descriptor of the profile who is scraping the inbox
'profile' => self.desc,
# hash descriptor of the lead who is the conversation partner
'lead' => nil,
# if the message has been sent by the profile, it is :outgoing.
# if the message has been sent by the lead, it is :incoming.
'direction' => :accepted,

“‘



102
103
104
# File 'lib/base-line/profile.rb', line 102

def connectioncheck(limit: 100, logger:nil)
    []
end

#inboxcheck(limit: 100, only_unread: true, logger: nil) ⇒ Object

Scrape the inbox of the profile. Return a an array of hash descriptors of outreach records.

Parameters:

  • limit: the maximum number of messages to scrape. Default: 100.

  • only_unread: if true, then only the unread messages will be scraped. Default: true.

  • logger: a logger object to log the process. Default: nil.

Example of a hash descritor into the returned array: “‘

# a scraped message is always a :performed message
'status' => :performed,
# what is the outreach type?
# e.g.: :LinkedIn_DirectMessage
# decide this in the child class.
'outreach_type' => nil,
# hash descriptor of the profile who is scraping the inbox
'profile' => self.desc,
# hash descriptor of the lead who is the conversation partner
'lead' => nil,
# if the message has been sent by the profile, it is :outgoing.
# if the message has been sent by the lead, it is :incoming.
'direction' => nil, 
# the content of the message
'subject' => nil,
'body' => nil,

“‘



72
73
74
# File 'lib/base-line/profile.rb', line 72

def inboxcheck(limit: 100, only_unread:true, logger:nil)
    []
end

#running?Boolean

return true of the profile is running if its profile type is rpa-access, then it will return true if the browser is running. else, it will return always true.

Returns:

  • (Boolean)


34
35
36
37
38
39
40
# File 'lib/base-line/profile.rb', line 34

def running?
    if self.type.desc['access'].to_sym == :rpa
        c = AdsPowerClient.new(key: ADSPOWER_API_KEY)
        return c.check(self.desc['ads_power_id'])
    end
    return true
end