Skip to content

Commit c09314c

Browse files
committed
Refine attachment documentation.
1 parent 58606de commit c09314c

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

lib/jira/resource/attachment.rb

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class AttachmentFactory < JIRA::BaseFactory # :nodoc:
2929
# === Retrieving file contents of attachment
3030
#
3131
# content = URI.open(attachment.content).read
32+
# content = attachment.download_contents
33+
# content = attachment.download_file { |file| file.read }
3234
#
3335
# === Adding an attachment to an issue
3436
#
@@ -41,10 +43,9 @@ class AttachmentFactory < JIRA::BaseFactory # :nodoc:
4143
# attachment.save!( { file: path, mimeType: content_type } )
4244
# end
4345
#
44-
# === Deleting a resource
46+
# === Deleting an attachment
4547
#
46-
# resource = client.Resource.find(id)
47-
# resource.delete
48+
# attachment.delete
4849
#
4950
# @!method save(attrs, path = url)
5051
# Uploads a file as an attachment to its issue.
@@ -69,7 +70,7 @@ class AttachmentFactory < JIRA::BaseFactory # :nodoc:
6970
# @!attribute [r] mimeType
7071
# @return [String] MIME of the content type
7172
# @!attribute [r] content
72-
# @return [String] URL to download the contents of the attachment
73+
# @return [String] URL (not the contents) to download the contents of the attachment
7374
# @!attribute [r] thumbnail
7475
# @return [String] URL to download the thumbnail of the attachment
7576
#
@@ -82,13 +83,11 @@ def self.endpoint_name
8283
'attachments'
8384
end
8485

85-
# Gets meta data about attachments on the server.
86+
# Gets metadata about attachments on the server.
8687
# @example Return metadata
87-
# {
88-
# "enabled" => true,
89-
# "uploadLimit" => 1000000
90-
# }
91-
# @return [Hash] The meta data for attachments. (See example.)
88+
# Attachment.meta(client)
89+
# => { "enabled" => true, "uploadLimit" => 1000000 }
90+
# @return [Hash] The metadata for attachments. (See example.)
9291
def self.meta(client)
9392
response = client.get("#{client.options[:rest_base_path]}/attachment/meta")
9493
parse_json(response.body)
@@ -122,9 +121,11 @@ def download_file(headers = {}, &block)
122121
# Downloads the file contents as a string object.
123122
#
124123
# Note that this reads the contents into a ruby string in memory.
125-
# A file might be very large so it is recommend to avoid this unless you are certain about doing so.
124+
# A file might be very large so it is recommended to avoid this unless you are certain about doing so.
126125
# Use the download_file method instead and avoid calling the read method without a limit.
127126
#
127+
# @example Save file contents to a string.
128+
# content = download_contents
128129
# @param [Hash] headers Any additional headers to call Jira.
129130
# @return [String,NilClass] The file contents.
130131
def download_contents(headers = {})
@@ -135,6 +136,10 @@ def download_contents(headers = {})
135136
#
136137
# Filename used will be the basename of the given file.
137138
#
139+
# @example Save a file as an attachment
140+
# issue = JIRA::Resource::Issue.find(client, 'SUP-3000', { fields: 'attachment' } )
141+
# attachment = issue.attachments.build
142+
# attachment.save!( { file: path, mimeType: 'text/plain' } )
138143
# @param [Hash] attrs the options to create a message with.
139144
# @option attrs [IO,String] :file The file to upload, either a file object or a file path to find the file.
140145
# @option attrs [String] :mimeType The MIME type of the file.

0 commit comments

Comments
 (0)