Class: Converse::RESTInteraction

Inherits:
Interaction show all
Defined in:
lib/converse/rest/rest_interaction.rb

Instance Attribute Summary

Attributes inherited from Interaction

#action, #broker, #concern, #conversation, #should_i_ask, #substance

Instance Method Summary collapse

Methods inherited from Interaction

#about, #ask_broker, #ask_broker_concerning, #by_asking, #by_saying, #concerning, #detailed_by, #discuss, #discuss_with, #discuss_with_broker_concerning, #does_not_include, #ensure_that, #handle_error!, #includes, #tell_broker, #tell_broker_concerning, #to, #using, #with

Instance Method Details

#askObject



19
20
21
# File 'lib/converse/rest/rest_interaction.rb', line 19

def ask
  @conversation.ask(path_with_params(@conversation.path, @substance))
end

#ask_broker_about(broker, action, substance) ⇒ Object



7
8
9
10
11
# File 'lib/converse/rest/rest_interaction.rb', line 7

def ask_broker_about(broker, action, substance)
  ask_broker_concerning(broker, "")
  about(action)
  detailed_by(substance)
end

#compile_params(params) ⇒ Object



27
28
29
# File 'lib/converse/rest/rest_interaction.rb', line 27

def compile_params(params)
  params.map {|k,v| CGI.escape(k.to_s)+'='+CGI.escape(v.to_s) }.join("&")
end

#format_error(response) ⇒ Object



45
46
47
48
49
50
# File 'lib/converse/rest/rest_interaction.rb', line 45

def format_error(response)
  result = []
  result << response.code
  result << response.body
  return result
end

#format_response(response_body) ⇒ Object



52
53
54
# File 'lib/converse/rest/rest_interaction.rb', line 52

def format_response(response_body)
  response_body
end

#interpret_conversation(response) ⇒ Object



41
42
43
# File 'lib/converse/rest/rest_interaction.rb', line 41

def interpret_conversation(response)
  return format_response(response.body)
end

#is_jsonObject



56
57
58
59
60
61
62
63
# File 'lib/converse/rest/rest_interaction.rb', line 56

def is_json
  begin
    JSON.parse(@validation)
    true
  rescue ::Exception
    raise ArgumentError, "#{@validation} is not in JSON format"
  end
end

#path_with_params(path, params) ⇒ Object



31
32
33
34
# File 'lib/converse/rest/rest_interaction.rb', line 31

def path_with_params(path, params)
  return path if params.nil? or params.empty?
  path + "?" + compile_params(params)
end

#sayObject



23
24
25
# File 'lib/converse/rest/rest_interaction.rb', line 23

def say
  @conversation.say(@conversation.path, compile_params(@substance))
end

#success?(response) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
# File 'lib/converse/rest/rest_interaction.rb', line 36

def success?(response)
  test_value = "#{response.code}"
  return test_value == "200"
end

#tell_broker_to(broker, action, substance) ⇒ Object



13
14
15
16
17
# File 'lib/converse/rest/rest_interaction.rb', line 13

def tell_broker_to(broker, action, substance)
  tell_broker_concerning(broker, "")
  about(action)
  detailed_by(substance)
end