Module: CloseEncounters

Defined in:
lib/close_encounters.rb,
lib/close_encounters/engine.rb,
lib/close_encounters/version.rb,
app/models/close_encounters/participant_event.rb,
app/models/close_encounters/application_record.rb,
app/models/close_encounters/participant_service.rb

Defined Under Namespace

Classes: ApplicationRecord, Engine, ParticipantEvent, ParticipantService

Constant Summary collapse

VERSION =
"0.1.3"

Class Method Summary collapse

Class Method Details

.contact(name, status:, response:) ⇒ Object

Record a contact with a third party service if the status has changed

Parameters:

  • name (String)

    the name of the service

  • status (Integer)

    the HTTP status of the contact

  • response (String)

    the response object



15
16
17
18
19
20
# File 'lib/close_encounters.rb', line 15

def contact(name, status:, response:)
  service = ParticipantService.find_by!(name:)
  unless service.events.newest.pick(:status) == status
    service.events.create!(status: status, response:)
  end
end

.ensure_service(name, connection_info: {}) ⇒ Object

Ensure that a participant service exists

Parameters:

  • name (String)

    the name of the service

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

    the connection information for the service



34
35
36
37
38
# File 'lib/close_encounters.rb', line 34

def ensure_service(name, connection_info: {})
  ParticipantService.find_or_create_by!(name: name) do |service|
    service.connection_info = connection_info unless service.connection_info.present?
  end
end

.status(name) ⇒ Integer

Get the status of the most recent contact with a third party service

Parameters:

  • name (String)

    the name of the service

Returns:

  • (Integer)

    the HTTP status of the most recent contact



26
27
28
# File 'lib/close_encounters.rb', line 26

def status(name)
  ParticipantService.find_by!(name: name).events.newest.pick(:status)
end