Sha256: 70475a01896711246b0c645a5be8a0785341afb2412565bacf91e4593c110f9a

Contents?: true

Size: 1.73 KB

Versions: 1

Compression:

Stored size: 1.73 KB

Contents

module ZombieFans::Actions
  module User
    def update_profile
      agent.get('https://github.com/settings/profile') do |page|
        page.form_with(action: "/users/#{login}") 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

    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

  private

    def sample_display_name
      names = name.split(' ')
      names = [names.join('-').downcase, names.first.downcase, names.last.downcase, name, name, name, name, name, names.first, names.last].sample
    end

    def sample_result result, weight1 = 1, weight2 = 1
      ([nil] * weight1 + [result] * weight2).sample
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
zombie_fans-0.2.0 lib/zombie_fans/actions/user.rb