Module: ZombieFans::Actions::User

Included in:
Robot
Defined in:
lib/zombie_fans/actions/user.rb

Instance Method Summary collapse

Instance Method Details

#follow_user(user) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/zombie_fans/actions/user.rb', line 21

def follow_user user
  page = agent.get("https://github.com/#{user}")
  form = page.at('.user-following-container:not(.on) .follow form')
  return unless form

  log_action 'FollowUser', "#{user}."

  authenticity_token = form.at('input[name=authenticity_token]').attr('value')
  follow_user_url = form.attr('action')

  query = {
    authenticity_token: authenticity_token
  }

  header = {
    'X-Requested-With' => 'XMLHttpRequest'
  }

  # agent.agent.allowed_error_codes = [400]
  page = agent.post(follow_user_url, query, header)
  response = JSON.parse page.body
end

#update_profileObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/zombie_fans/actions/user.rb', line 3

def update_profile
  agent.get('https://github.com/settings/profile') do |page|
    page.form_with(action: "/users/#{}") do |form|
      name = sample_display_name
      blog = sample_result Faker::Internet.url, 2
      company = sample_result Faker::Company.name, 1, 2
      location = sample_result Faker::Address.city, 1, 2

      log_action 'UpdateProfile', "with name: #{name}, blog: #{blog || 'nil'}, company: #{company || 'nil'}, location: #{location || 'nil'}."

      form['user[profile_name]'] = name
      form['user[profile_blog]'] = blog
      form['user[profile_company]'] = company
      form['user[profile_location]'] = location
    end.submit
  end
end