Class: FastGithub::Repo
- Inherits:
-
Object
- Object
- FastGithub::Repo
- Defined in:
- lib/fast_github.rb
Instance Attribute Summary collapse
-
#directory ⇒ Object
Returns the value of attribute directory.
-
#remote_name ⇒ Object
Returns the value of attribute remote_name.
-
#upload_response ⇒ Object
Returns the value of attribute upload_response.
Instance Method Summary collapse
- #create ⇒ Object
-
#initialize(token, remote_name = nil, dir = Dir.pwd) ⇒ Repo
constructor
A new instance of Repo.
- #upload ⇒ Object
Constructor Details
#initialize(token, remote_name = nil, dir = Dir.pwd) ⇒ Repo
Returns a new instance of Repo.
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/fast_github.rb', line 68 def initialize(token, remote_name=nil, dir=Dir.pwd) @token = token @directory = dir @upload_response = '' if remote_name && !remote_name.empty? @remote_name = remote_name else @remote_name = Dir.pwd[/[A-Za-z0-9_.-]*?(\/|)$/].gsub("/","") #regex pulls out folder name based on forward slashes end end |
Instance Attribute Details
#directory ⇒ Object
Returns the value of attribute directory.
66 67 68 |
# File 'lib/fast_github.rb', line 66 def directory @directory end |
#remote_name ⇒ Object
Returns the value of attribute remote_name.
66 67 68 |
# File 'lib/fast_github.rb', line 66 def remote_name @remote_name end |
#upload_response ⇒ Object
Returns the value of attribute upload_response.
66 67 68 |
# File 'lib/fast_github.rb', line 66 def upload_response @upload_response end |
Instance Method Details
#create ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/fast_github.rb', line 80 def create if !File.exists? @directory + "/.git" Dir.chdir @directory puts `git init` puts `git add -A .` puts `git commit -a -m "Initial commit"` end end |
#upload ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/fast_github.rb', line 89 def upload uri = URI.parse("https://api.github.com/user/repos") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' =>'application/json'}) request["Authorization"] = "token #{@token}" request.body = { "name" => @remote_name }.to_json response = http.request(request) if response.code[0] == "2" @upload_response == 'Success' else @upload_response == 'Failed' return end repo_fullname = (JSON.parse response.body)['full_name'] puts `git remote add origin [email protected]:#{repo_fullname}.git` puts `git push -u origin master` end |