module Nearmiss::Client::Incidents

Methods for the Incidents API

Public Instance Methods

create_incident(options = {}) click to toggle source

Create an incident

@param options [Hash] Incident information. @option options [String] :title Name of incident @option options [String] :note Description of what happened @option options [String] :category_id ID of associated category @option options [String] :project_id ID of the project where the incident occured @option options [String] :company Which company did the incident @option options [String] :date When did the nearmiss occur @option options [String] :trade e.g. is actually the activity @option options [Boolean] :is_public Submit the nearmiss publically or private

@option options [String] :bad_weather “rainy”, “sunny”, “cloudy”, “windy” @option options [String] :injured Answers: “yes”, “no” @option options [String] :jha Answers: “yes”, “no” @option options [String] :messy Answers: “yes”, “no”

@option options [Array] :attachments

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

# File lib/nearmiss-ruby/client/incidents.rb, line 66
def create_incident(options = {})
  post 'incidents', options
end
Also aliased as: create_nearmiss
create_incident_comment(incident_id, comment, options = {}) click to toggle source

Create incident comment

@param incident_id [String] Id of the incident. @param comment [String] Comment contents. @return [Sawyer::Resource] Hash representing incident comment. @example

Nearmiss.incident_comment('208sdaz3', "Some text")
# File lib/nearmiss-ruby/client/incidents.rb, line 108
def create_incident_comment(incident_id, comment, options = {})
  options.merge!({text: comment})
  post "incidents/#{incident_id}/comments", options
end
Also aliased as: create_nearmiss_comment
create_nearmiss(options = {})
Alias for: create_incident
create_nearmiss_comment(incident_id, comment, options = {})
delete_incident_comment(incident_id, comment_id, options = {}) click to toggle source

Delete incident comment

Requires authenticated client.

@param incident_id [String] Id of the incident. @param comment_id [Integer] Id of the comment to delete. @return [Boolean] True if comment deleted, false otherwise. @example

@client.delete_incident_comment('208sdaz3', '586399')
# File lib/nearmiss-ruby/client/incidents.rb, line 139
def delete_incident_comment(incident_id, comment_id, options = {})
  boolean_from_response(:delete, "incidents/#{incident_id}/comments/#{comment_id}", options)
end
Also aliased as: delete_nearmiss_comment
delete_nearmiss_comment(incident_id, comment_id, options = {})
edit_incident(incident, options = {})
Alias for: update_incident
edit_incident_comment(incident_id, comment_id, comment, options = {})
edit_nearmiss(incident, options = {})
Alias for: update_incident
edit_nearmiss_comment(incident_id, comment_id, comment, options = {})
incident(incident, options = {}) click to toggle source

Get a single incident

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

# File lib/nearmiss-ruby/client/incidents.rb, line 29
def incident(incident, options = {})
  get "incidents/#{incident}", options
end
Also aliased as: nearmiss
incident_comment(incident_id, comment_id, options = {}) click to toggle source

Get incident comment

@param incident_id [String] Id of the incident. @param comment_id [Integer] Id of the incident comment. @return [Sawyer::Resource] Hash representing incident comment. @example

Nearmiss.incident_comment('208sdaz3', 1451398)
# File lib/nearmiss-ruby/client/incidents.rb, line 96
def incident_comment(incident_id, comment_id, options = {})
  get "incidents/#{incident_id}/comments/#{comment_id}", options
end
Also aliased as: nearmiss_comment
incident_comments(incident_id, options = {}) click to toggle source

List incident comments

@param incident_id [String] Incident Id. @return [Array<Sawyer::Resource>] Array of hashes representing comments. @example

Nearmiss.incident_comments('3528ae645')
# File lib/nearmiss-ruby/client/incidents.rb, line 84
def incident_comments(incident_id, options = {})
  paginate "incidents/#{incident_id}/comments", options
end
Also aliased as: nearmiss_comments
incidents(options = {}) click to toggle source

List nearmiss incidents

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

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

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

  paginate "incidents", options
end
list_incidents(options = {})
Alias for: incidents
list_nearmisses(options = {})
Alias for: incidents
nearmiss(incident, options = {})
Alias for: incident
nearmiss_comment(incident_id, comment_id, options = {})
Alias for: incident_comment
nearmiss_comments(incident_id, options = {})
Alias for: incident_comments
nearmisses(options = {})
Alias for: incidents
project_incidents(project, options = {}) click to toggle source

Project incidents

@param project [String] ID of project @return [Sawyer::Resource] Incident information

# File lib/nearmiss-ruby/client/incidents.rb, line 39
def project_incidents(project, options = {})

  paginate "#{Project.new(project).path}/incidents", options

end
update_incident(incident, options = {}) click to toggle source
# File lib/nearmiss-ruby/client/incidents.rb, line 71
def update_incident(incident, options = {})
  patch "incidents/#{incident}", options
end
update_incident_comment(incident_id, comment_id, comment, options = {}) click to toggle source

Update incident comment

@param incident_id [String] Id of the incident. @param comment_id [String] Id of the comment. @param comment [String] Comment contents. @return [Sawyer::Resource] Hash representing incident comment. @example

Nearmiss.incident_comment('208sdaz3', "Some text")
# File lib/nearmiss-ruby/client/incidents.rb, line 122
def update_incident_comment(incident_id, comment_id, comment, options = {})
  options.merge!({text: comment})
  patch "incidents/#{incident_id}/comments/#{comment_id}", options
end
update_nearmiss(incident, options = {})
Alias for: update_incident
update_nearmiss_comment(incident_id, comment_id, comment, options = {})

Protected Instance Methods

iso8601(date) click to toggle source
# File lib/nearmiss-ruby/client/incidents.rb, line 146
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/nearmiss-ruby/client/incidents.rb, line 158
def parse_date(date)
  date = DateTime.parse(date.to_s)
rescue ArgumentError
  raise ArgumentError, "#{date} is not a valid date"
end