Module: Protocol

Included in:
Instabot
Defined in:
lib/instabot/create_protocol.rb

Instance Method Summary collapse

Instance Method Details

#create_mechanicObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/instabot/create_protocol.rb', line 2

def create_mechanic
  @agent                  = Mechanize.new
  @agent.max_history      = 2
  @agent.ca_file          = './cacert.pem' # Because i'm using windows and... you know... ._.
  @agent.user_agent_alias = ['Mac Mozilla', 'Mac Safari', 'Windows IE 6', 'Windows IE 7', 'Windows IE 8', 'Windows IE 9', 'Windows Mozilla', 'Windows Chrome'].sample
  if options[:use_proxy]
    proxy = options[:proxy]
    if proxy.size == 2
      @agent.set_proxy(proxy[0], proxy[1].to_i)
    else
      @agent.set_proxy(proxy[0], proxy[1].to_i, proxy[2], proxy[3])
    end
  end

  puts 'PROCESSING: '.cyan.bold + 'protocol created'
  log('Protocol successfully created', 'CREATE_PROTOCOL')
end

#get_page(url) ⇒ Object



20
21
22
# File 'lib/instabot/create_protocol.rb', line 20

def get_page(url)
  @agent.get(url)
end

#set_mechanic_data(params = {}) ⇒ Object



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

def set_mechanic_data(params = {})
  @cookies   = Hash[@agent.cookies.map { |key, _value| [key.name, key.value] }]
  @params     = params
  @headers   = {
    'Cookie'           => "mid=#{@cookies['mid']}; csrftoken=#{@cookies['csrftoken']}; sessionid=#{@cookies['sessionid']}; ds_user_id=#{@cookies['ds_user_id']}; rur=#{@cookies['rur']}; s_network=#{@cookies['s_network']}; ig_pr= 1; ig_vw=1920",
    'X-CSRFToken'      => (@cookies['csrftoken']).to_s,
    'X-Requested-With' => 'XMLHttpRequest',
    'Content-Type'     => 'application/x-www-form-urlencoded',
    'X-Instagram-AJAX' => '1',
    'Accept'           => 'application/json, text/javascript, */*',
    'User-Agent'       => 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0',
    'Accept-Encoding'  => 'gzip, deflate',
    'Accept-Language'  => 'ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4',
    'Connection'       => 'keep-alive',
    'Host'             => 'www.instagram.com',
    'Origin'           => 'https://www.instagram.com',
    'Referer'          => 'https://www.instagram.com/'
  }
end