Movatterモバイル変換


[0]ホーム

URL:


Libraries »piotrmurach/github(master) »Index (C) »Github »Client »Repos »Contents

Class: Github::Client::Repos::Contents

Inherits:
API
  • Object
  • API
  • Github::Client::Repos::Contents
show all
Defined in:
lib/github_api/client/repos/contents.rb

Overview

These API methods let you retrieve the contents of files within a repository as Base64 encoded content.

Constant Summarycollapse

REQUIRED_CONTENT_OPTIONS =
%w[ path message content ]

Constants included fromMimeType

MimeType::MEDIA_LOOKUP

Constants included fromGithub::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 fromAPI

#current_options

Instance Method Summarycollapse

Methods inherited fromAPI

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 fromRequest::Verbs

#delete_request,#get_request,#head_request,#options_request,#patch_request,#post_request,#put_request

Methods included fromRateLimit

#ratelimit,#ratelimit_remaining,#ratelimit_reset

Methods included fromMimeType

#lookup_media,#parse

Methods included fromAuthorization

#auth_code,#authenticated?,#authentication,#authorize_url,#basic_authed?,#client,#get_token

Constructor Details

This class inherits a constructor fromGithub::API

Dynamic Method Handling

This class handles dynamic methods through themethod_missing method in the classGithub::API

Instance Method Details

#archive(*args) ⇒Object

Note:

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.

Examples:

github=Github.newgithub.repos.contents.archive'user-name','repo-name',archive_format:"tarball",ref:"master"

Parameters:

251252253254255256257258259260261
# File 'lib/github_api/client/repos/contents.rb', line 251defarchive(*args)arguments(args,required:[:user,:repo])params=arguments.paramsarchive_format=params.delete('archive_format')||'tarball'ref=params.delete('ref')||'master'disable_redirectsdoresponse=get_request("/repos/#{arguments.user}/#{arguments.repo}/#{archive_format}/#{ref}",params)response.headers.locationendend

#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:

Examples:

github=Github.newgithub.repos.contents.create'user-name','repo-name','path',path:'hello.rb',content:"puts 'hello ruby'",message:"my commit message"

Parameters:

121122123124125126127128129
# File 'lib/github_api/client/repos/contents.rb', line 121defcreate(*args)arguments(args,required:[:user,:repo,:path])doassert_requiredREQUIRED_CONTENT_OPTIONSendparams=arguments.paramsparams.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:

Examples:

github=Github.newgithub.repos.contents.delete'user-name','repo-name','path',path:'hello.rb',message:"delete hello.rb file",sha:"329688480d39049927147c162b9d2deaf885005f"

Parameters:

219220221222223224225
# File 'lib/github_api/client/repos/contents.rb', line 219defdelete(*args)arguments(args,required:[:user,:repo,:path])doassert_required%w[ path message sha ]enddelete_request("/repos/#{arguments.user}/#{arguments.repo}/contents/#{arguments.path}",arguments.params)end

#get(*args) ⇒ObjectAlso known as:find

Get contents

This method returns the contents of any file or directory in a repository.

Examples:

github=Github.newgithub.repos.contents.get'user-name','repo-name','path'
github=Github.newuser:'user-name',repo:'repo-name'github.repos.contents.getpath:'README.md'

Parameters:

7374757677
# File 'lib/github_api/client/repos/contents.rb', line 73defget(*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.

Examples:

github=Github.newgithub.repos.contents.license'user-name','repo-name'

Parameters:

4748495051
# File 'lib/github_api/client/repos/contents.rb', line 47deflicense(*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.

Examples:

github=Github.newgithub.repos.contents.readme'user-name','repo-name'
content=Github::Client::Repos::Contents.newuser:'user-name',repo:'repo-name'content.readme

Parameters:

3031323334
# File 'lib/github_api/client/repos/contents.rb', line 30defreadme(*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:

Examples:

github=Github.newgithub.repos.contents.update'user-name','repo-name','path',path:'hello.rb',content:"puts 'hello ruby again'",message:"my commit message",sha:"25b0bef9e404bd2e3233de26b7ef8cbd86d0e913"

Parameters:

175176177
# File 'lib/github_api/client/repos/contents.rb', line 175defupdate(*args)create(*args)end
Generated on Sun Nov 16 02:10:26 2025 byyard 0.9.37 (ruby-3.4.3).

[8]ページ先頭

©2009-2025 Movatter.jp