Sha256: 256e0d82d61214e4ad08df56a9c52051e91ba32f0173cb9e044090233d824386

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

module Love
  class Author

    attr_reader :name, :info, :gems, :username

    def initialize(name, fetch = true)
      @name = name
      @gems = []
      fetch_info if fetch
    end

    def fetch_info
      uri = ERB::Util.url_encode(name)
      puts "search for #{name}"
      begin
        search_person = Love.octokit.search_users uri
        @info = \
          if search_person.count > 1
            puts '!!! THERE ARE SEVERAL PERSONS WITH THIS NAME IN GITHUB !!!'
            puts "Please check right man with his number and we'll continue"
            search_person.each_with_index do |person, index|
              puts "#{index} - name: #{person.name}; login: #{person.login}; username: #{person.username}"
            end

            user_num = $stdin.gets.chomp.to_i
            Love.octokit.user search_person[user_num].login
          else
            Love.octokit.user search_person.first.login
          end
        puts "found #{@info.login}"
      rescue Octokit::Forbidden
        puts 'github have some unfair limits =('
      rescue
        puts 'not found'
      end
    end

    def add_gem(gem)
      @gems << gem
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
share_some_love-0.0.5 lib/love/author.rb