Class: Stargate::Client

Inherits:
Object
  • Object
show all
Includes:
Operation::MetaOperation, Operation::RowOperation, Operation::ScannerOperation, Operation::TableOperation
Defined in:
lib/stargate/client.rb

Constant Summary collapse

VERSION =

File.read(File.join(File.dirname(__FILE__), “..”, “..”, “VERSION”)).chomp.freeze

1

Constants included from Operation::RowOperation

Operation::RowOperation::Converter

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Operation::ScannerOperation

#close_scanner, #get_rows, #open_scanner

Methods included from Operation::RowOperation

#create_row, #delete_row, #row_timestamps, #show_row

Methods included from Operation::TableOperation

#alter_table, #create_table, #delete_table, #destroy_table, #disable_table, #enable_table, #show_table, #table_regions

Methods included from Operation::MetaOperation

#cluster_version, #list_tables, #version

Constructor Details

#initialize(url = "http://localhost:8080", opts = {}) ⇒ Client

Returns a new instance of Client.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/stargate/client.rb', line 18

def initialize(url = "http://localhost:8080", opts = {})
  @url = URI.parse(url)
  unless @url.kind_of? URI::HTTP
    raise "invalid http url: #{url}"
  end

  # Not actually opening the connection yet, just setting up the persistent connection.
  if opts[:proxy]
    proxy_address, proxy_port = opts[:proxy].split(':')
    @connection = Net::HTTP.Proxy(proxy_address, proxy_port).new(@url.host, @url.port)
  else
    @connection = Net::HTTP.new(@url.host, @url.port)
  end
  @connection.read_timeout = opts[:timeout] if opts[:timeout]
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



16
17
18
# File 'lib/stargate/client.rb', line 16

def connection
  @connection
end

#urlObject (readonly)

Returns the value of attribute url.



16
17
18
# File 'lib/stargate/client.rb', line 16

def url
  @url
end

Instance Method Details

#delete(path, options = {}) ⇒ Object



50
51
52
# File 'lib/stargate/client.rb', line 50

def delete(path, options = {})
  safe_request { @connection.delete(@url.path + path, options) }
end

#delete_response(path, options = {}) ⇒ Object



54
55
56
# File 'lib/stargate/client.rb', line 54

def delete_response(path, options = {})
  safe_response { @connection.delete(@url.path + path, options) }
end

#get(path, options = {}) ⇒ Object



34
35
36
# File 'lib/stargate/client.rb', line 34

def get(path, options = {})
  safe_request { @connection.get(@url.path + path, {'Content-Type' => 'text/xml', "Accept" => "application/json"}.merge(options)) }
end

#get_response(path, options = {}) ⇒ Object



38
39
40
# File 'lib/stargate/client.rb', line 38

def get_response(path, options = {})
  safe_response { @connection.get(@url.path + path, {"Accept" => "application/json"}.merge(options)) }
end

#post(path, data = nil, options = {}) ⇒ Object



42
43
44
# File 'lib/stargate/client.rb', line 42

def post(path, data = nil, options = {})
  safe_request { @connection.post(@url.path + path, data, {'Content-Type' => 'text/xml', "Accept" => "application/json"}.merge(options)) }
end

#post_response(path, data = nil, options = {}) ⇒ Object



46
47
48
# File 'lib/stargate/client.rb', line 46

def post_response(path, data = nil, options = {})
  safe_response { @connection.post(@url.path + path, data, {'Content-Type' => 'text/xml', "Accept" => "application/json"}.merge(options)) }
end

#put(path, data = nil, options = {}) ⇒ Object



58
59
60
# File 'lib/stargate/client.rb', line 58

def put(path, data = nil, options = {})
  safe_request { @connection.put(@url.path + path, data, {'Content-Type' => 'text/xml', "Accept" => "application/json"}.merge(options)) }
end

#put_response(path, data = nil, options = {}) ⇒ Object



62
63
64
# File 'lib/stargate/client.rb', line 62

def put_response(path, data = nil, options = {})
  safe_response { @connection.put(@url.path + path, data, {'Content-Type' => 'text/xml', "Accept" => "application/json"}.merge(options)) }
end