module Nearmiss::Client::Attachments

Methods for the Attachments API

Public Instance Methods

attachment(attachment, options = {}) click to toggle source

Get a single attachment

@param attachment [String] ID of attachment to fetch @return [Sawyer::Resource] Incident information

# File lib/toolhound-ruby/client/attachments.rb, line 26
def attachment(attachment, options = {})
  get "attachments/#{attachment}", options
end
attachments(options = {}) click to toggle source

List nearmiss attachments

@return [Array<Sawyer::Resource>] List of attachments

# File lib/toolhound-ruby/client/attachments.rb, line 12
def attachments(options = {})
  since = options[:since] || options["since"]

  options.merge!(since: iso8601(parse_date(since))) if since

  paginate "attachments", options
end
Also aliased as: list_attachments
create_attachment(options = {}) click to toggle source

@return [Sawyer::Resource] Newly created attachment info

# File lib/toolhound-ruby/client/attachments.rb, line 54
def create_attachment(options = {})
  post 'attachments', options
end
edit_attachment(attachment, options = {})
Alias for: update_attachment
incident_attachments(incident, options = {}) click to toggle source

Project attachments

@param project [String, Hash, Incident] Incident @return [Sawyer::Resource] Incident information

# File lib/toolhound-ruby/client/attachments.rb, line 35
def incident_attachments(incident, options = {})

  paginate "#{Incident.new(incident).path}/attachments", options

end
Also aliased as: nearmiss_attachments
list_attachments(options = {})
Alias for: attachments
nearmiss_attachments(incident, options = {})
update_attachment(attachment, options = {}) click to toggle source
# File lib/toolhound-ruby/client/attachments.rb, line 59
def update_attachment(attachment, options = {})
  patch "attachments/#{attachment}", options
end
Also aliased as: edit_attachment

Protected Instance Methods

iso8601(date) click to toggle source
# File lib/toolhound-ruby/client/attachments.rb, line 67
def iso8601(date)
  if date.respond_to?(:iso8601)
    date.iso8601
  else
    date.strftime("%Y-%m-%dT%H:%M:%S%Z")
  end
end
parse_date(date) click to toggle source

Parses the given string representation of a date, throwing a meaningful exception (containing the date that failed to parse) in case of failure.

@param date [String] String representation of a date @return [DateTime]

# File lib/toolhound-ruby/client/attachments.rb, line 79
def parse_date(date)
  date = DateTime.parse(date.to_s)
rescue ArgumentError
  raise ArgumentError, "#{date} is not a valid date"
end