Class: DefraRuby::Storm::API

Inherits:
Object
  • Object
show all
Defined in:
lib/defra_ruby/storm/api.rb

Instance Method Summary collapse

Constructor Details

#initialize(config = DefraRuby::Storm::Configuration.call_recording_service_configuration) ⇒ API

Returns a new instance of API.



6
7
8
# File 'lib/defra_ruby/storm/api.rb', line 6

def initialize(config = DefraRuby::Storm::Configuration.call_recording_service_configuration)
  @client = ::Savon.client(config)
end

Instance Method Details

#get_user_details(username) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/defra_ruby/storm/api.rb', line 10

def get_user_details(username)
  response = @client.call(:get_user_details, message: { "ngw:UserName": username },
                                             message_tag: :getUserDetailsRequest)
  unless response.http.code == 200 && response.body[:get_user_details_response][:code] == "0"
    handle_error "Failed to get user details for username: #{username}"
  end

  DefraRuby::Storm::GetUserDetailsResponse.new(response.body[:get_user_details_response])
end

#handle_error(error_message) ⇒ Object

Raises:



42
43
44
# File 'lib/defra_ruby/storm/api.rb', line 42

def handle_error(error_message)
  raise ApiError, error_message
end

#pause_call_recording(agent_user_id) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/defra_ruby/storm/api.rb', line 20

def pause_call_recording(agent_user_id)
  response = @client.call("RedCentrexCalls/Recording",
                          message: { "cal:UserID": agent_user_id, "cal:Record": "pause", "cal:Muted": "0" },
                          message_tag: :RecordingRequest)
  unless response.http.code == 200 && response.body[:recording_response][:result] == "0"
    handle_error "Failed to pause call recording for agent_user_id: #{agent_user_id}"
  end

  DefraRuby::Storm::RecordingResponse.new(response.body[:recording_response])
end

#resume_call_recording(agent_user_id) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/defra_ruby/storm/api.rb', line 31

def resume_call_recording(agent_user_id)
  response = @client.call("RedCentrexCalls/Recording",
                          message: { "cal:UserID": agent_user_id, "cal:Record": "resume" },
                          message_tag: :RecordingRequest)
  unless response.http.code == 200 && response.body[:recording_response][:result] == "0"
    handle_error "Failed to resume call recording for agent_user_id: #{agent_user_id}"
  end

  DefraRuby::Storm::RecordingResponse.new(response.body[:recording_response])
end