module BlackStack::StealthBrowserAutomation::Multilogin

Public Class Methods

auth_token() click to toggle source
# File lib/stealth_browser_automation.rb, line 19
def self.auth_token()
  @@auth_token
end
create_local_profile(data) click to toggle source

returns the profileId of the new Mimic profile

# File lib/stealth_browser_automation.rb, line 38
def self.create_local_profile(data)
  url = "http://127.0.0.1:#{BlackStack::StealthBrowserAutomation::Multilogin::mla_local_port.to_s}/api/v2/localprofile/create"
  uri = URI(url)
  Net::HTTP.start(uri.host, uri.port, :use_ssl => false, :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
    req = Net::HTTP::Post.new(uri)
    req['Content-Type'] = 'application/json'
    req.body = data.to_json
    res = JSON.parse(http.request(req).body)
    raise "Error creating Multilogin local profile: #{res.to_s}" if !res.has_key?('uuid')
    return res['uuid']
  end
end
create_profile(data) click to toggle source

returns the profileId of the new Mimic profile

# File lib/stealth_browser_automation.rb, line 89
def self.create_profile(data)
  url = "https://api.multiloginapp.com/v2/profile?token=#{BlackStack::StealthBrowserAutomation::Multilogin::auth_token.to_s}&mlaVersion=#{BlackStack::StealthBrowserAutomation::Multilogin::mla_version.to_s}"
  uri = URI(url)
  Net::HTTP.start(uri.host, uri.port, :use_ssl => true, :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
    req = Net::HTTP::Post.new(uri)
    req['Content-Type'] = 'application/json'
    req.body = data.to_json
    res = JSON.parse(http.request(req).body)
    raise "Error creating Multilogin profile: #{res.to_s}" if !res.has_key?('uuid')
    return res['uuid']
  end
end
local_profile_id(name) click to toggle source

returns the profile_id from its name. If not exists a profile with such name, it returns nil.

# File lib/stealth_browser_automation.rb, line 82
def self.local_profile_id(name)
  h = self.local_profiles.select { |h| h['name'] == name }.first
  return nil if h.nil?
  h['sid']
end
local_profiles() click to toggle source

returns the profileId of the new Mimic profile TODO: validar posibles errores

# File lib/stealth_browser_automation.rb, line 67
def self.local_profiles()
  url = "http://127.0.0.1:#{BlackStack::StealthBrowserAutomation::Multilogin::mla_local_port.to_s}/api/v2/localprofile/list"
  uri = URI.parse(url)
  res = Net::HTTP.start(uri.host, uri.port, :use_ssl => false, :verify_mode => OpenSSL::SSL::VERIFY_NONE) {|http|
    req = Net::HTTP::Get.new(uri)
    #req['Content-Type'] = 'application/json'
    #req.body = {}.to_json
    res = JSON.parse(http.request(req).body)
    #raise "Error creating Multilogin local profile: #{res.to_s}" if res['status'] != 'OK'
    return res
  }
end
mla_local_port() click to toggle source
# File lib/stealth_browser_automation.rb, line 27
def self.mla_local_port()
  @@mla_local_port
end
mla_version() click to toggle source
# File lib/stealth_browser_automation.rb, line 23
def self.mla_version()
  @@mla_version
end
remove_local_profile(profile_id) click to toggle source

returns the profileId of the new Mimic profile

# File lib/stealth_browser_automation.rb, line 52
def self.remove_local_profile(profile_id)
  url = "http://127.0.0.1:#{BlackStack::StealthBrowserAutomation::Multilogin::mla_local_port.to_s}/api/v2/localprofile/remove"
  uri = URI.parse(url)
  res = Net::HTTP.start(uri.host, uri.port, :use_ssl => false, :verify_mode => OpenSSL::SSL::VERIFY_NONE) {|http|
    req = Net::HTTP::Post.new(uri)
    req['Content-Type'] = 'application/json'
    req.body = [profile_id].to_json
    res = JSON.parse(http.request(req).body)
    raise "Error creating Multilogin local profile: #{res.to_s}" if res['status'] != 'OK'
    return
  }
end
remove_profile(profile_id) click to toggle source

returns the profileId of the new Mimic profile

# File lib/stealth_browser_automation.rb, line 103
def self.remove_profile(profile_id)
  url = "https://api.multiloginapp.com/v1/profile/remove?token=#{BlackStack::StealthBrowserAutomation::Multilogin::auth_token.to_s}&profileId=#{profile_id}"
  uri = URI.parse(url)
  req = Net::HTTP::Get.new(url)
  res = Net::HTTP.start(uri.host, uri.port, :use_ssl => true, :verify_mode => OpenSSL::SSL::VERIFY_NONE) {|http|
    http.request(req)
  }
  res = JSON.parse(res.body)
  raise "Error removing Multilogin profile: #{res.to_s}" if !res.has_key?('status')
  raise "Error removing Multilogin profile: #{res['status'].to_s}" if res['status'] != 'OK'
end
set(h) click to toggle source
# File lib/stealth_browser_automation.rb, line 31
def self.set(h)
  @@auth_token = h[:auth_token]
  @@mla_version = h[:mla_version]
  @@mla_local_port = h[:mla_local_port]
end