Class: Karmasphere::Client
- Inherits:
-
Object
- Object
- Karmasphere::Client
- Defined in:
- lib/karmasphere/client.rb
Instance Method Summary collapse
- #ask(query) ⇒ Object
-
#initialize(*args) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(*args) ⇒ Client
Returns a new instance of Client.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/karmasphere/client.rb', line 73 def initialize(*args) host="query.karmasphere.com" port=8666 type=CONNECTION_UDP if Hash === args[0] then opts = args[0] host = opts[:host] if opts.has_key? :host port = opts[:port] if opts.has_key? :port type = opts[:type] if opts.has_key? :type and opts[:type] == CONNECTION_TCP || opts[:type] == CONNECTION_UDP @auth = nil if opts.has_key? :principal then unless opts.has_key? :credentials raise CredentialsError, "principal missing credentials" end end if opts.has_key? :credentials then unless opts.has_key? :principal raise CredentialsError, "credentials missing principal" end @auth = { "a" => [ opts[:principal], opts[:credentials] ] } end end if type == CONNECTION_UDP @socket = UDPSocket.new Karmasphere.dprint "UDP client: attempting to connect to #{host}:#{port}\n" @socket.connect host, port @socket.fcntl(Fcntl::F_SETFD,1) if defined? Fcntl::F_SETFD Karmasphere.dprint "UDP client: created socket #@socket\n" else Karmasphere.dprint "TCP client: attempting to connect to #{host}:#{port}\n" @socket = TCPSocket.new host, port end @response_pool={} end |
Instance Method Details
#ask(query) ⇒ Object
112 113 114 |
# File 'lib/karmasphere/client.rb', line 112 def ask(query) make_query(query) end |