-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/adding file attachments (#108)
* File attachments, delete and reload comments with story, create comments with epics * Specs, rest-calls refactor, README and bugfixes * CR changes - remove dead code, fix indentation, mark todo
- Loading branch information
1 parent
a9eb54d
commit bd4639a
Showing
20 changed files
with
263 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module TrackerApi | ||
module Endpoints | ||
class Attachment | ||
attr_accessor :client | ||
|
||
def initialize(client) | ||
@client = client | ||
end | ||
|
||
def create(comment, file) | ||
data = client.post("/projects/#{comment.project_id}/uploads", body: FileUtility.get_file_upload(file)).body | ||
Resources::FileAttachment.new({ comment: comment }.merge(data)) | ||
end | ||
|
||
# TODO : Discuss before implementing this as it orphans the file. | ||
# It deletes source, but the file name appears in the comments | ||
# def delete(comment, file_attachment_id) | ||
# client.delete("/projects/#{comment.project_id}/stories/#{comment.story_id}/comments/#{comment.id}/file_attachments/#{file_attachment_id}").body | ||
# end | ||
|
||
def get(comment) | ||
data = client.get("/projects/#{comment.project_id}/stories/#{comment.story_id}/comments/#{comment.id}?fields=file_attachments").body["file_attachments"] | ||
raise Errors::UnexpectedData, 'Array of file attachments expected' unless data.is_a? Array | ||
|
||
data.map do |file_attachment| | ||
Resources::FileAttachment.new({ comment: comment }.merge(file_attachment)) | ||
end | ||
end | ||
|
||
# TODO : Implement this properly. | ||
# This results in either content of the file or an S3 link. | ||
# the S3 link is also present in big_url attribute. | ||
# def download(download_path) | ||
# client.get(download_path, url: '').body | ||
# end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module TrackerApi | ||
module Endpoints | ||
class Attachments | ||
attr_accessor :client | ||
|
||
def initialize(client) | ||
@client = client | ||
end | ||
|
||
|
||
def create(comment, files) | ||
return [] if files.to_a.empty? | ||
#Check files before upload to make it all or none. | ||
FileUtility.check_files_exist(files) | ||
attachment = Endpoints::Attachment.new(client) | ||
files.map do | file | | ||
attachment.create(comment, file) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module TrackerApi | ||
class FileUtility | ||
class << self | ||
def get_file_upload(file) | ||
mime_type = MimeMagic.by_path(file) | ||
{ :file => Faraday::UploadIO.new(file, mime_type) } | ||
end | ||
|
||
def check_files_exist(files) | ||
files.each do | file | | ||
raise ArgumentError, 'Attachment file not found.' unless Pathname.new(file).exist? | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module TrackerApi | ||
module Resources | ||
class FileAttachment | ||
include Shared::Base | ||
|
||
attribute :comment, Comment | ||
|
||
attribute :id, Integer | ||
attribute :big_url, String | ||
attribute :content_type, String | ||
attribute :created_at, DateTime | ||
attribute :download_url, String | ||
attribute :filename, String | ||
attribute :height, Integer | ||
attribute :kind, String | ||
attribute :size, Integer | ||
attribute :thumbnail_url, String | ||
attribute :thumbnailable, Boolean | ||
attribute :uploaded, Boolean | ||
attribute :uploader_id, Integer | ||
attribute :width, Integer | ||
|
||
def delete | ||
comment.delete_attachments([id]) | ||
end | ||
|
||
# TODO : Implement download properly. | ||
# Look at Attchment#download for more details | ||
# The big_url actually has the AWS S3 link for the file | ||
# def download | ||
# file_data = Endpoints::Attachment.new(comment.client).download(download_url) | ||
# File.open(filename, 'wb') { |fp| fp.write(file_data) } | ||
# end | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.