Class: ChallengeServerClient
- Inherits:
-
Object
- Object
- ChallengeServerClient
show all
- Defined in:
- lib/tdl/runner/challenge_server_client.rb
Defined Under Namespace
Classes: ClientErrorException, OtherCommunicationException, ServerErrorException
Instance Method Summary
collapse
Constructor Details
#initialize(hostname, port, journey_id, use_colours) ⇒ ChallengeServerClient
Returns a new instance of ChallengeServerClient.
3
4
5
6
7
|
# File 'lib/tdl/runner/challenge_server_client.rb', line 3
def initialize(hostname, port, journey_id, use_colours)
@base_url = "http://#{hostname}:#{port}"
@journey_id = journey_id
use_colours ? @accept_header = 'text/coloured' : @accept_header = 'text/not-coloured'
end
|
Instance Method Details
#get_available_actions ⇒ Object
13
14
15
|
# File 'lib/tdl/runner/challenge_server_client.rb', line 13
def get_available_actions
get('availableActions')
end
|
#get_journey_progress ⇒ Object
9
10
11
|
# File 'lib/tdl/runner/challenge_server_client.rb', line 9
def get_journey_progress
get('journeyProgress')
end
|
#get_round_description ⇒ Object
17
18
19
|
# File 'lib/tdl/runner/challenge_server_client.rb', line 17
def get_round_description
get('roundDescription')
end
|
#send_action(action) ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/tdl/runner/challenge_server_client.rb', line 21
def send_action(action)
encoded_path = @journey_id.encode('utf-8')
url = "#{@base_url}/action/#{action}/#{encoded_path}"
response = Unirest.post(url, headers: {'Accept'=> @accept_header, 'Accept-Charset'=> 'UTF-8'})
ensure_status_ok(response)
response.body
end
|