Module: Octokit::Client::Downloads

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

Overview

Methods for the Repo Downloads API

Instance Method Summary collapse

Instance Method Details

#create_download(repo, name, options = {}) ⇒ Sawyer::Resource

Deprecated.

As of December 11th, 2012: github.com/blog/1302-goodbye-uploads

Create a download in a repository

Examples:

Create the “Robawt” download on Github/Hubot

Octokit.create_download("github/hubot", 'Robawt')

Parameters:

  • repo (String, Repository, Hash)

    A GitHub repository

  • name (String, Repository, Hash)

    A display name for the download

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

    a customizable set of options

Options Hash (options):

  • :description (String)

    The download description

  • :content_type (String)

    The content type. Defaults to 'text/plain'

Returns:

  • (Sawyer::Resource)

    A single download from the repository

See Also:



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/octokit/client/downloads.rb', line 46

def create_download(repo, name, options={})
  options[:content_type] ||= 'text/plain'
  file = Faraday::UploadIO.new(name, options[:content_type])
  resource = create_download_resource(repo, file.original_filename, File.size(name), options)

  resource_hash = {
    'key' => resource.path,
    'acl' => resource.acl,
    'success_action_status' => 201,
    'Filename' => resource.name,
    'AWSAccessKeyId' => resource.accesskeyid,
    'Policy' => resource.policy,
    'Signature' => resource.signature,
    'Content-Type' => resource.mime_type,
    'file' => file
  }

  conn = Faraday.new(resource.rels[:s3].href) do |builder|
    builder.request :multipart
    builder.request :url_encoded
    builder.adapter :net_http
  end

  response = conn.post '/', resource_hash
  response.status == 201
end

#delete_download(repo, id, options = {}) ⇒ Boolean

Deprecated.

As of December 11th, 2012: github.com/blog/1302-goodbye-uploads

Delete a single download for a repository

Examples:

Get the “Robawt” download from Github/Hubot

Octokit.delete_download("github/hubot", 1234)

Parameters:

  • repo (String, Repository, Hash)

    A GitHub repository

  • id (Integer)

    ID of the download

Returns:

  • (Boolean)

    Status

See Also:



82
83
84
# File 'lib/octokit/client/downloads.rb', line 82

def delete_download(repo, id, options = {})
  boolean_from_response :delete, "repos/#{Repository.new(repo)}/downloads/#{id}", options
end

#download(repo, id, options = {}) ⇒ Sawyer::Resource

Deprecated.

As of December 11th, 2012: github.com/blog/1302-goodbye-uploads

Get single download for a repository

Examples:

Get the “Robawt” download from Github/Hubot

Octokit.download("github/hubot")

Parameters:

  • repo (String, Repository, Hash)

    A GitHub repository

  • id (Integer)

    ID of the download

Returns:

  • (Sawyer::Resource)

    A single download from the repository

See Also:



31
32
33
# File 'lib/octokit/client/downloads.rb', line 31

def download(repo, id, options={})
  get "repos/#{Repository.new(repo)}/downloads/#{id}", options
end

#downloads(repo, options = {}) ⇒ Array Also known as: list_downloads

Deprecated.

As of December 11th, 2012: github.com/blog/1302-goodbye-uploads

List available downloads for a repository

Examples:

List all downloads for Github/Hubot

Octokit.downloads("github/hubot")

Parameters:

  • repo (String, Repository, Hash)

    A Github Repository

Returns:

  • (Array)

    A list of available downloads

See Also:



17
18
19
# File 'lib/octokit/client/downloads.rb', line 17

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