Module: GitHub::Client::Contents
- Included in:
- GitHub::Client
- Defined in:
- lib/github_api_v3/client/contents.rb
Overview
Methods for the Contents API.
These methods allow the retrieval of contents of files within a repository as Base64 encoded content.
Instance Method Summary collapse
-
#archive(owner, repo, format = 'zipball', ref = 'master') ⇒ String
Retrieve archive link.
-
#contents(owner, repo, path = '', ref = 'master') ⇒ Array, Hash
Get the contents of a file or directory.
-
#create_file(owner, repo, options = {}) ⇒ Hash
Create a file in a repository.
-
#delete_file(owner, repo, options = {}) ⇒ Hash
(also: #remove_file)
Delete a file in a repository.
-
#readme(owner, repo, ref = 'master') ⇒ Hash
Get the README of a repository.
-
#update_file(owner, repo, options = {}) ⇒ Hash
(also: #edit_file)
Update a file in a repository.
Instance Method Details
#archive(owner, repo, format = 'zipball', ref = 'master') ⇒ String
Retrieve archive link.
138 139 140 141 142 |
# File 'lib/github_api_v3/client/contents.rb', line 138 def archive(owner, repo, format='zipball', ref='master') request :get, "/repos/#{owner}/#{repo}/#{format}/#{ref}", no_follow: true rescue HTTParty::RedirectionTooDeep => e e.response['location'] end |
#contents(owner, repo, path = '', ref = 'master') ⇒ Array, Hash
Get the contents of a file or directory.
33 34 35 |
# File 'lib/github_api_v3/client/contents.rb', line 33 def contents(owner, repo, path='', ref='master') get "/repos/#{owner}/#{repo}/contents/#{path}", params: { ref: ref } end |
#create_file(owner, repo, options = {}) ⇒ Hash
Create a file in a repository.
Requires authentication.
61 62 63 64 |
# File 'lib/github_api_v3/client/contents.rb', line 61 def create_file(owner, repo, ={}) [:content] = Base64.strict_encode64([:content]) put "/repos/#{owner}/#{repo}/contents/#{options[:path]}", body: end |
#delete_file(owner, repo, options = {}) ⇒ Hash Also known as: remove_file
Delete a file in a repository.
Requires authentication.
122 123 124 |
# File 'lib/github_api_v3/client/contents.rb', line 122 def delete_file(owner, repo, ={}) delete "/repos/#{owner}/#{repo}/contents/#{options[:path]}", body: end |
#readme(owner, repo, ref = 'master') ⇒ Hash
Get the README of a repository.
21 22 23 |
# File 'lib/github_api_v3/client/contents.rb', line 21 def readme(owner, repo, ref='master') get "/repos/#{owner}/#{repo}/readme", params: { ref: ref } end |
#update_file(owner, repo, options = {}) ⇒ Hash Also known as: edit_file
Update a file in a repository.
Requires authentication.
92 93 94 95 |
# File 'lib/github_api_v3/client/contents.rb', line 92 def update_file(owner, repo, ={}) [:content] = Base64.strict_encode64([:content]) put "/repos/#{owner}/#{repo}/contents/#{options[:path]}", body: end |