Module: Octokit::Client::Contents
- Included in:
- Octokit::Client
- Defined in:
- lib/octokit/client/contents.rb
Instance Method Summary collapse
-
#archive_link(repo, options = {}) ⇒ String
This method will provide a URL to download a tarball or zipball archive for a repository.
-
#contents(repo, options = {}) ⇒ Hash
(also: #content)
Receive a listing of a repository folder or the contents of a file.
-
#create_contents(*args) ⇒ Hash
(also: #create_content, #add_content, #add_contents)
Add content to a repository.
-
#delete_contents(repo, path, message, sha, options = {}) ⇒ Hash
(also: #delete_content, #remove_content, #remove_contents)
Delete content in a repository.
-
#readme(repo, options = {}) ⇒ Hash
Receive the default Readme for a repository.
-
#update_contents(*args) ⇒ Hash
(also: #update_content)
Update content in a repository.
Instance Method Details
#archive_link(repo, options = {}) ⇒ String
This method will provide a URL to download a tarball or zipball archive for a repository.
144 145 146 147 148 149 |
# File 'lib/octokit/client/contents.rb', line 144 def archive_link(repo, ={}) repo_ref = .delete :ref format = (.delete :format) || 'tarball' url = "repos/#{Repository.new repo}/#{format}/#{repo_ref}" request(:head, url, ).env[:url].to_s end |
#contents(repo, options = {}) ⇒ Hash Also known as: content
Receive a listing of a repository folder or the contents of a file
28 29 30 31 32 |
# File 'lib/octokit/client/contents.rb', line 28 def contents(repo, ={}) repo_path = .delete :path url = "repos/#{Repository.new repo}/contents/#{repo_path}" get(url, ) end |
#create_contents(*args) ⇒ Hash Also known as: create_content, add_content, add_contents
Add content to a repository
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/octokit/client/contents.rb', line 51 def create_contents(*args) = args.last.is_a?(Hash) ? args.pop : {} repo = args.shift path = args.shift = args.shift content = args.shift if content.nil? && file = .delete(:file) case file when String if File.exists?(file) file = File.open(file, "r") content = file.read file.close end when File content = file.read file.close end end raise ArgumentError.new "content or :file option required" if content.nil? [:content] = Base64.encode64(content).delete("\r\n") [:message] = url = "repos/#{Repository.new repo}/contents/#{path}" put(url, ) end |
#delete_contents(repo, path, message, sha, options = {}) ⇒ Hash Also known as: delete_content, remove_content, remove_contents
Delete content in a repository
125 126 127 128 129 130 |
# File 'lib/octokit/client/contents.rb', line 125 def delete_contents(repo, path, , sha, = {}) [:message] = [:sha] = sha url = "repos/#{Repository.new repo}/contents/#{path}" delete(url, ) end |
#readme(repo, options = {}) ⇒ Hash
Receive the default Readme for a repository
15 16 17 |
# File 'lib/octokit/client/contents.rb', line 15 def readme(repo, ={}) get("repos/#{Repository.new repo}/readme", ) end |
#update_contents(*args) ⇒ Hash Also known as: update_content
Update content in a repository
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/octokit/client/contents.rb', line 98 def update_contents(*args) = args.last.is_a?(Hash) ? args.pop : {} repo = args.shift path = args.shift = args.shift sha = args.shift content = args.shift .merge!(:sha => sha) create_contents(repo, path, , content, ) end |