Class: Stargate::Client
- Inherits:
-
Object
- Object
- Stargate::Client
- 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
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #delete(path, options = {}) ⇒ Object
- #delete_response(path, options = {}) ⇒ Object
- #get(path, options = {}) ⇒ Object
- #get_response(path, options = {}) ⇒ Object
-
#initialize(url = "http://localhost:8080", opts = {}) ⇒ Client
constructor
A new instance of Client.
- #post(path, data = nil, options = {}) ⇒ Object
- #post_response(path, data = nil, options = {}) ⇒ Object
- #put(path, data = nil, options = {}) ⇒ Object
- #put_response(path, data = nil, options = {}) ⇒ Object
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
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
16 17 18 |
# File 'lib/stargate/client.rb', line 16 def connection @connection end |
#url ⇒ Object (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, = {}) safe_request { @connection.delete(@url.path + path, ) } end |
#delete_response(path, options = {}) ⇒ Object
54 55 56 |
# File 'lib/stargate/client.rb', line 54 def delete_response(path, = {}) safe_response { @connection.delete(@url.path + path, ) } end |
#get(path, options = {}) ⇒ Object
34 35 36 |
# File 'lib/stargate/client.rb', line 34 def get(path, = {}) safe_request { @connection.get(@url.path + path, {'Content-Type' => 'text/xml', "Accept" => "application/json"}.merge()) } end |
#get_response(path, options = {}) ⇒ Object
38 39 40 |
# File 'lib/stargate/client.rb', line 38 def get_response(path, = {}) safe_response { @connection.get(@url.path + path, {"Accept" => "application/json"}.merge()) } end |
#post(path, data = nil, options = {}) ⇒ Object
42 43 44 |
# File 'lib/stargate/client.rb', line 42 def post(path, data = nil, = {}) safe_request { @connection.post(@url.path + path, data, {'Content-Type' => 'text/xml', "Accept" => "application/json"}.merge()) } end |
#post_response(path, data = nil, options = {}) ⇒ Object
46 47 48 |
# File 'lib/stargate/client.rb', line 46 def post_response(path, data = nil, = {}) safe_response { @connection.post(@url.path + path, data, {'Content-Type' => 'text/xml', "Accept" => "application/json"}.merge()) } end |
#put(path, data = nil, options = {}) ⇒ Object
58 59 60 |
# File 'lib/stargate/client.rb', line 58 def put(path, data = nil, = {}) safe_request { @connection.put(@url.path + path, data, {'Content-Type' => 'text/xml', "Accept" => "application/json"}.merge()) } end |
#put_response(path, data = nil, options = {}) ⇒ Object
62 63 64 |
# File 'lib/stargate/client.rb', line 62 def put_response(path, data = nil, = {}) safe_response { @connection.put(@url.path + path, data, {'Content-Type' => 'text/xml', "Accept" => "application/json"}.merge()) } end |