rubberband 0.1.6 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - ruby-head
6
+ # - jruby-18mode
7
+ # - jruby-19mode
8
+ # - jruby-head
9
+ - rbx-18mode
10
+ - rbx-19mode
11
+
12
+ before_install:
13
+ - sudo service elasticsearch start
14
+ - sleep 3
15
+
16
+ notifications:
17
+ email: false
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  gemspec
4
+
5
+ gem 'thrift'
@@ -0,0 +1,65 @@
1
+ # RubberBand
2
+ [![Build Status](https://secure.travis-ci.org/grantr/rubberband.png?branch=master)](http://travis-ci.org/grantr/rubberband)
3
+
4
+ An ElasticSearch client with ThriftClient-like failover handling.
5
+
6
+ ## License
7
+
8
+ Copyright 2010-2012 Grant Rodgers. See included LICENSE file.
9
+
10
+ ## Features
11
+
12
+ * Automatic failover, retry, and peer discovery
13
+ * Support for multiple transports (HTTP, Thrift, Memcached)
14
+ * Support for multiple encodings (JSON, Smile TODO)
15
+
16
+ Rubberband uses MultiJson for JSON encoding and decoding and supports all JSON backends that MultiJson supports.
17
+
18
+ The HTTP transport uses Faraday, which also supports a number of http backends. Choose the one that works best for you.
19
+
20
+ ## Supported Rubies
21
+
22
+ Tested on 1.8.7, 1.9.2, 1.9.3, and Rubinius in 1.8 and 1.9 mode. Ruby 1.8.6 is NOT supported due to missing String#bytesize.
23
+
24
+ ## Usage
25
+
26
+ Instantiate a client:
27
+
28
+ client = ElasticSearch.new('http://127.0.0.1:9200', :index => "twitter", :type => "tweet")
29
+
30
+ Instantiate a client with multiple servers:
31
+
32
+ client = ElasticSearch.new(['127.0.0.1:9200', '127.0.0.1:9201'])
33
+
34
+ Instantiate a client using a Heroku URL (this sets the default index):
35
+
36
+ client = ElasticSearch.new(ENV['ELASTICSEARCH_URL'])
37
+
38
+ Connect using the thrift transport (requires the thrift gem and elasticsearch thrift plugin to be installed):
39
+
40
+ client = ElasticSearch.new('127.0.0.1:9500', :transport => ElasticSearch::Transport::Thrift)
41
+
42
+ Pass a block to Faraday to configure middleware and options:
43
+
44
+ ```ruby
45
+ client = ElasticSearch::Client.new('127.0.0.1:9200') do |conn|
46
+ conn.response :logger
47
+ conn.adapter Faraday.default_adapter
48
+ end
49
+ ```
50
+
51
+ API:
52
+ ```ruby
53
+ client.index({:body => "elasticsearch is cool"}, :id => 1)
54
+ client.get("1")
55
+ client.search("body:elasticsearch")
56
+ ```
57
+ ## TODO
58
+
59
+ See TODO file.
60
+
61
+ ## Contributing
62
+
63
+ http://github.com/grantr/rubberband
64
+
65
+ Fork, code, send pull request
data/Rakefile CHANGED
@@ -8,6 +8,3 @@ RSpec::Core::RakeTask.new(:spec) do |spec|
8
8
  end
9
9
 
10
10
  task :default => :spec
11
-
12
- require 'yard'
13
- YARD::Rake::YardocTask.new
data/TODO CHANGED
@@ -1,7 +1,5 @@
1
- delete_by_query
2
1
  terms
3
2
  more_like_this
4
- bulk ops
5
3
  test scroll better, maybe add a scroller object
6
4
  handle partial failure cases where some shards are unsuccessful (optionally raise a PartialResult exception, allow override option to return results anyway. results should have a flag that signifies incompleteness)
7
5
  tests/specs/features
@@ -8,7 +8,7 @@ require 'client'
8
8
 
9
9
  module ElasticSearch
10
10
 
11
- def self.new(servers_or_url, options={})
12
- ElasticSearch::Client.new(servers_or_url, options)
11
+ def self.new(servers_or_url, options={}, &block)
12
+ ElasticSearch::Client.new(servers_or_url, options, &block)
13
13
  end
14
14
  end
@@ -7,37 +7,40 @@ module ElasticSearch
7
7
  :transport => ElasticSearch::Transport::HTTP
8
8
  }.freeze
9
9
 
10
- def initialize(servers_or_url, options={})
10
+ attr_accessor :servers, :current_server, :connection
11
+
12
+ def initialize(servers_or_url, options={}, &block)
11
13
  @options = DEFAULTS.merge(options)
12
- @server_list, @default_index, @default_type = extract_server_list_and_defaults(servers_or_url)
13
- @current_server = @server_list.first
14
+ @servers, @default_index, @default_type = extract_servers_and_defaults(servers_or_url)
15
+ @current_server = @servers.first
16
+ @connect_block = block
14
17
  end
15
18
 
16
- def extract_server_list_and_defaults(servers_or_url)
19
+ def extract_servers_and_defaults(servers_or_url)
17
20
  default_index = default_type = nil
18
- servers = Array(servers_or_url).collect do |server|
19
- uri = URI.parse(server)
20
- _, default_index, default_type = uri.path.split("/")
21
- uri.path = "" # is this expected behavior of URI? may be dangerous to rely on
22
- uri.to_s
21
+ given_servers = Array(servers_or_url).collect do |server|
22
+ begin
23
+ uri = URI.parse(server)
24
+ _, default_index, default_type = uri.path.split("/")
25
+ uri.path = "" # is this expected behavior of URI? may be dangerous to rely on
26
+ uri.to_s
27
+ rescue URI::InvalidURIError
28
+ server
29
+ end
23
30
  end
24
- [servers, default_index, default_type]
25
- end
26
-
27
- def current_server
28
- @current_server
29
- end
30
-
31
- def servers
32
- @server_list
33
- end
34
-
35
- def inspect
36
- "<#{self.class} @current_server=#{@current_server} @server_list=#{@server_list.inspect} @options=#{@options.inspect}>"
31
+ [given_servers, default_index, default_type]
37
32
  end
38
33
 
39
34
  def connect!
40
- @connection = @options[:transport].new(@current_server, @options)
35
+ if @options[:transport].is_a?(Class)
36
+ if @connect_block
37
+ @connection = @options[:transport].new(@current_server, @options, &@connect_block)
38
+ else
39
+ @connection = @options[:transport].new(@current_server, @options)
40
+ end
41
+ else
42
+ @connection = @options[:transport]
43
+ end
41
44
  @connection.connect!
42
45
  end
43
46
 
@@ -5,16 +5,12 @@ module ElasticSearch
5
5
  PSEUDO_INDICES = [:all]
6
6
 
7
7
  def index_status(*args)
8
- options = args.last.is_a?(Hash) ? args.pop : {}
9
- indices = args.empty? ? [(default_index || :all)] : args.flatten
10
- indices.collect! { |i| PSEUDO_INDICES.include?(i) ? "_#{i}" : i }
8
+ indices, options = extract_indices_and_options(args)
11
9
  execute(:index_status, indices, options)
12
10
  end
13
11
 
14
12
  def index_mapping(*args)
15
- options = args.last.is_a?(Hash) ? args.pop : {}
16
- indices = args.empty? ? [(default_index || :all)] : args.flatten
17
- indices.collect! { |i| PSEUDO_INDICES.include?(i) ? "_#{i}" : i }
13
+ indices, options = extract_indices_and_options(args)
18
14
  execute(:index_mapping, indices, options)
19
15
  end
20
16
 
@@ -92,9 +88,7 @@ module ElasticSearch
92
88
  # options: refresh
93
89
  # default: default_index if defined, otherwise :all
94
90
  def flush(*args)
95
- options = args.last.is_a?(Hash) ? args.pop : {}
96
- indices = args.empty? ? [(default_index || :all)] : args.flatten
97
- indices.collect! { |i| PSEUDO_INDICES.include?(i) ? "_#{i}" : i }
91
+ indices, options = extract_indices_and_options(args)
98
92
  execute(:flush, indices, options)
99
93
  end
100
94
 
@@ -102,9 +96,7 @@ module ElasticSearch
102
96
  # no options
103
97
  # default: default_index if defined, otherwise all
104
98
  def refresh(*args)
105
- options = args.last.is_a?(Hash) ? args.pop : {}
106
- indices = args.empty? ? [(default_index || :all)] : args.flatten
107
- indices.collect! { |i| PSEUDO_INDICES.include?(i) ? "_#{i}" : i }
99
+ indices, options = extract_indices_and_options(args)
108
100
  execute(:refresh, indices, options)
109
101
  end
110
102
 
@@ -112,9 +104,7 @@ module ElasticSearch
112
104
  # no options
113
105
  # default: default_index if defined, otherwise all
114
106
  def snapshot(*args)
115
- options = args.last.is_a?(Hash) ? args.pop : {}
116
- indices = args.empty? ? [(default_index || :all)] : args.flatten
117
- indices.collect! { |i| PSEUDO_INDICES.include?(i) ? "_#{i}" : i }
107
+ indices, options = extract_indices_and_options(args)
118
108
  execute(:snapshot, indices, options)
119
109
  end
120
110
 
@@ -122,9 +112,7 @@ module ElasticSearch
122
112
  # options: max_num_segments, only_expunge_deletes, refresh, flush
123
113
  # default: default_index if defined, otherwise all
124
114
  def optimize(*args)
125
- options = args.last.is_a?(Hash) ? args.pop : {}
126
- indices = args.empty? ? [(default_index || :all)] : args.flatten
127
- indices.collect! { |i| PSEUDO_INDICES.include?(i) ? "_#{i}" : i }
115
+ indices, options = extract_indices_and_options(args)
128
116
  execute(:optimize, indices, options)
129
117
  end
130
118
 
@@ -143,6 +131,14 @@ module ElasticSearch
143
131
  def delete_river(type=nil, options={})
144
132
  execute(:delete_river, type, options)
145
133
  end
134
+
135
+ private
136
+ def extract_indices_and_options(args)
137
+ options = args.last.is_a?(Hash) ? args.pop : {}
138
+ indices = args.empty? ? [(default_index || :all)] : args.flatten
139
+ indices.collect! { |i| PSEUDO_INDICES.include?(i) ? "_#{i}" : i }
140
+ [indices, options]
141
+ end
146
142
  end
147
143
  end
148
144
  end
@@ -5,7 +5,7 @@ module ElasticSearch
5
5
  :auto_discovery => true
6
6
  }.freeze
7
7
 
8
- def initialize(servers, options={})
8
+ def initialize(servers_or_url, options={})
9
9
  super
10
10
  @options = AUTO_DISCOVERING_DEFAULTS.merge(@options)
11
11
  if @options[:auto_discovery]
@@ -15,7 +15,7 @@ module ElasticSearch
15
15
 
16
16
  #TODO how to autodiscover on reconnect? don't want to overwrite methods of RetryingClient
17
17
  def auto_discover_nodes!
18
- @server_list = execute(:all_nodes)
18
+ @servers = execute(:all_nodes)
19
19
  end
20
20
  end
21
21
  end
@@ -14,10 +14,10 @@ module ElasticSearch
14
14
  }.freeze
15
15
 
16
16
  # use cluster status to get server list
17
- def initialize(servers, options={})
17
+ def initialize(servers_or_url, options={})
18
18
  super
19
19
  @options = RETRYING_DEFAULTS.merge(@options)
20
- @retries = options[:retries] || @server_list.size
20
+ @retries = options[:retries] || @servers.size
21
21
  @request_count = 0
22
22
  @max_requests = @options[:server_max_requests]
23
23
  @retry_period = @options[:server_retry_period]
@@ -46,7 +46,7 @@ module ElasticSearch
46
46
  def next_server
47
47
  if @retry_period
48
48
  rebuild_live_server_list! if Time.now > @last_rebuild + @retry_period
49
- raise NoServersAvailable, "No live servers in #{@server_list.inspect} since #{@last_rebuild.inspect}." if @live_server_list.empty?
49
+ raise NoServersAvailable, "No live servers in #{@servers.inspect} since #{@last_rebuild.inspect}." if @live_server_list.empty?
50
50
  elsif @live_server_list.empty?
51
51
  rebuild_live_server_list!
52
52
  end
@@ -56,9 +56,9 @@ module ElasticSearch
56
56
  def rebuild_live_server_list!
57
57
  @last_rebuild = Time.now
58
58
  if @options[:randomize_server_list]
59
- @live_server_list = @server_list.sort_by { rand }
59
+ @live_server_list = @servers.sort_by { rand }
60
60
  else
61
- @live_server_list = @server_list.dup
61
+ @live_server_list = @servers.dup
62
62
  end
63
63
  end
64
64
 
@@ -1,14 +1,26 @@
1
- require 'yajl'
1
+ require 'multi_json'
2
2
 
3
3
  module ElasticSearch
4
4
  module Encoding
5
5
  class JSON < Base
6
- def encode(object)
7
- Yajl::Encoder.encode(object)
8
- end
9
6
 
10
- def decode(string)
11
- Yajl::Parser.parse(string)
7
+ # MultiJson switched to a new api in 1.3
8
+ if MultiJson.respond_to?(:adapter)
9
+ def encode(object)
10
+ MultiJson.dump(object)
11
+ end
12
+
13
+ def decode(string)
14
+ MultiJson.load(string)
15
+ end
16
+ else
17
+ def encode(object)
18
+ MultiJson.encode(object)
19
+ end
20
+
21
+ def decode(string)
22
+ MultiJson.decode(string)
23
+ end
12
24
  end
13
25
 
14
26
  def is_encoded?(object)
@@ -1,3 +1,5 @@
1
+ require 'faraday'
2
+
1
3
  module ElasticSearch
2
4
  module Transport
3
5
  module IndexProtocol
@@ -42,8 +44,8 @@ module ElasticSearch
42
44
 
43
45
  def search(index, type, query, options={})
44
46
  if query.is_a?(Hash)
45
- # patron cannot submit get requests with content, so if query is a hash, post it instead (assume a query hash is using the query dsl)
46
- response = request(:post, {:index => index, :type => type, :op => "_search"}, options, encoder.encode(query))
47
+ # Some http libraries cannot submit get requests with content, so if query is a hash, post it instead (assume a query hash is using the query dsl)
48
+ response = request(:get, {:index => index, :type => type, :op => "_search"}, options, encoder.encode(query))
47
49
  else
48
50
  response = request(:get, {:index => index, :type => type, :op => "_search"}, options.merge(:q => query))
49
51
  end
@@ -58,7 +60,7 @@ module ElasticSearch
58
60
  end
59
61
 
60
62
  def scroll(scroll_id, options={})
61
- # patron cannot submit get requests with content, so we pass the scroll_id in the parameters
63
+ # Some http libraries cannot submit get requests with content, so we pass the scroll_id in the parameters
62
64
  response = request(:get, {:op => "_search/scroll"}, options.merge(:scroll_id => scroll_id))
63
65
  handle_error(response) unless response.status == 200
64
66
  results = encoder.decode(response.body)
@@ -72,7 +74,7 @@ module ElasticSearch
72
74
 
73
75
  def count(index, type, query, options={})
74
76
  if query.is_a?(Hash)
75
- # patron cannot submit get requests with content, so if query is a hash, post it instead (assume a query hash is using the query dsl)
77
+ # Some http libraries cannot submit get requests with content, so if query is a hash, post it instead (assume a query hash is using the query dsl)
76
78
  response = request(:post, {:index => index, :type => type, :op => "_count"}, options, encoder.encode(query))
77
79
  else
78
80
  response = request(:get, {:index => index, :type => type, :op => "_count"}, options.merge(:q => query))
@@ -248,17 +250,12 @@ module ElasticSearch
248
250
  nil
249
251
  end
250
252
 
251
- # faster than CGI.escape
252
- # stolen from RSolr, who stole it from Rack
253
253
  def escape(string)
254
- string.to_s.gsub(/([^ a-zA-Z0-9_.-]+)/n) {
255
- #'%'+$1.unpack('H2'*$1.size).join('%').upcase
256
- '%'+$1.unpack('H2'*bytesize($1)).join('%').upcase
257
- }.tr(' ', '+')
254
+ Faraday::Utils.escape(string)
258
255
  end
259
256
 
260
257
  def unescape(string)
261
- CGI.unescape(string)
258
+ Faraday::Utils.unescape(string)
262
259
  end
263
260
 
264
261
  if ''.respond_to?(:force_encoding) && ''.respond_to?(:encoding)
@@ -273,18 +270,6 @@ module ElasticSearch
273
270
  string
274
271
  end
275
272
  end
276
-
277
- # Return the bytesize of String; uses String#size under Ruby 1.8 and
278
- # String#bytesize under 1.9.
279
- if ''.respond_to?(:bytesize)
280
- def bytesize(string)
281
- string.bytesize
282
- end
283
- else
284
- def bytesize(string)
285
- string.size
286
- end
287
- end
288
273
  end
289
274
 
290
275
  module BaseProtocol
@@ -1,5 +1,4 @@
1
- require 'patron'
2
- require 'cgi'
1
+ require 'faraday'
3
2
 
4
3
  module ElasticSearch
5
4
  module Transport
@@ -10,9 +9,12 @@ module ElasticSearch
10
9
  :protocol => 'http'
11
10
  }.freeze
12
11
 
13
- def initialize(server, options={})
12
+ attr_accessor :session
13
+
14
+ def initialize(server, options={}, &block)
14
15
  super
15
16
  @options = DEFAULTS.merge(@options)
17
+ @connect_block = block if block_given?
16
18
 
17
19
  # Make sure the server starts with a URI scheme.
18
20
  unless @server =~ /^(([^:\/?#]+):)?\/\//
@@ -21,10 +23,12 @@ module ElasticSearch
21
23
  end
22
24
 
23
25
  def connect!
24
- @session = Patron::Session.new
25
- @session.base_url = @server
26
- @session.timeout = @options[:timeout]
27
- @session.headers['User-Agent'] = 'ElasticSearch.rb v0.1'
26
+ if @connect_block
27
+ @session = Faraday.new :url => @server, :headers => {'User-Agent' => 'Rubberband'}, &@connect_block
28
+ else
29
+ @session = Faraday.new :url => @server, :headers => {'User-Agent' => 'Rubberband'}
30
+ end
31
+ @session.options[:timeout] = @options[:timeout]
28
32
  end
29
33
 
30
34
  def all_nodes
@@ -41,21 +45,20 @@ module ElasticSearch
41
45
 
42
46
  def request(method, operation, params={}, body=nil, headers={})
43
47
  begin
44
- uri = generate_uri(operation)
45
- query = generate_query_string(params)
46
- path = [uri, query].join("?")
47
- #puts "request: #{method} #{@server} #{path} #{body}"
48
- response = @session.request(method, path, headers, :data => body)
48
+ response = @session.send(method, generate_uri(operation)) do |req|
49
+ req.headers = headers
50
+ req.params = params
51
+ req.body = body
52
+ end
53
+ # handle all 500 statuses here, other statuses are protocol-specific
49
54
  handle_error(response) if response.status >= 500
50
55
  response
51
56
  rescue Exception => e
52
57
  case e
53
- when Patron::ConnectionFailed
54
- raise ConnectionFailed
55
- when Patron::HostResolutionError
56
- raise HostResolutionError
57
- when Patron::TimeoutError
58
- raise TimeoutError
58
+ when Faraday::Error::ConnectionFailed
59
+ raise ConnectionFailed, $!
60
+ when Faraday::Error::TimeoutError
61
+ raise TimeoutError, $!
59
62
  else
60
63
  raise e
61
64
  end
@@ -60,7 +60,7 @@ module ElasticSearch
60
60
  rescue Exception => e
61
61
  case e
62
62
  when TimeoutError
63
- raise TimeoutError
63
+ raise TimeoutError, $!
64
64
  else
65
65
  raise e
66
66
  end
@@ -95,9 +95,9 @@ module ElasticSearch
95
95
  when ::Thrift::TransportException
96
96
  case e.type
97
97
  when ::Thrift::TransportException::TIMED_OUT
98
- raise TimeoutError
98
+ raise TimeoutError, $!
99
99
  else
100
- raise ConnectionFailed
100
+ raise ConnectionFailed, $!
101
101
  end
102
102
  #TODO Thrift::ApplicationException, Thrift::ProtocolException, IOError.. retryable or fatal?
103
103
  else
@@ -1,3 +1,3 @@
1
1
  module ElasticSearch
2
- VERSION = "0.1.6"
2
+ VERSION = "0.9.0"
3
3
  end
@@ -22,16 +22,15 @@ Gem::Specification.new do |s|
22
22
 
23
23
  s.extra_rdoc_files = [
24
24
  "LICENSE",
25
- "README.rdoc"
25
+ "README.md"
26
26
  ]
27
27
  s.licenses = ["Apache v2"]
28
28
 
29
- s.add_runtime_dependency("patron", ["~> 0.4.12"])
30
- s.add_runtime_dependency("yajl-ruby", [">= 0"])
31
- s.add_development_dependency("rake", ["~> 0.9.2"])
32
- s.add_development_dependency("rspec", ["~> 2.0"])
33
- s.add_development_dependency("yard", [">= 0.7.0"])
34
- s.add_development_dependency("simplecov", [">= 0.3.8"])
35
- s.add_development_dependency("mocha", ["~> 0.9.0"])
29
+ s.add_runtime_dependency "faraday"
30
+ s.add_runtime_dependency "multi_json"
31
+ s.add_development_dependency "rake"
32
+ s.add_development_dependency "rspec", ["~> 2.0"]
33
+ s.add_development_dependency "simplecov", [">= 0.3.8"]
34
+ s.add_development_dependency "mocha", ["~> 0.9.0"]
36
35
 
37
36
  end
@@ -1,6 +1,14 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "connect" do
4
+ context 'ip and port only' do
5
+ let(:servers) { '127.0.0.1:9200' }
6
+
7
+ it 'should connect' do
8
+ client = ElasticSearch.new(servers)
9
+ client.nodes_info.should include('cluster_name')
10
+ end
11
+ end
4
12
 
5
13
  context 'one server' do
6
14
  let(:servers) { 'http://127.0.0.1:9200' }
@@ -58,4 +66,34 @@ describe "connect" do
58
66
  client.default_type.should == 'test_type'
59
67
  end
60
68
  end
69
+
70
+ context 'alternate transport' do
71
+ let(:servers) { '127.0.0.1:9500' }
72
+
73
+ it 'should take an alternate transport class' do
74
+ client = ElasticSearch.new(servers, :auto_discovery => false, :transport => DummyTransport)
75
+ client.connect!
76
+ client.connection.should be_an_instance_of(DummyTransport)
77
+ end
78
+
79
+ it 'should take a transport object' do
80
+ transport = DummyTransport.new(servers)
81
+ client = ElasticSearch.new(servers, :auto_discovery => false, :transport => transport)
82
+ client.connect!
83
+ client.connection.should be(transport)
84
+ end
85
+ end
86
+
87
+ context 'with block' do
88
+ let(:server) { '127.0.0.1:9200' }
89
+
90
+ it 'should pass the block to the transport' do
91
+ client = ElasticSearch.new(server, :auto_discovery => false, :transport => DummyTransport) do
92
+ 'hi there'
93
+ end
94
+ client.connect!
95
+
96
+ client.connection.block.call.should == 'hi there'
97
+ end
98
+ end
61
99
  end
@@ -12,4 +12,17 @@ describe ElasticSearch::Transport::HTTP do
12
12
  described_class.new(server, :protocol => 'https').instance_variable_get('@server').should =~ /^https:\/\//
13
13
  end
14
14
  end
15
+
16
+ context 'with block' do
17
+ let(:server) { 'http://127.0.0.1:9200' }
18
+
19
+ it 'should pass the block to Faraday.new' do
20
+ transport = described_class.new(server) do |conn|
21
+ conn.options[:foo] = 'bar'
22
+ end
23
+ transport.connect!
24
+
25
+ transport.session.options[:foo].should == 'bar'
26
+ end
27
+ end
15
28
  end
@@ -81,4 +81,14 @@ describe "index ops" do
81
81
  { "id" => "3", "fields" => { "foo" => "bazbar" }, "_source" => nil },
82
82
  ]
83
83
  end
84
+
85
+ it 'should handle html escaping and unescaping' do
86
+ @client.index({'fo/o' => 'ba=r'}, :id => "1'")
87
+ @client.refresh
88
+
89
+ results = @client.search({:query => { :field => { 'fo/o' => 'ba=r' }}})
90
+ results.should have(1).item
91
+ results.first.id.should == "1'"
92
+ results.first._source.should == {'fo/o' => 'ba=r'}
93
+ end
84
94
  end
@@ -1,4 +1,4 @@
1
- if RUBY_VERSION =~ /^1\.9/
1
+ if RUBY_VERSION =~ /^1\.9/ && RUBY_ENGINE == "ruby" # don't run coverage on rbx
2
2
  require 'simplecov'
3
3
  SimpleCov.start do
4
4
  add_filter '/spec/'
@@ -0,0 +1,10 @@
1
+ class DummyTransport
2
+ attr_accessor :block
3
+
4
+ def initialize(server, options={}, &block)
5
+ @block = block
6
+ end
7
+
8
+ def connect!
9
+ end
10
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubberband
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.9.0
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: 2012-02-17 00:00:00.000000000 Z
12
+ date: 2012-07-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: patron
16
- requirement: &16575640 !ruby/object:Gem::Requirement
15
+ name: faraday
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ~>
19
+ - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 0.4.12
21
+ version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *16575640
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
- name: yajl-ruby
27
- requirement: &16575000 !ruby/object:Gem::Requirement
31
+ name: multi_json
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,21 +37,31 @@ dependencies:
32
37
  version: '0'
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *16575000
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: rake
38
- requirement: &16574340 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
- - - ~>
51
+ - - ! '>='
42
52
  - !ruby/object:Gem::Version
43
- version: 0.9.2
53
+ version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *16574340
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: rspec
49
- requirement: &16573760 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ~>
@@ -54,21 +69,15 @@ dependencies:
54
69
  version: '2.0'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *16573760
58
- - !ruby/object:Gem::Dependency
59
- name: yard
60
- requirement: &16573180 !ruby/object:Gem::Requirement
72
+ version_requirements: !ruby/object:Gem::Requirement
61
73
  none: false
62
74
  requirements:
63
- - - ! '>='
75
+ - - ~>
64
76
  - !ruby/object:Gem::Version
65
- version: 0.7.0
66
- type: :development
67
- prerelease: false
68
- version_requirements: *16573180
77
+ version: '2.0'
69
78
  - !ruby/object:Gem::Dependency
70
79
  name: simplecov
71
- requirement: &16572580 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
72
81
  none: false
73
82
  requirements:
74
83
  - - ! '>='
@@ -76,10 +85,15 @@ dependencies:
76
85
  version: 0.3.8
77
86
  type: :development
78
87
  prerelease: false
79
- version_requirements: *16572580
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: 0.3.8
80
94
  - !ruby/object:Gem::Dependency
81
95
  name: mocha
82
- requirement: &16571980 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
83
97
  none: false
84
98
  requirements:
85
99
  - - ~>
@@ -87,7 +101,12 @@ dependencies:
87
101
  version: 0.9.0
88
102
  type: :development
89
103
  prerelease: false
90
- version_requirements: *16571980
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 0.9.0
91
110
  description: An ElasticSearch client with ThriftClient-like failover handling.
92
111
  email:
93
112
  - grantr@gmail.com
@@ -95,15 +114,16 @@ executables: []
95
114
  extensions: []
96
115
  extra_rdoc_files:
97
116
  - LICENSE
98
- - README.rdoc
117
+ - README.md
99
118
  files:
100
119
  - .autotest
101
120
  - .gitignore
102
121
  - .rspec
122
+ - .travis.yml
103
123
  - CONTRIBUTORS
104
124
  - Gemfile
105
125
  - LICENSE
106
- - README.rdoc
126
+ - README.md
107
127
  - Rakefile
108
128
  - TODO
109
129
  - lib/elasticsearch.rb
@@ -138,6 +158,7 @@ files:
138
158
  - spec/http_spec.rb
139
159
  - spec/index_spec.rb
140
160
  - spec/spec_helper.rb
161
+ - spec/support/dummy_transport.rb
141
162
  - spec/type_spec.rb
142
163
  - vendor/elasticsearch/elasticsearch.thrift
143
164
  homepage: http://github.com/grantr/rubberband
@@ -161,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
182
  version: '0'
162
183
  requirements: []
163
184
  rubyforge_project: rubberband
164
- rubygems_version: 1.8.11
185
+ rubygems_version: 1.8.23
165
186
  signing_key:
166
187
  specification_version: 3
167
188
  summary: An ElasticSearch client with ThriftClient-like failover handling.
@@ -173,5 +194,6 @@ test_files:
173
194
  - spec/http_spec.rb
174
195
  - spec/index_spec.rb
175
196
  - spec/spec_helper.rb
197
+ - spec/support/dummy_transport.rb
176
198
  - spec/type_spec.rb
177
199
  has_rdoc:
@@ -1,44 +0,0 @@
1
-
2
- = RubberBand
3
-
4
- An ElasticSearch client with ThriftClient-like failover handling.
5
-
6
- == License
7
-
8
- Copyright 2010-2011 Grant Rodgers. See included LICENSE file.
9
-
10
- == Features
11
-
12
- * Automatic failover, retry, and peer discovery
13
- * Support for multiple transports (HTTP, Thrift, Memcached TODO)
14
- * Support for multiple encodings (JSON (Yajl), Smile TODO)
15
-
16
- == Usage
17
-
18
- Instantiate a client:
19
-
20
- client = ElasticSearch.new('127.0.0.1:9200', :index => "twitter", :type => "tweet")
21
-
22
- Instantiate a client with multiple servers:
23
-
24
- client = ElasticSearch.new(['127.0.0.1:9200', '127.0.0.1:9201'])
25
-
26
- Instantiate a client using a Heroku URL (this sets the default index):
27
-
28
- client = ElasticSearch.new(ENV['ELASTICSEARCH_URL'])
29
-
30
- API:
31
-
32
- client.index({:body => "elasticsearch is cool"}, :id => 1)
33
- client.get("1")
34
- client.search("body:elasticsearch")
35
-
36
- == TODO
37
-
38
- See TODO file.
39
-
40
- == Contributing
41
-
42
- http://github.com/grantr/rubberband
43
-
44
- Fork, code, send pull request