Class: Github::Client::Repos::Releases::Assets

Inherits:
API
  • Object
show all
Defined in:
lib/github_api2/client/repos/releases/assets.rb

Overview

The Release Assets API

Constant Summary collapse

VALID_ASSET_PARAM_NAMES =
%w[
  name
  label
  content_type
].freeze

Constants included from MimeType

MimeType::MEDIA_LOOKUP

Constants included from Github::Constants

Github::Constants::ACCEPT, Github::Constants::ACCEPTED_OAUTH_SCOPES, Github::Constants::ACCEPT_CHARSET, Github::Constants::CACHE_CONTROL, Github::Constants::CONTENT_LENGTH, Github::Constants::CONTENT_TYPE, Github::Constants::DATE, Github::Constants::ETAG, Github::Constants::HEADER_LAST, Github::Constants::HEADER_LINK, Github::Constants::HEADER_NEXT, Github::Constants::LOCATION, Github::Constants::META_FIRST, Github::Constants::META_LAST, Github::Constants::META_NEXT, Github::Constants::META_PREV, Github::Constants::META_REL, Github::Constants::OAUTH_SCOPES, Github::Constants::PARAM_PAGE, Github::Constants::PARAM_PER_PAGE, Github::Constants::PARAM_START_PAGE, Github::Constants::RATELIMIT_LIMIT, Github::Constants::RATELIMIT_REMAINING, Github::Constants::RATELIMIT_RESET, Github::Constants::SERVER, Github::Constants::USER_AGENT

Instance Attribute Summary

Attributes inherited from API

#current_options

Instance Method Summary collapse

Methods inherited from API

after_callbacks, after_request, #api_methods_in, #arguments, before_callbacks, before_request, clear_request_methods!, #disable_redirects, #execute, extend_with_actions, extra_methods, #extract_basic_auth, extract_class_name, #filter_callbacks, inherited, #initialize, internal_methods, method_added, #method_missing, #module_methods_in, namespace, request_methods, require_all, #respond_to?, root!, #run_callbacks, #set, #yield_or_eval

Methods included from Request::Verbs

#delete_request, #get_request, #head_request, #options_request, #patch_request, #post_request, #put_request

Methods included from RateLimit

#ratelimit, #ratelimit_remaining, #ratelimit_reset

Methods included from MimeType

#lookup_media, #parse

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

#delete(*args) ⇒ Object

Delete a release asset

Examples:

github = Github.new
github.repos.releases.assets.delete 'owner', 'repo', 'id'


130
131
132
133
134
# File 'lib/github_api2/client/repos/releases/assets.rb', line 130

def delete(*args)
  arguments(args, required: [:owner, :repo, :id])

  delete_request("/repos/#{arguments.owner}/#{arguments.repo}/releases/assets/#{arguments.id}", arguments.params)
end

#edit(*args) ⇒ Object Also known as: update

Edit a release asset

Users with push access to the repository can edit a release asset.

Examples:

github = Github.new
github.repos.releases.assets.edit 'owner', 'repo', 'id',
  name: "foo-1.0.0-osx.zip",
  label: "Mac binary"

Parameters:



114
115
116
117
118
119
120
# File 'lib/github_api2/client/repos/releases/assets.rb', line 114

def edit(*args)
  arguments(args, required: [:owner, :repo, :id]) do
    permit VALID_ASSET_PARAM_NAMES
  end

  patch_request("/repos/#{arguments.owner}/#{arguments.repo}/releases/assets/#{arguments.id}", arguments.params)
end

#get(*args) ⇒ Object Also known as: find

Get a single release asset

Examples:

github = Github.new
github.repos.releases.assets.get 'owner', 'repo', 'id'


39
40
41
42
43
# File 'lib/github_api2/client/repos/releases/assets.rb', line 39

def get(*args)
  arguments(args, required: [:owner, :repo, :id]).params

  get_request("/repos/#{arguments.owner}/#{arguments.repo}/releases/assets/#{arguments.id}" , arguments.params)
end

#infer_media(filepath) ⇒ Object

Infer media type of the asset



88
89
90
91
92
93
94
# File 'lib/github_api2/client/repos/releases/assets.rb', line 88

def infer_media(filepath)
  require 'mime/types'
  types = MIME::Types.type_for(filepath)
  types.empty? ? 'application/octet-stream' : types.first
rescue LoadError
  raise Github::Error::UnknownMedia.new(filepath)
end

#list(*args) ⇒ Object Also known as: all

List assets for a release

Examples:

github = Github.new
github.repos.releases.assets.list 'owner', 'repo', 'id'
github.repos.releases.assets.list 'owner', 'repo', 'id' { |asset| ... }


23
24
25
26
27
28
29
# File 'lib/github_api2/client/repos/releases/assets.rb', line 23

def list(*args)
  arguments(args, required: [:owner, :repo, :id]).params

  response = get_request("/repos/#{arguments.owner}/#{arguments.repo}/releases/#{arguments.id}/assets", arguments.params)
  return response unless block_given?
  response.each { |el| yield el }
end

#upload(*args) ⇒ Object

Upload a release asset

Examples:

github = Github.new
github.repos.releases.assets.upload 'owner', 'repo', 'id', 'file-path'
  name: "batman.jpg",
  content_type: "application/octet-stream"

Parameters:



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/github_api2/client/repos/releases/assets.rb', line 62

def upload(*args)
  arguments(args, required: [:owner, :repo, :id, :filepath]) do
    permit VALID_ASSET_PARAM_NAMES
  end
  params = arguments.params

  unless type = params['content_type']
    type = infer_media(arguments.filepath)
  end

  file = Faraday::UploadIO.new(arguments.filepath, type)
  options = {
    headers: { content_type: type },
    endpoint: upload_endpoint,
    query: {'name' => params['name']}
  }
  params['data']    = file.read
  params['options'] = options

  post_request("/repos/#{arguments.owner}/#{arguments.repo}/releases/#{arguments.id}/assets", params)
ensure
  file.close if file
end