Skip to content

Commit

Permalink
Rewrite the project
Browse files Browse the repository at this point in the history
  • Loading branch information
murjax committed Sep 6, 2023
1 parent 481fa5e commit f725995
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ruby/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source 'https://rubygems.org'

gem 'httparty'
gem 'rspec'
gem 'pry'
38 changes: 38 additions & 0 deletions ruby/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
GEM
remote: https://rubygems.org/
specs:
coderay (1.1.3)
diff-lcs (1.5.0)
httparty (0.21.0)
mini_mime (>= 1.0.0)
multi_xml (>= 0.5.2)
method_source (1.0.0)
mini_mime (1.1.5)
multi_xml (0.6.0)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
rspec (3.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-core (3.12.2)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-mocks (3.12.6)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-support (3.12.1)

PLATFORMS
x86_64-linux

DEPENDENCIES
httparty
pry
rspec

BUNDLED WITH
2.4.7
29 changes: 29 additions & 0 deletions ruby/cloner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'json'
require 'httparty'

class Cloner
def initialize(username)
@username = username
end

def call
Kernel.system(clone_command)
end

private

attr_reader :username

def info_url
"https://api.github.com/users/#{username}/repos"
end

def repo_info
repo_info_response = HTTParty.get(info_url)
JSON.parse(repo_info_response)
end

def clone_command
repo_info.map { |info| "git clone #{info['clone_url']}" }.join(' & ')
end
end
37 changes: 37 additions & 0 deletions ruby/spec/cloner_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require_relative '../cloner.rb'
require 'json'
require 'httparty'

RSpec.describe Cloner do
subject(:call) { described_class.new(username).call }

context 'valid username with repos' do
let(:username) { 'murjax' }
let(:clone_url1) { 'https://github.com/murjax/spring_engine.git' }
let(:clone_url2) { 'https://github.com/murjax/burger_bot.git' }
let(:repo_info_url) { "https://api.github.com/users/#{username}/repos" }
let(:repo_info) { [{ 'clone_url' => clone_url1 }, { 'clone_url' => clone_url2 }] }
let(:serialized_repo_info) { JSON.generate(repo_info) }
let(:command1) { "git clone #{clone_url1}" }
let(:command2) { "git clone #{clone_url2}" }
let(:final_command) { "#{command1} & #{command2}" }

it 'runs clone commands' do
expect(HTTParty).to receive(:get).with(repo_info_url).and_return(serialized_repo_info)
expect(Kernel).to receive(:system).with(final_command)
call
end
end

context 'valid username without repos' do

end

context 'username not found' do

end

context 'username nil' do

end
end

0 comments on commit f725995

Please sign in to comment.