Sha256: bc70ccb2b54b9b4c2f31bc60cc659b4bc513d9ab4bf8e082415db95ff57e6d58

Contents?: true

Size: 806 Bytes

Versions: 1

Compression:

Stored size: 806 Bytes

Contents

# Simple RPC client on YAML.
module YamlRpc
  
  class Client
    
    attr_accessor :url
    
    def initialize(url)
      @url = url
    end
    
    def method_missing(method, args)
      post(method, args)
    end

  protected

    # * <tt>url</tt> Url
    # * <tt>data</tt> Data to be passed as POST form field 'yaml', ie: { :status => 'SUCCESS', :message => 'All ok' }
    def post(url, data = {})
      url = URI.parse("#{@url}#{url}")
      req = Net::HTTP::Post.new(url.path)
      req.set_form_data({ :yaml => YAML::dump(data) }, ';')
      res = Net::HTTP.new(url.host, url.port).start { |http| http.request(req) }
      case res
        when Net::HTTPSuccess
          YAML::load(res.body)
        else
          res.error!
      end
    end
  
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
yamlrpc-0.1.080624130617 lib/yamlrpc/client.rb