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 +4 -4
- data/lib/crate_ruby/client.rb +19 -14
- data/lib/crate_ruby/version.rb +1 -1
- data/spec/crate_ruby/client_spec.rb +2 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89005d37bce3036b7cc74a9cf521a85493f8695e
|
4
|
+
data.tar.gz: d92405d8c41d5c191cd6a943cc45a3227fd2c01b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7fc3c5596813c4de4565c91f4d4a8b8ff5447143a66734956fbf342d997209cde01b042949721184868948c916e0beabd0a985353722bbc7c5d7e17b5afce279
|
7
|
+
data.tar.gz: f7dd74c16239b2e5f6bb5811529c44513b184c77a4849bf45431c4e3ddfa1bf6ebcb121ca71c4b044886f545ee48d1b02bf8cfdff7374b064877e50dcfec3d40
|
data/lib/crate_ruby/client.rb
CHANGED
@@ -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
|
-
# *
|
12
|
-
|
13
|
-
|
14
|
-
@
|
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 =
|
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
|
-
|
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 =
|
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 =
|
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
|
data/lib/crate_ruby/version.rb
CHANGED
@@ -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
|
100
|
-
client.instance_variable_get(:@
|
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
|