Class: Github::Client::Repos::Contents
- Defined in:
- lib/github_api2/client/repos/contents.rb
Overview
These API methods let you retrieve the contents of files within a repository as Base64 encoded content.
Constant Summary collapse
- REQUIRED_CONTENT_OPTIONS =
%w[ path message content ]
Constants included from MimeType
Constants included from Github::Constants
Github::Constants::ACCEPT, Github::Constants::ACCEPTED_OAUTH_SCOPES, Github::Constants::ACCEPT_CHARSET, Github::Constants::CACHE_CONTROL, Github::Constants::CONTENT_LENGTH, Github::Constants::CONTENT_TYPE, Github::Constants::DATE, Github::Constants::ETAG, Github::Constants::HEADER_LAST, Github::Constants::HEADER_LINK, Github::Constants::HEADER_NEXT, Github::Constants::LOCATION, Github::Constants::META_FIRST, Github::Constants::META_LAST, Github::Constants::META_NEXT, Github::Constants::META_PREV, Github::Constants::META_REL, Github::Constants::OAUTH_SCOPES, Github::Constants::PARAM_PAGE, Github::Constants::PARAM_PER_PAGE, Github::Constants::PARAM_START_PAGE, Github::Constants::RATELIMIT_LIMIT, Github::Constants::RATELIMIT_REMAINING, Github::Constants::RATELIMIT_RESET, Github::Constants::SERVER, Github::Constants::USER_AGENT
Instance Attribute Summary
Attributes inherited from API
Instance Method Summary collapse
-
#archive(*args) ⇒ Object
Get archive link.
-
#create(*args) ⇒ Object
Create a file.
-
#delete(*args) ⇒ Object
Delete a file.
-
#get(*args) ⇒ Object
(also: #find)
Get contents.
-
#license(*args) ⇒ Object
Get the LICENSE.
-
#readme(*args) ⇒ Object
Get the README.
-
#update(*args) ⇒ Object
Update a file.
Methods inherited from API
after_callbacks, after_request, #api_methods_in, #arguments, before_callbacks, before_request, clear_request_methods!, #disable_redirects, #execute, extend_with_actions, extra_methods, #extract_basic_auth, extract_class_name, #filter_callbacks, inherited, #initialize, internal_methods, method_added, #method_missing, #module_methods_in, namespace, request_methods, require_all, #respond_to?, root!, #run_callbacks, #set, #yield_or_eval
Methods included from Request::Verbs
#delete_request, #get_request, #head_request, #options_request, #patch_request, #post_request, #put_request
Methods included from RateLimit
#ratelimit, #ratelimit_remaining, #ratelimit_reset
Methods included from MimeType
Methods included from Authorization
#auth_code, #authenticated?, #authentication, #authorize_url, #basic_authed?, #client, #get_token
Constructor Details
This class inherits a constructor from Github::API
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Github::API
Instance Method Details
#archive(*args) ⇒ Object
For private repositories, these links are temporary and expire quickly.
Get archive link
This method will return a 302 to a URL to download a tarball or zipball archive for a repository. Please make sure your HTTP framework is configured to follow redirects or you will need to use the Location header to make a second GET request.
251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/github_api2/client/repos/contents.rb', line 251 def archive(*args) arguments(args, required: [:user, :repo]) params = arguments.params archive_format = params.delete('archive_format') || 'tarball' ref = params.delete('ref') || 'master' disable_redirects do response = get_request("/repos/#{arguments.user}/#{arguments.repo}/#{archive_format}/#{ref}", params) response.headers.location end end |
#create(*args) ⇒ Object
Create a file
This method creates a new file in a repository
Optional Parameters
The :author section is optional and is filled in with the :committer information if omitted. If the :committer information is omitted, the authenticated user’s information is used.
You must provide values for both :name and :email, whether you choose to use :author or :committer. Otherwise, you’ll receive a 500 status code.
Both the author and commiter parameters have the same keys:
121 122 123 124 125 126 127 128 129 |
# File 'lib/github_api2/client/repos/contents.rb', line 121 def create(*args) arguments(args, required: [:user, :repo, :path]) do assert_required REQUIRED_CONTENT_OPTIONS end params = arguments.params params.strict_encode64('content') put_request("/repos/#{arguments.user}/#{arguments.repo}/contents/#{arguments.path}", params) end |
#delete(*args) ⇒ Object
Delete a file
This method deletes a file in a repository
Optional Parameters
The :author section is optional and is filled in with the :committer information if omitted. If the :committer information is omitted, the authenticated user’s information is used.
You must provide values for both :name and :email, whether you choose to use :author or :committer. Otherwise, you’ll receive a 500 status code.
Both the author and commiter parameters have the same keys:
219 220 221 222 223 224 225 |
# File 'lib/github_api2/client/repos/contents.rb', line 219 def delete(*args) arguments(args, required: [:user, :repo, :path]) do assert_required %w[ path message sha ] end delete_request("/repos/#{arguments.user}/#{arguments.repo}/contents/#{arguments.path}", arguments.params) end |
#get(*args) ⇒ Object Also known as: find
Get contents
This method returns the contents of any file or directory in a repository.
73 74 75 76 77 |
# File 'lib/github_api2/client/repos/contents.rb', line 73 def get(*args) arguments(args, required: [:user, :repo, :path]) get_request("/repos/#{arguments.user}/#{arguments.repo}/contents/#{arguments.path}", arguments.params) end |
#license(*args) ⇒ Object
Get the LICENSE
This method returns the contents of the repository’s license file, if one is detected.
47 48 49 50 51 |
# File 'lib/github_api2/client/repos/contents.rb', line 47 def license(*args) arguments(args, required: [:user, :repo]) get_request("/repos/#{arguments.user}/#{arguments.repo}/license", arguments.params) end |
#readme(*args) ⇒ Object
Get the README
This method returns the preferred README for a repository.
30 31 32 33 34 |
# File 'lib/github_api2/client/repos/contents.rb', line 30 def readme(*args) arguments(args, required: [:user, :repo]) get_request("/repos/#{arguments.user}/#{arguments.repo}/readme", arguments.params) end |
#update(*args) ⇒ Object
Update a file
This method updates a file in a repository
Optional Parameters
The :author section is optional and is filled in with the :committer information if omitted. If the :committer information is omitted, the authenticated user’s information is used.
You must provide values for both :name and :email, whether you choose to use :author or :committer. Otherwise, you’ll receive a 500 status code.
Both the author and commiter parameters have the same keys:
175 176 177 |
# File 'lib/github_api2/client/repos/contents.rb', line 175 def update(*args) create(*args) end |