Module: Octokit::Client::Downloads

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

Instance Method Summary collapse

Instance Method Details

#create_download(repo, name, options = {}) ⇒ Download

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:

  • (Download)

    A single download from the repository

See Also:



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/octokit/client/downloads.rb', line 39

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.s3_url) 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) ⇒ Object

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

See Also:



73
74
75
# File 'lib/octokit/client/downloads.rb', line 73

def delete_download(repo, id)
  delete("repos/#{Repository.new(repo)}/downloads/#{id}", {}, 3, true, true, true)
end

#download(repo, id, options = {}) ⇒ Download

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:

  • (Download)

    A single download from the repository

See Also:



25
26
27
# File 'lib/octokit/client/downloads.rb', line 25

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

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

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:



12
13
14
# File 'lib/octokit/client/downloads.rb', line 12

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