Class: Hyrb::Tasks::Developers::Download

Inherits:
Hyrb::Task
  • Object
show all
Defined in:
lib/hyrb/tasks/developers.rb

Instance Attribute Summary

Attributes inherited from Hyrb::Task

#env, #pipeline

Instance Method Summary collapse

Methods inherited from Hyrb::Task

depends, #initialize, prompt, prompts, #run_before

Constructor Details

This class inherits a constructor from Hyrb::Task

Instance Method Details

#run(env) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/hyrb/tasks/developers.rb', line 35

def run(env)
  response = Faraday.post "https://accounts.google.com/o/oauth2/token",
    refresh_token: env.creds.google_refresh_token,
    client_id:     env.creds.google_client_id,
    client_secret: env.creds.google_client_secret,
    grant_type:    "refresh_token"

  access_token = JSON.parse(response.body)['access_token']
  seeder = GoogleDocSeed.new(access_token)
  csv_string = seeder.to_csv_string(env.creds.google_spreadsheet_key)

  csv = CSV.parse(csv_string, GoogleCSVConverters::CSV_SETTINGS)

  env.developers = Hyrb::Models::Cache::Developers.new
  env.developers.data = csv.map do |row|
    pks = []
    while true
      field = row.delete(:public_key)
      if field.length > 1
        pks << field[1] if field[1]
      else
        break
      end
    end

    Hyrb::Models::Developer.new({
      name:            row[:name],
      email:           row[:email],
      role:            Hyrb::Models::Developer::ROLE_MAP[row[:role].to_i],
      github_username: row[:github],
      keys:            pks,
    }) if row[:role].to_i < 4 && row[:email]
  end.compact

  env.developers.save!
  say "Developer data downloaded", :green
end