Sha256: 8c9ed4e951294b2ae463612d80a5641dd4c3d0eff7de2eba366db0cd71cbd86c

Contents?: true

Size: 1.27 KB

Versions: 4

Compression:

Stored size: 1.27 KB

Contents

require 'cgi'
require "converse/interaction"

module Converse
  class RESTInteraction < Interaction
    protected

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

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

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

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

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

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

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

  def interpret_conversation(response)
    format_error(response) if not response_ok?(response)
    return format_response(response.body)
  end

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

  def format_response(response_body)
    response_body
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
converse-1.0.18 lib/converse/rest/rest_interaction.rb
converse-1.0.17 lib/converse/rest/rest_interaction.rb
converse-1.0.16 lib/converse/rest/rest_interaction.rb
converse-1.0.15 lib/converse/rest/rest_interaction.rb