# encoding: utf-8require'github_api/s3_uploader'moduleGithubclassRepos::Downloads<APIREQUIRED_PARAMS=%w[ name size ]VALID_DOWNLOAD_PARAM_NAMES=%w[
name
size
description
content_type
].freeze# 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| ... }#deflist(user_name,repo_name,params={})set:user=>user_name,:repo=>repo_nameassert_presence_ofuser,reponormalize!paramsresponse=get_request("/repos/#{user}/#{repo}/downloads",params)returnresponseunlessblock_given?response.each{|el|yieldel}endalias:all:list# Get a single download## = Examples# github = Github.new# github.repos.downloads.get 'user-name', 'repo-name', 'download-id'#defget(user_name,repo_name,download_id,params={})set:user=>user_name,:repo=>repo_nameassert_presence_ofuser,repo,download_idnormalize!paramsget_request("/repos/#{user}/#{repo}/downloads/#{download_id}",params)endalias:find:get# Delete download from a repository## = Examples# github = Github.new# github.repos.downloads.delete 'user-name', 'repo-name', 'download-id'#defdelete(user_name,repo_name,download_id,params={})set:user=>user_name,:repo=>repo_nameassert_presence_ofuser,repo,download_idnormalize!paramsdelete_request("/repos/#{user}/#{repo}/downloads/#{download_id}",params)end# 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# * <tt>:name</tt> - Required string - name of the file that is being created.# * <tt>:size</tt> - Required number - size of file in bytes.# * <tt>:description</tt> - Optional string# * <tt>:content_type</tt> - 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"#defcreate(user_name,repo_name,params={})set:user=>user_name,:repo=>repo_nameassert_presence_ofuser,reponormalize!paramsfilter!VALID_DOWNLOAD_PARAM_NAMES,paramsassert_required_keys(REQUIRED_PARAMS,params)post_request("/repos/#{user}/#{repo}/downloads",params)end# 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# * <tt>resource</tt> - Required resource of the create_download call.# * <tt>:filename</tt> - 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'#defupload(resource,filename)assert_presence_ofresource,filenameresponse=Github::S3Uploader.new(resource,filename).sendresponse.bodyendalias:upload_to_s3:uploadalias:upload_to_amazon:uploadend# Repos::Downloadsend# Github