Module: Octokit::Client::Contents

Included in:
Octokit::Client
Defined in:
lib/octokit/client/contents.rb

Instance Method Summary collapse

Instance Method Details

This method will provide a URL to download a tarball or zipball archive for a repository.

Examples:

Get archive link for pengwynn/octokit

Octokit.archive_link("pengwynn/octokit")

Parameters:

  • repo (String, Repository, Hash)

    A GitHub repository.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • format (String)

    Either tarball (default) or zipball.

  • :ref (String)

    Optional valid Git reference, defaults to master.

Returns:

  • (String)

    Location of the download

See Also:



42
43
44
45
46
47
48
# File 'lib/octokit/client/contents.rb', line 42

def archive_link(repo, options={})
  repo_ref = options.delete :ref
  format = (options.delete :format) || 'tarball'
  url = "repos/#{Repository.new repo}/#{format}/#{repo_ref}"
  headers = get(url, options, 3, false, true).headers
  return headers['location']
end

#contents(repo, options = {}) ⇒ Hash

Receive a listing of a repository folder or the contents of a file

Examples:

List the contents of lib/octokit.rb

Octokit.contents("pengwynn/octokit", :path => 'lib/octokit.rb')

Parameters:

  • repo (String, Repository, Hash)

    A GitHub repository

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :path (String)

    A folder or file path

  • :ref (String)

    name of the Commit/Branch/Tag. Defaults to “master”.

Returns:

  • (Hash)

    The contents of a file or list of the files in the folder

See Also:



27
28
29
30
31
# File 'lib/octokit/client/contents.rb', line 27

def contents(repo, options={})
  repo_path = options.delete :path
  url = "repos/#{Repository.new repo}/contents/#{repo_path}"
  get(url, options, 3)
end

#readme(repo, options = {}) ⇒ Hash

Receive the default Readme for a repository

Examples:

Get the readme file for a repo

Octokit.readme("pengwynn/octokit")

Parameters:

  • repo (String, Repository, Hash)

    A GitHub repository

  • ref (String)

    The String name of the Commit/Branch/Tag. Defaults to “master”.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :ref (String)

    name of the Commit/Branch/Tag. Defaults to “master”.

Returns:

  • (Hash)

    The detail of the readme

See Also:



14
15
16
# File 'lib/octokit/client/contents.rb', line 14

def readme(repo, options={})
  get("repos/#{Repository.new repo}/readme", options, 3)
end