converse 1.0.12 → 1.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/converse/rest/rest_broker.rb +34 -0
- data/lib/converse/rest/rest_interaction.rb +58 -0
- data/lib/converse/version.rb +1 -1
- metadata +5 -3
| @@ -0,0 +1,34 @@ | |
| 1 | 
            +
            require "converse/broker"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Converse
         | 
| 4 | 
            +
              class RESTBroker < Broker
         | 
| 5 | 
            +
                attr_accessor :peer_host_and_port
         | 
| 6 | 
            +
                attr_accessor :username
         | 
| 7 | 
            +
                attr_accessor :password
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                def broker_conversation(topic)
         | 
| 10 | 
            +
                  conversation = HTMLConversation.new(topic)
         | 
| 11 | 
            +
                  conversation.username = @username if @username.nil? == false
         | 
| 12 | 
            +
                  conversation.password = @password if @password.nil? == false
         | 
| 13 | 
            +
                  conversation
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                def open_topic(concern, action)
         | 
| 17 | 
            +
                  if (concern.nil? == true or concern == "")
         | 
| 18 | 
            +
                    "http://#{@peer_host_and_port}/#{action}"
         | 
| 19 | 
            +
                  else
         | 
| 20 | 
            +
                    "http://#{@peer_host_and_port}/#{concern}/#{action}"
         | 
| 21 | 
            +
                  end
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                def authenticated_by(username)
         | 
| 25 | 
            +
                  @username = username
         | 
| 26 | 
            +
                  self
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                def with_password(password)
         | 
| 30 | 
            +
                  @password = password
         | 
| 31 | 
            +
                  self
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
              end
         | 
| 34 | 
            +
            end
         | 
| @@ -0,0 +1,58 @@ | |
| 1 | 
            +
            require 'cgi'
         | 
| 2 | 
            +
            require "converse/interaction"
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            module Converse
         | 
| 5 | 
            +
              class RESTInteraction < Interaction
         | 
| 6 | 
            +
                protected
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                def ask_broker_about(broker, action, substance)
         | 
| 9 | 
            +
                  ask_broker_concerning(broker, "")
         | 
| 10 | 
            +
                  about(action)
         | 
| 11 | 
            +
                  detailed_by(substance)
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                def tell_broker_to(broker, action, substance)
         | 
| 15 | 
            +
                  tell_broker_concerning(broker, "")
         | 
| 16 | 
            +
                  about(action)
         | 
| 17 | 
            +
                  detailed_by(substance)
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                def ask
         | 
| 21 | 
            +
                  @conversation.ask(path_with_params(@conversation.path, @substance))
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                def say
         | 
| 25 | 
            +
                  @conversation.say(@conversation.path, compile_params(@substance))
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                def compile_params(params)
         | 
| 29 | 
            +
                  params.map {|k,v| CGI.escape(k.to_s)+'='+CGI.escape(v.to_s) }.join("&")
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                def path_with_params(path, params)
         | 
| 33 | 
            +
                  return path if params.empty?
         | 
| 34 | 
            +
                  path + "?" + compile_params(params)
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                def response_ok?(response)
         | 
| 38 | 
            +
                  test_value = "#{response.code}"
         | 
| 39 | 
            +
                  return test_value == "200"
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
              end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
              def interpret_conversation(response)
         | 
| 44 | 
            +
                format_error(response) if not response_ok?(response)
         | 
| 45 | 
            +
                return format_response(response.body)
         | 
| 46 | 
            +
              end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
              def format_error(response)
         | 
| 49 | 
            +
                result = []
         | 
| 50 | 
            +
                result << response.code
         | 
| 51 | 
            +
                result << response.body
         | 
| 52 | 
            +
                return result
         | 
| 53 | 
            +
              end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
              def format_response(response_body)
         | 
| 56 | 
            +
                response_body
         | 
| 57 | 
            +
              end
         | 
| 58 | 
            +
            end
         | 
    
        data/lib/converse/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,13 +1,13 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: converse
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              hash:  | 
| 4 | 
            +
              hash: 9
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
              segments: 
         | 
| 7 7 | 
             
              - 1
         | 
| 8 8 | 
             
              - 0
         | 
| 9 | 
            -
              -  | 
| 10 | 
            -
              version: 1.0. | 
| 9 | 
            +
              - 15
         | 
| 10 | 
            +
              version: 1.0.15
         | 
| 11 11 | 
             
            platform: ruby
         | 
| 12 12 | 
             
            authors: 
         | 
| 13 13 | 
             
            - Ernst van Graan
         | 
| @@ -48,6 +48,8 @@ files: | |
| 48 48 | 
             
            - lib/converse/comms/mysql/mysql_conversation.rb
         | 
| 49 49 | 
             
            - lib/converse/comms/simple_logger.rb
         | 
| 50 50 | 
             
            - lib/converse/interaction.rb
         | 
| 51 | 
            +
            - lib/converse/rest/rest_broker.rb
         | 
| 52 | 
            +
            - lib/converse/rest/rest_interaction.rb
         | 
| 51 53 | 
             
            - lib/converse/version.rb
         | 
| 52 54 | 
             
            homepage: ""
         | 
| 53 55 | 
             
            licenses: []
         |