Class: Github::Repos::Downloads
- Defined in:
- lib/github_api/repos/downloads.rb
Constant Summary collapse
- REQUIRED_PARAMS =
%w[ name size ].freeze
- VALID_DOWNLOAD_PARAM_NAMES =
%w[ name size description content_type ].freeze
Constants included from Github::Request
Github::Request::METHODS, Github::Request::METHODS_WITH_BODIES
Constants included from Connection
Constants included from Constants
Constants::ACCEPT, Constants::ACCEPTED_OAUTH_SCOPES, Constants::ACCEPT_CHARSET, Constants::CACHE_CONTROL, Constants::CONTENT_LENGTH, Constants::CONTENT_TYPE, Constants::DATE, Constants::ETAG, Constants::HEADER_LAST, Constants::HEADER_LINK, Constants::HEADER_NEXT, Constants::LOCATION, Constants::META_FIRST, Constants::META_LAST, Constants::META_NEXT, Constants::META_PREV, Constants::META_REL, Constants::OAUTH_SCOPES, Constants::PARAM_PAGE, Constants::PARAM_PER_PAGE, Constants::PARAM_START_PAGE, Constants::RATELIMIT_LIMIT, Constants::RATELIMIT_REMAINING, Constants::SERVER, Constants::USER_AGENT
Constants included from MimeType
Instance Attribute Summary
Attributes inherited from API
Attributes included from Authorization
Instance Method Summary collapse
-
#create(*args) ⇒ Object
Creating a new download is a two step process.
-
#delete(*args) ⇒ Object
(also: #remove)
Delete download from a repository.
-
#get(*args) ⇒ Object
(also: #find)
Get a single download.
-
#list(*args) ⇒ Object
(also: #all)
List downloads for a repository.
-
#upload(*args) ⇒ Object
(also: #upload_to_s3, #upload_to_amazon)
Upload a file to Amazon, using the reponse instance from Github::Repos::Downloads#create_download.
Methods inherited from API
#api_methods_in, #append_arguments, #arguments, inherited, #initialize, #method_missing, #process_basic_auth, #set, #setup, #with, #yield_or_eval
Methods included from Github::RateLimit
#ratelimit, #ratelimit_remaining
Methods included from Github::Request
#delete_request, #get_request, #patch_request, #post_request, #put_request, #request
Methods included from Connection
#caching?, #clear_cache, #connection, #default_middleware, #default_options, #stack
Methods included from MimeType
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
#create(*args) ⇒ Object
Creating a new download is a two step process. You must first create a new download resource using this method. Response from this method is to be used in #upload method.
Inputs
-
:name
- Required string - name of the file that is being created. -
:size
- Required number - size of file in bytes. -
:description
- Optional string -
:content_type
- Optional string
Examples
github = Github.new
github.repos.downloads.create 'user-name', 'repo-name',
"name" => "new_file.jpg",
"size" => 114034,
"description" => "Latest release",
"content_type" => "text/plain"
79 80 81 82 83 84 85 86 87 |
# File 'lib/github_api/repos/downloads.rb', line 79 def create(*args) arguments(args, :required => [:user, :repo]) do sift VALID_DOWNLOAD_PARAM_NAMES assert_required REQUIRED_PARAMS end params = arguments.params post_request("/repos/#{user}/#{repo}/downloads", params) end |
#delete(*args) ⇒ Object Also known as: remove
53 54 55 56 57 58 |
# File 'lib/github_api/repos/downloads.rb', line 53 def delete(*args) arguments(args, :required => [:user, :repo, :download_id]) params = arguments.params delete_request("/repos/#{user}/#{repo}/downloads/#{download_id}", params) end |
#get(*args) ⇒ Object Also known as: find
39 40 41 42 43 44 |
# File 'lib/github_api/repos/downloads.rb', line 39 def get(*args) arguments(args, :required => [:user, :repo, :download_id]) params = arguments.params get_request("/repos/#{user}/#{repo}/downloads/#{download_id}", params) end |
#list(*args) ⇒ Object Also known as: all
List downloads for a repository
Examples
github = Github.new
github.repos.downloads.list 'user-name', 'repo-name'
github.repos.downloads.list 'user-name', 'repo-name' { |downl| ... }
24 25 26 27 28 29 30 |
# File 'lib/github_api/repos/downloads.rb', line 24 def list(*args) arguments(args, :required => [:user, :repo]) response = get_request("/repos/#{user}/#{repo}/downloads", arguments.params) return response unless block_given? response.each { |el| yield el } end |
#upload(*args) ⇒ Object Also known as: upload_to_s3, upload_to_amazon
Upload a file to Amazon, using the reponse instance from Github::Repos::Downloads#create_download. This can be done by passing the response object as an argument to upload method.
Parameters
-
resource
- Required resource of the create_download call. -
:filename
- Required filename, a path to a file location.
Examples
resource = github.repos.downloads.create 'user-name', 'repo-name'
github.repos.downloads.upload resource, '/users/octokit/image.jpg'
102 103 104 105 106 107 |
# File 'lib/github_api/repos/downloads.rb', line 102 def upload(*args) arguments(args, :required => [:resource, :filename]) response = Github::S3Uploader.new(resource, filename).send response.body end |