module Github::Repos::Downloads

def create_download(user_name=nil, repo_name=nil, params={})


"content_type" => "text/plain"
"description" => "Latest release",
"size" => 114034,
"name" => "new_file.jpg",
@github.repos.create_download 'user-name', 'repo-name',
@github = Github.new
= Examples

* :content_type - Optional string
* :description - Optional string
* :size - Required number - size of file in bytes.
* :name - Required string - name of the file that is being created.
= Inputs

Response from this method is to be used in #upload method.
You must first create a new download resource using this method.
Creating a new download is a two step process.
def create_download(user_name=nil, repo_name=nil, params={})
  _update_user_repo_params(user_name, repo_name)
  _validate_user_repo_params(user, repo) unless user? && repo?
  _normalize_params_keys(params)
  _filter_params_keys(VALID_DOWNLOAD_PARAM_NAMES, params)
  raise ArgumentError, "Required parameters are: #{REQUIRED_PARAMS.join(', ')}" unless _validate_inputs(REQUIRED_PARAMS, params)
  post("/repos/#{user}/#{repo}/downloads", params)
end

def delete_download(user_name, repo_name, download_id, params={})


@github.repos.delete_download 'user-name', 'repo-name', 'download-id'
@github = Github.new
= Examples

Delete download from a repository
def delete_download(user_name, repo_name, download_id, params={})
  _update_user_repo_params(user_name, repo_name)
  _validate_user_repo_params(user, repo) unless user? && repo?
  _validate_presence_of download_id
  _normalize_params_keys(params)
  delete("/repos/#{user}/#{repo}/downloads/#{download_id}")
end

def download(user_name, repo_name, download_id, params={})


@github.repos.download 'user-name', 'repo-name'
@github = Github.new
= Examples

Get a single download
def download(user_name, repo_name, download_id, params={})
  _update_user_repo_params(user_name, repo_name)
  _validate_user_repo_params(user, repo) unless user? && repo?
  _validate_presence_of download_id
  _normalize_params_keys(params)
  get("/repos/#{user}/#{repo}/downloads/#{download_id}")
end

def downloads(user_name=nil, repo_name=nil, params={})


@github.repos.downloads 'user-name', 'repo-name' { |downl| ... }
@github.repos.downloads 'user-name', 'repo-name'
@github = Github.new
= Examples

List downloads for a repository
def downloads(user_name=nil, repo_name=nil, params={})
  _update_user_repo_params(user_name, repo_name)
  _validate_user_repo_params(user, repo) unless user? && repo?
  _normalize_params_keys(params)
  response = get("/repos/#{user}/#{repo}/downloads")
  return response unless block_given?
  response.each { |el| yield el }
end

def prepend_at_for(file)

def prepend_at_for(file)
  /^@.*/ =~ file ? '@' + file : file
end

def upload(resource, filename)


* :size - Required number - size of file in bytes.
* resource - Required Hashie::Mash -resource of the create_download call
= Parameters

the response object as an argument to upload method.
Github::Repos::Downloads#create_download. This can be done by passing
Upload a file to Amazon, using the reponse instance from
def upload(resource, filename)
  _validate_presence_of resource, filename
  raise ArgumentError, 'Need to provied resource of Github::Repose::Downloads#create_download call' unless resource.is_a? Hashie::Mash
  REQUIRED_S3_PARAMS.each do |key|
    raise ArgumentError, "Expected following key: #{key}" unless resource.respond_to?(key)
  end
  # TODO use ordered hash if Ruby < 1.9
  hash = ruby_18 {
    require 'active_support'
    ActiveSupport::OrderedHash.new } || ruby_19 { Hash.new }
  mapped_params = {
    'key'                   => resource.path,
    'acl'                   => resource.acl,
    'success_action_status' => SUCCESS_STATUS,
    'Filename'              => resource.name,
    'AWSAccessKeyId'        => resource.accesskeyid,
    'Policy'                => resource.policy,
    'Signature'             => resource.signature,
    'Content-Type'          => resource.mime_type,
    'file'                  => prepend_at_for(filename.to_s)
  }
  post('', mapped_params, { :url => resource.s3_url })
end