Parent

Class/Module Index [+]

Quicksearch

Github::Repos::Contents

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

Public Instance Methods

archive(*args) click to toggle source

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.

Note: For private repositories, these links are temporary and expire quickly.

Parameters

  • :archive_format - Required string - either tarball or zipball

  • :ref - Optional string - valid Git reference, defaults to master

Examples

github = Github.new
github.repos.contents.archive 'user-name', 'repo-name',
  "archive_format" =>  "tarball",
  "ref" => "master"
# File lib/github_api/repos/contents.rb, line 177
def archive(*args)
  arguments(args, :required => [:user, :repo])
  params         = arguments.params
  archive_format = params.delete('archive_format') || 'zipball'
  ref            = params.delete('ref') || 'master'

  get_request("/repos/#{user}/#{repo}/#{archive_format}/#{ref}", params)
end
create(*args) click to toggle source

Create a file

This method creates a new file in a repository

Parameters

  • :path - Requried string - The content path

  • :message - Requried string - The commit message

  • :content - Requried string - The new file content,

    which will be Base64 encoded
  • :branch - Optional string - The branch name. If not provided,

    uses the repository’s default branch (usually master)

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.

  • author.name - string - The name of the author of the commit

  • author.email - string - The email of the author of the commit

  • committer.name - string - The name of the committer of the commit

  • committer.email - string - The email of the committer of the commit

Examples

github = Github.new
github.repos.contents.create 'user-name', 'repo-name', 'path',
  path: 'hello.rb',
  content: "puts 'hello ruby'",
  message: "my commit message"
# File lib/github_api/repos/contents.rb, line 83
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/#{user}/#{repo}/contents/#{path}", params)
end
delete(*args) click to toggle source

Delete a file

This method deletes a file in a repository

Parameters

  • :path - Requried string - The content path

  • :message - Requried string - The commit message

  • :sha - Requried string - The blob SHA of the file being removed.

  • :branch - Optional string - The branch name. If not provided,

    uses the repository’s default branch (usually master)

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.

  • author.name - string - The name of the author of the commit

  • author.email - string - The email of the author of the commit

  • committer.name - string - The name of the committer of the commit

  • committer.email - string - The email of the committer of the commit

Examples

github = Github.new
github.repos.contents.delete 'user-name', 'repo-name', 'path',
  path: 'hello.rb',
  message: "delete hello.rb file",
  sha: "329688480d39049927147c162b9d2deaf885005f"
# File lib/github_api/repos/contents.rb, line 150
def delete(*args)
  arguments(args, :required => [:user, :repo, :path]) do
    assert_required ] path message sha ]
  end

  delete_request("/repos/#{user}/#{repo}/contents/#{path}", arguments.params)
end
find(*args) click to toggle source
Alias for: get
get(*args) click to toggle source

Get contents

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

Parameters

  • :ref - Optional string - valid Git reference, defaults to master

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'
# File lib/github_api/repos/contents.rb, line 42
def get(*args)
  arguments(args, :required => [:user, :repo, :path])
  params = arguments.params

  get_request("/repos/#{user}/#{repo}/contents/#{path}", params)
end
Also aliased as: find
readme(*args) click to toggle source

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::Repos;:Contents.new user: 'user-name', 'repo-name'
content.readme
# File lib/github_api/repos/contents.rb, line 21
def readme(*args)
  arguments(args, :required => [:user, :repo])
  params = arguments.params

  get_request("/repos/#{user}/#{repo}/readme", params)
end
update(*args) click to toggle source

Update a file

This method updates a file in a repository

Parameters

  • :path - Requried string - The content path

  • :message - Requried string - The commit message

  • :content - Requried string - The new file content,

    which will be Base64 encoded
  • :sha - Requried string - The blob SHA of the file being replaced.

  • :branch - Optional string - The branch name. If not provided,

    uses the repository’s default branch (usually master)

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"
# File lib/github_api/repos/contents.rb, line 114
def update(*args)
  create(*args)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.