@@ -29,6 +29,8 @@ class AttachmentFactory < JIRA::BaseFactory # :nodoc:
29
29
# === Retrieving file contents of attachment
30
30
#
31
31
# content = URI.open(attachment.content).read
32
+ # content = attachment.download_contents
33
+ # content = attachment.download_file { |file| file.read }
32
34
#
33
35
# === Adding an attachment to an issue
34
36
#
@@ -41,10 +43,9 @@ class AttachmentFactory < JIRA::BaseFactory # :nodoc:
41
43
# attachment.save!( { file: path, mimeType: content_type } )
42
44
# end
43
45
#
44
- # === Deleting a resource
46
+ # === Deleting an attachment
45
47
#
46
- # resource = client.Resource.find(id)
47
- # resource.delete
48
+ # attachment.delete
48
49
#
49
50
# @!method save(attrs, path = url)
50
51
# Uploads a file as an attachment to its issue.
@@ -69,7 +70,7 @@ class AttachmentFactory < JIRA::BaseFactory # :nodoc:
69
70
# @!attribute [r] mimeType
70
71
# @return [String] MIME of the content type
71
72
# @!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
73
74
# @!attribute [r] thumbnail
74
75
# @return [String] URL to download the thumbnail of the attachment
75
76
#
@@ -82,13 +83,11 @@ def self.endpoint_name
82
83
'attachments'
83
84
end
84
85
85
- # Gets meta data about attachments on the server.
86
+ # Gets metadata about attachments on the server.
86
87
# @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.)
92
91
def self . meta ( client )
93
92
response = client . get ( "#{ client . options [ :rest_base_path ] } /attachment/meta" )
94
93
parse_json ( response . body )
@@ -122,9 +121,11 @@ def download_file(headers = {}, &block)
122
121
# Downloads the file contents as a string object.
123
122
#
124
123
# 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.
126
125
# Use the download_file method instead and avoid calling the read method without a limit.
127
126
#
127
+ # @example Save file contents to a string.
128
+ # content = download_contents
128
129
# @param [Hash] headers Any additional headers to call Jira.
129
130
# @return [String,NilClass] The file contents.
130
131
def download_contents ( headers = { } )
@@ -135,6 +136,10 @@ def download_contents(headers = {})
135
136
#
136
137
# Filename used will be the basename of the given file.
137
138
#
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' } )
138
143
# @param [Hash] attrs the options to create a message with.
139
144
# @option attrs [IO,String] :file The file to upload, either a file object or a file path to find the file.
140
145
# @option attrs [String] :mimeType The MIME type of the file.
0 commit comments