require 'net/http'
require 'json'

file  = {"Cooperativa-Cultural"=>[{"author"=>"Igor Marques da Silva","gem"=>"rails"},{"author"=>"Igor Marques da Silva","gem"=>"sass-rails"},{"author"=>"Igor Marques da Silva","gem"=>"uglifier"},{"author"=>"Igor Marques da Silva","gem"=>"coffee-rails"},{"author"=>"Igor Marques da Silva","gem"=>"chosen-rails"},{"author"=>"Igor Marques da Silva","gem"=>"jquery-rails"},{"author"=>"Igor Marques da Silva","gem"=>"turbolinks"},{"author"=>"Igor Marques da Silva","gem"=>"jbuilder"},{"author"=>"Igor Marques da Silva","gem"=>"sdoc"},{"author"=>"Igor Marques da Silva","gem"=>"spring"},{"author"=>"Igor Marques da Silva","gem"=>"friendly_id"},{"author"=>"Igor Marques da Silva","gem"=>"simple_form"},{"author"=>"Igor Marques da Silva","gem"=>"devise"},{"author"=>"Igor Marques da Silva","gem"=>"bootstrap-sass"},{"author"=>"Igor Marques da Silva","gem"=>"autoprefixer-rails"},{"author"=>"Igor Marques da Silva","gem"=>"carrierwave"},{"author"=>"Igor Marques da Silva","gem"=>"font-awesome-sass"},{"author"=>"Marcos Siqueira Jr","gem"=>"rails4-autocomplete"}],"Eleja-se"=>[{"author"=>"Igor Marques da Silva","gem"=>"devise"},{"author"=>"Lucas Bibiano","gem"=>"rails"},{"author"=>"Igor Marques da Silva","gem"=>"sass-rails"},{"author"=>"Igor Marques da Silva","gem"=>"uglifier"},{"author"=>"Igor Marques da Silva","gem"=>"coffee-rails"},{"author"=>"Igor Marques da Silva","gem"=>"jquery-rails"},{"author"=>"Igor Marques da Silva","gem"=>"jbuilder"},{"author"=>"Igor Marques da Silva","gem"=>"sdoc"},{"author"=>"Igor Marques da Silva","gem"=>"spring"},{"author"=>"Iago","gem"=>"bootstrap-sass"},{"author"=>"Igor Marques da Silva","gem"=>"font-awesome-sass"},{"author"=>"Iago","gem"=>"simple_form"},{"author"=>"Iago","gem"=>"validates_cpf_cnpj"},{"author"=>"Igor Marques da Silva","gem"=>"seedbank"},{"author"=>"Igor Marques da Silva","gem"=>"draper"},{"author"=>"Igor Marques da Silva","gem"=>"cancancan"},{"author"=>"Luiz Rogério","gem"=>"rails_12factor"}],"gepe-manager"=>[{"author"=>"MildoOSJ","gem"=>"twitter-bootstrap-rails"},{"author"=>"Higorhicaro","gem"=>"rails"},{"author"=>"andreza","gem"=>"sass-rails"},{"author"=>"Higorhicaro","gem"=>"draper"},{"author"=>"Higorhicaro","gem"=>"uglifier"},{"author"=>"Higorhicaro","gem"=>"coffee-rails"},{"author"=>"Karyd'ja","gem"=>"therubyracer"},{"author"=>"Higorhicaro","gem"=>"jquery-rails"},{"author"=>"Higorhicaro","gem"=>"turbolinks"},{"author"=>"Higorhicaro","gem"=>"jbuilder"},{"author"=>"Higorhicaro","gem"=>"rails_12factor"},{"author"=>"Higorhicaro","gem"=>"bootstrap-sass"},{"author"=>"Higorhicaro","gem"=>"simple_form"},{"author"=>"Higorhicaro","gem"=>"puma"},{"author"=>"Higorhicaro","gem"=>"magic_encoding"},{"author"=>"Igor Marques da Silva","gem"=>"kaminari"},{"author"=>"Higorhicaro","gem"=>"bootswatch-rails"},{"author"=>"Higorhicaro","gem"=>"coveralls"},{"author"=>"Higorhicaro","gem"=>"devise"},{"author"=>"Higorhicaro","gem"=>"chosen-rails"},{"author"=>"Lucas Bibiano","gem"=>"unicorn"},{"author"=>"Higorhicaro","gem"=>"nested_form"},{"author"=>"Igor Marques da Silva","gem"=>"newrelic_rpm"},{"author"=>"Higorhicaro","gem"=>"ransack"},{"author"=>"Higorhicaro","gem"=>"by_star"},{"author"=>"Victor Hugo de Oliveira","gem"=>"maskedinput-rails"},{"author"=>"Victor Hugo de Oliveira","gem"=>"font-awesome-sass"},{"author"=>"Victor Hugo de Oliveira","gem"=>"summernote-rails"},{"author"=>"higor","gem"=>"wicked_pdf"},{"author"=>"bengurgel","gem"=>"wkhtmltopdf-binary"}],"iglesiasapi"=>[{"author"=>"Lucas Bibiano","gem"=>"draper"},{"author"=>"Lucas Bibiano","gem"=>"devise"},{"author"=>"Igor Marques da Silva","gem"=>"validates_cpf_cnpj"},{"author"=>"Lucas Bibiano","gem"=>"rest_client"},{"author"=>"Lucas Bibiano","gem"=>"carrierwave"},{"author"=>"Lucas Bibiano","gem"=>"fog"},{"author"=>"Lucas Bibiano","gem"=>"ransack"},{"author"=>"Lucas Bibiano","gem"=>"simple_form"},{"author"=>"Lucas Bibiano","gem"=>"rails"},{"author"=>"Lucas Bibiano","gem"=>"sass-rails"},{"author"=>"Lucas Bibiano","gem"=>"bootstrap-sass"},{"author"=>"Lucas Bibiano","gem"=>"bootswatch-rails"},{"author"=>"Igor Marques da Silva","gem"=>"font-awesome-sass"},{"author"=>"Lucas Bibiano","gem"=>"uglifier"},{"author"=>"Lucas Bibiano","gem"=>"coffee-rails"},{"author"=>"Lucas Bibiano","gem"=>"jquery-rails"},{"author"=>"Lucas Bibiano","gem"=>"turbolinks"},{"author"=>"Lucas Bibiano","gem"=>"jbuilder"},{"author"=>"Lucas Bibiano","gem"=>"sdoc"},{"author"=>"Lucas Bibiano","gem"=>"rails_12factor"},{"author"=>"Igor Marques da Silva","gem"=>"factory_girl"},{"author"=>"Igor Marques da Silva","gem"=>"maskedinput-rails"},{"author"=>"Igor Marques da Silva","gem"=>"valid_email"},{"author"=>"Igor Marques da Silva","gem"=>"cancancan"},{"author"=>"Igor Marques da Silva","gem"=>"chosen-rails"}],"LuLanches"=>[{"author"=>"karydja","gem"=>"rails"},{"author"=>"karydja","gem"=>"pg"},{"author"=>"SeuRAUL","gem"=>"sass-rails"},{"author"=>"SeuRAUL","gem"=>"uglifier"},{"author"=>"SeuRAUL","gem"=>"coffee-rails"},{"author"=>"Karyd'ja","gem"=>"therubyracer"},{"author"=>"SeuRAUL","gem"=>"jquery-rails"},{"author"=>"Iago","gem"=>"momentjs-rails"},{"author"=>"Iago","gem"=>"bootstrap-daterangepicker-rails"},{"author"=>"SeuRAUL","gem"=>"jbuilder"},{"author"=>"Iago","gem"=>"kaminari"},{"author"=>"Iago","gem"=>"has_scope"},{"author"=>"karydja","gem"=>"simple_form"},{"author"=>"Karyd'ja","gem"=>"compass-rails"},{"author"=>"karydja","gem"=>"bootstrap-sass"},{"author"=>"Karyd'ja","gem"=>"bootswatch-rails"},{"author"=>"karydja","gem"=>"chosen-rails"},{"author"=>"SeuRAUL","gem"=>"devise"},{"author"=>"SeuRAUL","gem"=>"cancancan"},{"author"=>"karydja","gem"=>"maskedinput-rails"},{"author"=>"karydja","gem"=>"rails_12factor"},{"author"=>"SeuRAUL","gem"=>"rspec"},{"author"=>"SeuRAUL","gem"=>"rspec-rails"},{"author"=>"SeuRAUL","gem"=>"shoulda-matchers"},{"author"=>"SeuRAUL","gem"=>"factory_girl_rails"},{"author"=>"SeuRAUL","gem"=>"capybara"},{"author"=>"SeuRAUL","gem"=>"simplecov"},{"author"=>"Raquel","gem"=>"autoprefixer-rails"},{"author"=>"Raquel","gem"=>"sprockets-rails"},{"author"=>"Raquel","gem"=>"font-awesome-sass"},{"author"=>"Iago","gem"=>"draper"}]}

devs = {}

file.each do |project, gem_list|
  # puts gem_list
  gem_list.each do |gem_author|
     a = gem_author["author"]
     g = gem_author["gem"]

     devs[a] = {} if !devs.keys.include? a

     if devs[a].keys.include?(g)
        devs[a][g][:qtd] += 1
     else
       devs[a][g] = {}
       devs[a][g][:qtd] = 1


       url = URI.parse('http://rubygems.org/api/v1/gems/' + g + '.json')
       req = Net::HTTP::Get.new(url.to_s)
       res = Net::HTTP.start(url.host, url.port) {|http|
         http.request(req)
       }

       devs[a][g][:desc] = JSON.parse(res.body)["info"]

       puts "Downloading info for #{g}"
     end

  end
end

devs.delete("MildoOSJ")

devs.each do |dev, gems|
  puts "-----" + dev + "-----"
  puts "\nGEMS:\n\n"

  i = 0

  gems.each do |g, c|
    puts "#{g}: #{c[:qtd]} - #{c[:desc][0..100][...]}\n" 
    i += 1
  end

  puts "\n"
  puts "TOTAL: #{i}"
  puts "\n"

end
