Class: FastGithub::Repo

Inherits:
Object
  • Object
show all
Defined in:
lib/fast_github.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#directoryObject

Returns the value of attribute directory.



66
67
68
# File 'lib/fast_github.rb', line 66

def directory
  @directory
end

#remote_nameObject

Returns the value of attribute remote_name.



66
67
68
# File 'lib/fast_github.rb', line 66

def remote_name
  @remote_name
end

#upload_responseObject

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

#createObject



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

#uploadObject



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