Module: Octokit::Client::Contents
- Included in:
- Octokit::Client
- Defined in:
- lib/octokit/client/contents.rb
Overview
Methods for the Repo Contents API
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 = {}) ⇒ Sawyer::Resource
(also: #content)
Receive a listing of a repository folder or the contents of a file.
-
#create_contents(repo, path, message, content = nil, options = {}) ⇒ Sawyer::Resource
(also: #create_content, #add_content, #add_contents)
Add content to a repository.
-
#delete_contents(repo, path, message, sha, options = {}) ⇒ Sawyer::Resource
(also: #delete_content, #remove_content, #remove_contents)
Delete content in a repository.
-
#readme(repo, options = {}) ⇒ Sawyer::Resource
Receive the default Readme for a repository.
-
#update_contents(repo, path, message, sha, content = nil, options = {}) ⇒ Sawyer::Resource
(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.
154 155 156 157 158 159 160 161 |
# File 'lib/octokit/client/contents.rb', line 154 def archive_link(repo, ={}) repo_ref = .delete :ref format = (.delete :format) || 'tarball' url = "#{Repository.path repo}/#{format}/#{repo_ref}" response = client_without_redirects.head(url, ) response.headers['Location'] end |
#contents(repo, options = {}) ⇒ Sawyer::Resource Also known as: content
Receive a listing of a repository folder or the contents of a file
32 33 34 35 36 37 |
# File 'lib/octokit/client/contents.rb', line 32 def contents(repo, ={}) = .dup repo_path = .delete :path url = "#{Repository.path repo}/contents/#{repo_path}" get url, end |
#create_contents(repo, path, message, content = nil, options = {}) ⇒ Sawyer::Resource Also known as: create_content, add_content, add_contents
Add content to a repository
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/octokit/client/contents.rb', line 57 def create_contents(*args) args = args.map { |item| item && item.dup } = 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.exist?(file) file = File.open(file, "r") content = file.read file.close end when File, Tempfile content = file.read file.close end end raise ArgumentError.new("content or :file option required") if content.nil? [:content] = Base64.respond_to?(:strict_encode64) ? Base64.strict_encode64(content) : Base64.encode64(content).delete("\n") # Ruby 1.9.2 [:message] = url = "#{Repository.path repo}/contents/#{path}" put url, end |
#delete_contents(repo, path, message, sha, options = {}) ⇒ Sawyer::Resource Also known as: delete_content, remove_content, remove_contents
Delete content in a repository
135 136 137 138 139 140 |
# File 'lib/octokit/client/contents.rb', line 135 def delete_contents(repo, path, , sha, = {}) [:message] = [:sha] = sha url = "#{Repository.path repo}/contents/#{path}" delete url, end |
#readme(repo, options = {}) ⇒ Sawyer::Resource
Receive the default Readme for a repository
19 20 21 |
# File 'lib/octokit/client/contents.rb', line 19 def readme(repo, ={}) get "#{Repository.path repo}/readme", end |
#update_contents(repo, path, message, sha, content = nil, options = {}) ⇒ Sawyer::Resource Also known as: update_content
Update content in a repository
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/octokit/client/contents.rb', line 108 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 |