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



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

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

#ask_broker_about(broker, action, substance) ⇒ Object



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

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

#compile_params(params) ⇒ Object



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

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

#format_error(response) ⇒ Object



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

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

#format_response(response_body) ⇒ Object



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

def format_response(response_body)
  response_body
end

#interpret_conversation(response) ⇒ Object



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

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

#path_with_params(path, params) ⇒ Object



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

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

#sayObject



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

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

#success?(response) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#tell_broker_to(broker, action, substance) ⇒ Object



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

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