Class: Reposit::RepositoryMaker
- Inherits:
-
Object
- Object
- Reposit::RepositoryMaker
- Defined in:
- lib/reposit.rb
Instance Attribute Summary collapse
-
#repo_name ⇒ Object
readonly
Returns the value of attribute repo_name.
Class Method Summary collapse
Instance Method Summary collapse
- #copy_response(response) ⇒ Object
- #create ⇒ Object
-
#initialize(repo_name) ⇒ RepositoryMaker
constructor
A new instance of RepositoryMaker.
Constructor Details
#initialize(repo_name) ⇒ RepositoryMaker
Returns a new instance of RepositoryMaker.
11 12 13 |
# File 'lib/reposit.rb', line 11 def initialize(repo_name) @repo_name = repo_name end |
Instance Attribute Details
#repo_name ⇒ Object (readonly)
Returns the value of attribute repo_name.
9 10 11 |
# File 'lib/reposit.rb', line 9 def repo_name @repo_name end |
Class Method Details
.run(repo_name) ⇒ Object
15 16 17 |
# File 'lib/reposit.rb', line 15 def self.run(repo_name) new(repo_name).create end |
Instance Method Details
#copy_response(response) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/reposit.rb', line 36 def copy_response(response) original_stdout = $stdout $stdout = fake = StringIO.new begin ap JSON.parse(response.body) ensure $stdout = original_stdout end File.open('temp_response', 'w+') do |f| f.write fake.string end `sed -n '/"ssh_url"/p' temp_response | gawk 'match($0, /m{1}"(.*)"/, ary) {print ary[1]}' | pbcopy` FileUtils.rm('temp_response') end |
#create ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/reposit.rb', line 19 def create credential_reader = CredentialsReader.new username = credential_reader.username api_key = credential_reader.api_key conn = Faraday.new(url: 'https://api.github.com') do |faraday| faraday.adapter Faraday.default_adapter faraday.basic_auth(username, api_key) end response = conn.post do |req| req.url '/user/repos' req.body = "{ \"name\": \"#{repo_name}\" }" end copy_response(response) end |