yoga_pants 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +4 -0
- data/lib/yoga_pants/client.rb +37 -12
- data/lib/yoga_pants/connection.rb +1 -0
- data/lib/yoga_pants/version.rb +1 -1
- data/spec/integration/basic_spec.rb +3 -3
- metadata +47 -16
data/CHANGELOG.md
CHANGED
data/lib/yoga_pants/client.rb
CHANGED
@@ -5,15 +5,6 @@ module YogaPants
|
|
5
5
|
# * failing over to nodes in a list
|
6
6
|
# * ES-specific error handling
|
7
7
|
|
8
|
-
class RequestError < RuntimeError
|
9
|
-
attr_reader :http_error
|
10
|
-
|
11
|
-
def initialize(message, http_error = nil)
|
12
|
-
@http_error = nil
|
13
|
-
super(message)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
8
|
attr_accessor :hosts, :options, :active_host
|
18
9
|
|
19
10
|
def initialize(hosts, options = {})
|
@@ -55,6 +46,8 @@ module YogaPants
|
|
55
46
|
|
56
47
|
BULK_OPERATIONS_WITH_DATA = [:index, :create].freeze
|
57
48
|
def bulk(path, operations, args = {})
|
49
|
+
return [] if operations.empty?
|
50
|
+
|
58
51
|
path = path.sub(%r{/(?:_bulk)?$}, '/_bulk')
|
59
52
|
|
60
53
|
with_error_handling do
|
@@ -112,6 +105,38 @@ module YogaPants
|
|
112
105
|
connection.reset
|
113
106
|
end
|
114
107
|
|
108
|
+
class RequestError < RuntimeError; end
|
109
|
+
|
110
|
+
class HTTPRequestError < RequestError
|
111
|
+
attr_reader :http_error
|
112
|
+
|
113
|
+
def initialize(message, http_error)
|
114
|
+
super(message)
|
115
|
+
@http_error = http_error
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
class ElasticSearchError < RequestError
|
120
|
+
attr_reader :elasticsearch_exception_name
|
121
|
+
attr_reader :elasticsearch_exception_details
|
122
|
+
|
123
|
+
def initialize(elasticsearch_error_message, original_exception)
|
124
|
+
super(elasticsearch_error_message)
|
125
|
+
set_backtrace(original_exception.backtrace)
|
126
|
+
parse_and_set_elasticsearch_error_message(elasticsearch_error_message)
|
127
|
+
end
|
128
|
+
|
129
|
+
def parse_and_set_elasticsearch_error_message(message)
|
130
|
+
if message =~ /(\w+)\[(.+)\]/m
|
131
|
+
@elasticsearch_exception_name = $1
|
132
|
+
@elasticsearch_exception_details = $2
|
133
|
+
else
|
134
|
+
@elasticsearch_exception_name = message
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
|
115
140
|
private
|
116
141
|
|
117
142
|
def connection
|
@@ -134,10 +159,10 @@ module YogaPants
|
|
134
159
|
@retries += 1
|
135
160
|
pick_next_host
|
136
161
|
retry
|
137
|
-
elsif e.body.is_a?(Hash) &&
|
138
|
-
raise
|
162
|
+
elsif e.body.is_a?(Hash) && error_message = e.body['error']
|
163
|
+
raise ElasticSearchError.new(error_message, e)
|
139
164
|
else
|
140
|
-
raise
|
165
|
+
raise HTTPRequestError.new(e.message, e)
|
141
166
|
end
|
142
167
|
end
|
143
168
|
end
|
@@ -33,6 +33,7 @@ module YogaPants
|
|
33
33
|
@host = host.chomp('/')
|
34
34
|
@options = options || {}
|
35
35
|
@http = HTTPClient.new
|
36
|
+
@http.debug_dev = @options[:debug_io] if @options[:debug_io].respond_to?(:<<)
|
36
37
|
|
37
38
|
default_timeout = @options[:timeout] || 5
|
38
39
|
http.connect_timeout = @options[:connect_timeout] || default_timeout
|
data/lib/yoga_pants/version.rb
CHANGED
@@ -97,7 +97,7 @@ module YogaPants
|
|
97
97
|
[:index, {:_index => 'yoga_pants_test', :_type => 'doc', :_id => 1}, {:bar => 1}],
|
98
98
|
[:index, {:_index => '', :_type => 'doc', :_id => 2}, {:bar => 'invalid'}],
|
99
99
|
])
|
100
|
-
end.to raise_error(Client::
|
100
|
+
end.to raise_error(Client::ElasticSearchError, "ElasticSearchException[String index out of range: 0]; nested: StringIndexOutOfBoundsException[String index out of range: 0]; ")
|
101
101
|
|
102
102
|
subject.exists?("/yoga_pants_test/doc/1").should be_false
|
103
103
|
subject.exists?("/yoga_pants_test/doc/2").should be_false
|
@@ -137,7 +137,7 @@ module YogaPants
|
|
137
137
|
subject.post("/yoga_pants_test/doc/1", :body => {
|
138
138
|
:foo => 'bar'
|
139
139
|
})
|
140
|
-
expect { subject.get("/yoga_pants_test/doc/1/_mlt?min_term_freq=invalid") }.to raise_error(Client::
|
140
|
+
expect { subject.get("/yoga_pants_test/doc/1/_mlt?min_term_freq=invalid") }.to raise_error(Client::ElasticSearchError, "Failed to parse int parameter [min_term_freq] with value [invalid]")
|
141
141
|
end
|
142
142
|
end
|
143
143
|
|
@@ -154,7 +154,7 @@ module YogaPants
|
|
154
154
|
|
155
155
|
it "raises an RequestError" do
|
156
156
|
VCR.use_cassette('connection_refused') do
|
157
|
-
expect { subject.exists?("/foo") }.to raise_error(Client::
|
157
|
+
expect { subject.exists?("/foo") }.to raise_error(Client::HTTPRequestError, "Connection refused to http://localhost:1")
|
158
158
|
end
|
159
159
|
end
|
160
160
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yoga_pants
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,22 +9,27 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-06-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httpclient
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- - =
|
19
|
+
- - '='
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: 2.2.5
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - '='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.2.5
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: multi_json
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: '0'
|
33
38
|
type: :runtime
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: rspec
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ! '>='
|
@@ -43,10 +53,15 @@ dependencies:
|
|
43
53
|
version: '0'
|
44
54
|
type: :development
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: vcr
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ! '>='
|
@@ -54,10 +69,15 @@ dependencies:
|
|
54
69
|
version: '0'
|
55
70
|
type: :development
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
58
78
|
- !ruby/object:Gem::Dependency
|
59
79
|
name: webmock
|
60
|
-
requirement:
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
61
81
|
none: false
|
62
82
|
requirements:
|
63
83
|
- - ! '>='
|
@@ -65,10 +85,15 @@ dependencies:
|
|
65
85
|
version: '0'
|
66
86
|
type: :development
|
67
87
|
prerelease: false
|
68
|
-
version_requirements:
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
69
94
|
- !ruby/object:Gem::Dependency
|
70
95
|
name: rake
|
71
|
-
requirement:
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
72
97
|
none: false
|
73
98
|
requirements:
|
74
99
|
- - ! '>='
|
@@ -76,7 +101,12 @@ dependencies:
|
|
76
101
|
version: '0'
|
77
102
|
type: :development
|
78
103
|
prerelease: false
|
79
|
-
version_requirements:
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
80
110
|
description: A super lightweight interface to ElasticSearch's HTTP REST API
|
81
111
|
email:
|
82
112
|
executables: []
|
@@ -129,10 +159,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
159
|
version: '0'
|
130
160
|
requirements: []
|
131
161
|
rubyforge_project:
|
132
|
-
rubygems_version: 1.8.
|
162
|
+
rubygems_version: 1.8.23
|
133
163
|
signing_key:
|
134
164
|
specification_version: 3
|
135
165
|
summary: A super lightweight interface to ElasticSearch's HTTP REST API.
|
136
166
|
test_files:
|
137
167
|
- spec/integration/basic_spec.rb
|
138
168
|
- spec/spec_helper.rb
|
169
|
+
has_rdoc:
|