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!, #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, root!, #run_callbacks, #set, #yield_or_eval

Methods included from Github::ClassMethods

#configuration, #configure, #require_all

Methods included from RateLimit

#ratelimit, #ratelimit_remaining, #ratelimit_reset

Methods included from Request::Verbs

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

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:


232
233
234
235
236
237
238
239
# File 'lib/github_api/client/repos/contents.rb', line 232

def archive(*args)
  arguments(args, required: [:user, :repo])
  params         = arguments.params
  archive_format = params.delete('archive_format') || 'tarball'
  ref            = params.delete('ref') || 'master'

  get_request("/repos/#{arguments.user}/#{arguments.repo}/#{archive_format}/#{ref}", params)
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:


102
103
104
105
106
107
108
109
110
# File 'lib/github_api/client/repos/contents.rb', line 102

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:


200
201
202
203
204
205
206
# File 'lib/github_api/client/repos/contents.rb', line 200

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:


54
55
56
57
58
# File 'lib/github_api/client/repos/contents.rb', line 54

def get(*args)
  arguments(args, required: [:user, :repo, :path])

  get_request("/repos/#{arguments.user}/#{arguments.repo}/contents/#{arguments.path}", 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:


28
29
30
31
32
# File 'lib/github_api/client/repos/contents.rb', line 28

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:


156
157
158
# File 'lib/github_api/client/repos/contents.rb', line 156

def update(*args)
  create(*args)
end