Sha256: 9a071eeaea614908a8083889fa09e869bc6cff9df37b6b231b932a2f53dcca8a

Contents?: true

Size: 1.24 KB

Versions: 10

Compression:

Stored size: 1.24 KB

Contents

require 'net/http'

module Hoth
  module Transport
    class Http < Base     
      def call_remote_with(*params)
        begin
          handle_response post_payload(params)
        rescue Exception => e
          raise TransportError.wrap(e)
        end
      end
      
      def handle_response(response)
        case response
        when Net::HTTPSuccess
          Hoth::Logger.debug "response.body: #{response.body}"
          encoder.decode(response.body)["result"]
        when Net::HTTPServerError
          begin
            Hoth::Logger.debug "response.body: #{response.body}"
            raise encoder.decode(response.body)["error"]
          rescue JSON::ParserError => jpe
            raise TransportError.wrap(jpe)
          end
        when Net::HTTPRedirection, Net::HTTPClientError, Net::HTTPInformation, Net::HTTPUnknownResponse
          raise NotImplementedError, "code: #{response.code}, message: #{response.body}"
        end
      end
      
      def post_payload(payload)
        uri = URI.parse(self.endpoint.to_url)
        return Net::HTTP.post_form(uri,
          'name'        => self.name.to_s,
          'caller_uuid' => Hoth.client_uuid,
          'params'      => encoder.encode(payload)
        )
      end
      
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
hoth-0.4.2 lib/hoth/transport/http.rb
hoth-0.4.1 lib/hoth/transport/http.rb
hoth-0.4.0 lib/hoth/transport/http.rb
hoth-0.3.4 lib/hoth/transport/http.rb
hoth-0.3.3 lib/hoth/transport/http.rb
hoth-0.3.2.beta4 lib/hoth/transport/http.rb
hoth-0.3.2.beta3 lib/hoth/transport/http.rb
hoth-0.3.2.beta2 lib/hoth/transport/http.rb
hoth-0.3.2.beta1 lib/hoth/transport/http.rb
hoth-0.3.1 lib/hoth/transport/http.rb