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

Inherits:
API
  • Object
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 Summary collapse

REQUIRED_CONTENT_OPTIONS =
%w[ path message content ]

Constants included from MimeType

MimeType::MEDIA_LOOKUP

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

#current_options

Instance Method Summary collapse

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

#lookup_media, #parse

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

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.new
github.repos.contents.archive 'user-name', 'repo-name',
  archive_format: "tarball",
  ref: "master"

Parameters:



251
252
253
254
255
256
257
258
259
260
261
# File 'lib/github_api/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:

Examples:

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

Parameters:



121
122
123
124
125
126
127
128
129
# File 'lib/github_api/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:

Examples:

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

Parameters:



219
220
221
222
223
224
225
# File 'lib/github_api/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.

Examples:

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

Parameters:



73
74
75
76
77
# File 'lib/github_api/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.

Examples:

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

Parameters:



47
48
49
50
51
# File 'lib/github_api/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.

Examples:

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

Parameters:



30
31
32
33
34
# File 'lib/github_api/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:

Examples:

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

Parameters:



175
176
177
# File 'lib/github_api/client/repos/contents.rb', line 175

def update(*args)
  create(*args)
end
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy