Sha256: a44940663bca0fab6731d6a9822554729783f7eecbf1e68069015a2a2290a0c2

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

require 'thrift'

module Geong
  class Client
    DEFAULT_HOST = '127.0.0.1'
    DEFAULT_PORT = 9090

    attr_reader :transport, :protocol
    def initialize(options = {})
      @transport = options[:transport] || self.class.default_transport(options)
      @protocol =  options[:protocol ] || self.class.default_protocol(@transport, options)
      @client = Geong::Geocoder::GeocoderService::Client.new(@protocol)
    end
    
    def self.default_transport(options)
      Thrift::FramedTransport.new(Thrift::Socket.new(options[:host] || DEFAULT_HOST, options[:port] || DEFAULT_PORT))
    end
    
    def self.default_protocol(transport, options)
      Thrift::BinaryProtocol.new(transport)
    end
    
    def open
      @transport.open
      self
    end
    
    def open?
      @transport.open?
    end
    
    def close
      @transport.close
      self
    end
    
    def closed?
      @transport.closed?
    end
    
    def respond_to_missing?(method, include_private)
      @client.respond_to?(method, include_private)
    end
    
    def method_missing(*args, &block)
      @client.send(*args, &block)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
geong-0.0.2 lib/geong/client.rb
geong-0.0.1 lib/geong/client.rb