Module: Nearmiss::Client::Incidents

Defined in:
lib/toolhound-ruby/client/incidents.rb

Overview

Methods for the Incidents API

Instance Method Summary collapse

Instance Method Details

#create_incident(options = {}) ⇒ Sawyer::Resource Also known as: create_nearmiss

Create an incident

Parameters:

  • options (Hash) (defaults to: {})

    Incident information.

Options Hash (options):

  • :title (String)

    Name of incident

  • :note (String)

    Description of what happened

  • :category_id (String)

    ID of associated category

  • :project_id (String)

    ID of the project where the incident occured

  • :company (String)

    Which company did the incident

  • :date (String)

    When did the nearmiss occur

  • :trade (String)

    e.g. is actually the activity

  • :is_public (Boolean)

    Submit the nearmiss publically or private

  • :bad_weather (String)

    “rainy”, “sunny”, “cloudy”, “windy”

  • :injured (String)

    Answers: “yes”, “no”

  • :jha (String)

    Answers: “yes”, “no”

  • :messy (String)

    Answers: “yes”, “no”

  • :attachments (Array)

Returns:

  • (Sawyer::Resource)

    Newly created incident info



66
67
68
# File 'lib/toolhound-ruby/client/incidents.rb', line 66

def create_incident(options = {})
  post 'incidents', options
end

#create_incident_comment(incident_id, comment, options = {}) ⇒ Sawyer::Resource Also known as: create_nearmiss_comment

Create incident comment

Examples:

Nearmiss.incident_comment('208sdaz3', "Some text")

Parameters:

  • incident_id (String)

    Id of the incident.

  • comment (String)

    Comment contents.

Returns:

  • (Sawyer::Resource)

    Hash representing incident comment.



108
109
110
111
# File 'lib/toolhound-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

#delete_incident_comment(incident_id, comment_id, options = {}) ⇒ Boolean Also known as: delete_nearmiss_comment

Delete incident comment

Requires authenticated client.

Examples:

@client.delete_incident_comment('208sdaz3', '586399')

Parameters:

  • incident_id (String)

    Id of the incident.

  • comment_id (Integer)

    Id of the comment to delete.

Returns:

  • (Boolean)

    True if comment deleted, false otherwise.



139
140
141
# File 'lib/toolhound-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

#incident(incident, options = {}) ⇒ Sawyer::Resource Also known as: nearmiss

Get a single incident

Parameters:

  • incident (String)

    ID of incident to fetch

Returns:

  • (Sawyer::Resource)

    Incident information



29
30
31
# File 'lib/toolhound-ruby/client/incidents.rb', line 29

def incident(incident, options = {})
  get "incidents/#{incident}", options
end

#incident_comment(incident_id, comment_id, options = {}) ⇒ Sawyer::Resource Also known as: nearmiss_comment

Get incident comment

Examples:

Nearmiss.incident_comment('208sdaz3', 1451398)

Parameters:

  • incident_id (String)

    Id of the incident.

  • comment_id (Integer)

    Id of the incident comment.

Returns:

  • (Sawyer::Resource)

    Hash representing incident comment.



96
97
98
# File 'lib/toolhound-ruby/client/incidents.rb', line 96

def incident_comment(incident_id, comment_id, options = {})
  get "incidents/#{incident_id}/comments/#{comment_id}", options
end

#incident_comments(incident_id, options = {}) ⇒ Array<Sawyer::Resource> Also known as: nearmiss_comments

List incident comments

Examples:

Nearmiss.incident_comments('3528ae645')

Parameters:

  • incident_id (String)

    Incident Id.

Returns:

  • (Array<Sawyer::Resource>)

    Array of hashes representing comments.



84
85
86
# File 'lib/toolhound-ruby/client/incidents.rb', line 84

def incident_comments(incident_id, options = {})
  paginate "incidents/#{incident_id}/comments", options
end

#incidents(options = {}) ⇒ Array<Sawyer::Resource> Also known as: list_incidents, list_nearmisses, nearmisses

List nearmiss incidents

Returns:

  • (Array<Sawyer::Resource>)

    List of incidents



12
13
14
15
16
17
18
# File 'lib/toolhound-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

#project_incidents(project, options = {}) ⇒ Sawyer::Resource

Project incidents

Parameters:

  • project (String)

    ID of project

Returns:

  • (Sawyer::Resource)

    Incident information



39
40
41
42
43
# File 'lib/toolhound-ruby/client/incidents.rb', line 39

def project_incidents(project, options = {})

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

end

#update_incident(incident, options = {}) ⇒ Object Also known as: edit_incident, update_nearmiss, edit_nearmiss



71
72
73
# File 'lib/toolhound-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 = {}) ⇒ Sawyer::Resource Also known as: edit_incident_comment, update_nearmiss_comment, edit_nearmiss_comment

Update incident comment

Examples:

Nearmiss.incident_comment('208sdaz3', "Some text")

Parameters:

  • incident_id (String)

    Id of the incident.

  • comment_id (String)

    Id of the comment.

  • comment (String)

    Comment contents.

Returns:

  • (Sawyer::Resource)

    Hash representing incident comment.



122
123
124
125
# File 'lib/toolhound-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