Class: Github::Repos::Releases::Assets
- Defined in:
- lib/github_api/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 Github::Request
Github::Request::METHODS, Github::Request::METHODS_WITH_BODIES
Constants included from Connection
Constants included from Constants
Constants::ACCEPT, Constants::ACCEPTED_OAUTH_SCOPES, Constants::ACCEPT_CHARSET, Constants::CACHE_CONTROL, Constants::CONTENT_LENGTH, Constants::CONTENT_TYPE, Constants::DATE, Constants::ETAG, Constants::HEADER_LAST, Constants::HEADER_LINK, Constants::HEADER_NEXT, Constants::LOCATION, Constants::META_FIRST, Constants::META_LAST, Constants::META_NEXT, Constants::META_PREV, Constants::META_REL, Constants::OAUTH_SCOPES, Constants::PARAM_PAGE, Constants::PARAM_PER_PAGE, Constants::PARAM_START_PAGE, Constants::RATELIMIT_LIMIT, Constants::RATELIMIT_REMAINING, Constants::SERVER, Constants::USER_AGENT
Constants included from MimeType
Instance Attribute Summary
Attributes inherited from API
Attributes included from Authorization
Instance Method Summary collapse
-
#delete(*args) ⇒ Object
Delete a release asset.
-
#edit(*args) ⇒ Object
(also: #update)
Edit a release asset.
-
#get(*args) ⇒ Object
(also: #find)
Get a single release asset.
-
#infer_media(filepath) ⇒ Object
Infer media type of the asset.
-
#list(*args) ⇒ Object
(also: #all)
List assets for a release.
-
#upload(*args) ⇒ Object
Upload a release asset.
Methods inherited from API
#api_methods_in, #append_arguments, #arguments, inherited, #initialize, #method_missing, #process_basic_auth, #set, #setup, #with, #yield_or_eval
Methods included from Github::RateLimit
#ratelimit, #ratelimit_remaining
Methods included from Github::Request
#delete_request, #get_request, #patch_request, #post_request, #put_request, #request
Methods included from Connection
#caching?, #clear_cache, #connection, #default_middleware, #default_options, #stack
Methods included from MimeType
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'
119 120 121 122 123 |
# File 'lib/github_api/repos/releases/assets.rb', line 119 def delete(*args) params = arguments(args, required: [:owner, :repo, :id]).params delete_request("/repos/#{owner}/#{repo}/releases/assets/#{id}", params) end |
#edit(*args) ⇒ Object Also known as: update
Edit a release asset
Inputs
-
:name- Required string - the filename of the asset -
:label- Optional string - An alternate short description ofthe asset. Used in place of the filename.
Examples
github = Github.new
github.repos.releases.assets.edit 'owner', 'repo', 'id',
"name": "foo-1.0.0-osx.zip",
"label": "Mac binary"
103 104 105 106 107 108 109 110 |
# File 'lib/github_api/repos/releases/assets.rb', line 103 def edit(*args) arguments(args, required: [:owner, :repo, :id]) do sift VALID_ASSET_PARAM_NAMES end params = arguments.params patch_request("/repos/#{owner}/#{repo}/releases/assets/#{id}", 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'
36 37 38 39 40 |
# File 'lib/github_api/repos/releases/assets.rb', line 36 def get(*args) params = arguments(args, required: [:owner, :repo, :id]).params get_request("/repos/#{owner}/#{repo}/releases/assets/#{id}" , params) end |
#infer_media(filepath) ⇒ Object
Infer media type of the asset
82 83 84 85 86 87 88 |
# File 'lib/github_api/repos/releases/assets.rb', line 82 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| ... }
21 22 23 24 25 26 27 |
# File 'lib/github_api/repos/releases/assets.rb', line 21 def list(*args) params = arguments(args, required: [:owner, :repo, :id]).params response = get_request("/repos/#{owner}/#{repo}/releases/#{id}/assets", params) return response unless block_given? response.each { |el| yield el } end |
#upload(*args) ⇒ Object
Upload a release asset
Inputs
-
:name- Required string - The file name of the asset -
:content_type- Required string - The content typeof the asset. Example:
Examples
github = Github.new
github.repos.releases.assets.upload 'owner', 'repo', 'id', 'file-path'
"name": "batman.jpg",
"content_type": "application/octet-stream"
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/github_api/repos/releases/assets.rb', line 56 def upload(*args) arguments(args, required: [:owner, :repo, :id, :filepath]) do sift VALID_ASSET_PARAM_NAMES end params = arguments.params unless type = params['content_type'] type = infer_media(filepath) end file = Faraday::UploadIO.new(filepath, type) = { headers: { content_type: type }, endpoint: 'https://uploads.github.com', query: {'name' => params['name']} } params['data'] = file.read params['options'] = post_request("/repos/#{owner}/#{repo}/releases/#{id}/assets", params) ensure file.close if file end |