crate_ruby 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b3ff57320c97fd0469f294c16516f805ac815380
4
- data.tar.gz: 15b6f0ea26f2d8b64892f706b45a2f23dc753fda
3
+ metadata.gz: 89005d37bce3036b7cc74a9cf521a85493f8695e
4
+ data.tar.gz: d92405d8c41d5c191cd6a943cc45a3227fd2c01b
5
5
  SHA512:
6
- metadata.gz: 4b887ed5e8bfa23435bfa9ad3eecbf8deee91fc5c95242ce7086a80bcfb9fbed64fd8403cdcf4a0ea95c97f05e54a5104d6620aa8df32d6b875163a2b47d565d
7
- data.tar.gz: 338c270195d22fd4fb127cefea310317a2a6b79170f3972f6c597aff6df375ff3e3b6ef4017f0658c2dbb37a019a24e5a13be16c4fc0be1c0296be9d719ffbdf
6
+ metadata.gz: 7fc3c5596813c4de4565c91f4d4a8b8ff5447143a66734956fbf342d997209cde01b042949721184868948c916e0beabd0a985353722bbc7c5d7e17b5afce279
7
+ data.tar.gz: f7dd74c16239b2e5f6bb5811529c44513b184c77a4849bf45431c4e3ddfa1bf6ebcb121ca71c4b044886f545ee48d1b02bf8cfdff7374b064877e50dcfec3d40
@@ -7,13 +7,13 @@ module CrateRuby
7
7
 
8
8
  attr_accessor :logger
9
9
 
10
+ # Currently only a single server is supported. Fail over will be implemented in upcoming versions
11
+ # @param [Array] servers An Array of servers including ports [127.0.0.1:4200, 10.0.0.1:4201]
10
12
  # @param [opts] Optional paramters
11
- # * host: ip or host name, defaults to 127.0.0.1
12
- # * port: defaults to 4200
13
- def initialize(opts = {})
14
- @host = opts[:host] || DEFAULT_HOST
15
- @port = opts[:port] || DEFAULT_PORT
16
- @uri = "http://#{DEFAULT_HOST}:#{DEFAULT_PORT}"
13
+ # * logger: Custom Logger
14
+ def initialize(servers = [], opts = {})
15
+ @servers = servers
16
+ @servers << "#{DEFAULT_HOST}:#{DEFAULT_PORT}" if servers.empty?
17
17
  @logger = opts[:logger] || CrateRuby.logger
18
18
  end
19
19
 
@@ -68,7 +68,7 @@ module CrateRuby
68
68
  def execute(sql)
69
69
  req = Net::HTTP::Post.new("/_sql", initheader = {'Content-Type' => 'application/json'})
70
70
  req.body = {"stmt" => sql}.to_json
71
- response = Net::HTTP.new(@host, @port).start { |http| http.request(req) }
71
+ response = request(req)
72
72
  success = case response.code
73
73
  when "200"
74
74
  ResultSet.new response.body
@@ -91,8 +91,7 @@ module CrateRuby
91
91
  @logger.debug("BLOB PUT #{uri}")
92
92
  req = Net::HTTP::Put.new(blob_path(table, digest))
93
93
  req.body = data
94
- #req["Content-Type"] = "multipart/form-data, boundary=#{boundary}"
95
- response = Net::HTTP.new(@host, @port).start { |http| http.request(req) }
94
+ response = request(req)
96
95
  success = case response.code
97
96
  when "201"
98
97
  true
@@ -100,7 +99,7 @@ module CrateRuby
100
99
  @logger.info("Response #{response.code}: " + response.body)
101
100
  false
102
101
  end
103
- success
102
+ success
104
103
  end
105
104
 
106
105
  # Download blob
@@ -112,9 +111,7 @@ module CrateRuby
112
111
  uri = blob_path(table, digest)
113
112
  @logger.debug("BLOB GET #{uri}")
114
113
  req = Net::HTTP::Get.new(uri)
115
- response = Net::HTTP.new(@host, @port).start do |http|
116
- http.request(req)
117
- end
114
+ response = request(req)
118
115
  case response.code
119
116
  when "200"
120
117
  response.body
@@ -133,7 +130,7 @@ module CrateRuby
133
130
  uri = blob_path(table, digest)
134
131
  @logger.debug("BLOB DELETE #{uri}")
135
132
  req = Net::HTTP::Delete.new(uri)
136
- response = Net::HTTP.new(@host, @port).start { |http| http.request(req) }
133
+ response = request(req)
137
134
  success = case response.code
138
135
  when "200"
139
136
  true
@@ -150,6 +147,14 @@ module CrateRuby
150
147
  "/_blobs/#{table}/#{digest}"
151
148
  end
152
149
 
150
+ def connection
151
+ host, port = @servers.first.split(':');
152
+ Net::HTTP.new(host, port)
153
+ end
154
+
155
+ def request(req)
156
+ connection.start { |http| http.request(req) }
157
+ end
153
158
 
154
159
  end
155
160
  end
@@ -1,3 +1,3 @@
1
1
  module CrateRuby
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -96,10 +96,8 @@ describe CrateRuby::Client do
96
96
 
97
97
  it 'should use host and ports parameters' do
98
98
  logger = double()
99
- client = CrateRuby::Client.new host: "10.0.0.1", port: 5000, logger: logger
100
- client.instance_variable_get(:@host).should eq("10.0.0.1")
101
- client.instance_variable_get(:@port).should eq(5000)
102
- client.instance_variable_get(:@logger).should == logger
99
+ client = CrateRuby::Client.new ["10.0.0.1:5000"],logger: logger
100
+ client.instance_variable_get(:@servers).should eq(["10.0.0.1:5000"])
103
101
  end
104
102
 
105
103
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crate_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christoph Klocker