eson-http 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/LICENSE.md +20 -0
  2. data/README.md +111 -0
  3. data/Rakefile +31 -0
  4. data/bin/elshell +20 -0
  5. data/eson-http.gemspec +28 -0
  6. data/lib/eson-http.rb +55 -0
  7. data/lib/eson/http.rb +16 -0
  8. data/lib/eson/http/api.rb +13 -0
  9. data/lib/eson/http/client.rb +24 -0
  10. data/lib/eson/http/cluster/health.rb +15 -0
  11. data/lib/eson/http/cluster/nodes.rb +14 -0
  12. data/lib/eson/http/cluster/shutdown.rb +15 -0
  13. data/lib/eson/http/cluster/state.rb +16 -0
  14. data/lib/eson/http/cluster/stats.rb +18 -0
  15. data/lib/eson/http/core/bulk.rb +33 -0
  16. data/lib/eson/http/core/count.rb +26 -0
  17. data/lib/eson/http/core/delete.rb +14 -0
  18. data/lib/eson/http/core/delete_by_query.rb +22 -0
  19. data/lib/eson/http/core/get.rb +15 -0
  20. data/lib/eson/http/core/index.rb +26 -0
  21. data/lib/eson/http/core/mget.rb +23 -0
  22. data/lib/eson/http/core/more_like_this.rb +14 -0
  23. data/lib/eson/http/core/msearch.rb +47 -0
  24. data/lib/eson/http/core/percolate.rb +16 -0
  25. data/lib/eson/http/core/search.rb +29 -0
  26. data/lib/eson/http/core/simple_search.rb +18 -0
  27. data/lib/eson/http/indices/aliases.rb +14 -0
  28. data/lib/eson/http/indices/analyze.rb +14 -0
  29. data/lib/eson/http/indices/clear_cache.rb +18 -0
  30. data/lib/eson/http/indices/close_index.rb +14 -0
  31. data/lib/eson/http/indices/create_index.rb +14 -0
  32. data/lib/eson/http/indices/delete_index.rb +14 -0
  33. data/lib/eson/http/indices/delete_mapping.rb +17 -0
  34. data/lib/eson/http/indices/delete_template.rb +14 -0
  35. data/lib/eson/http/indices/exists.rb +14 -0
  36. data/lib/eson/http/indices/flush.rb +18 -0
  37. data/lib/eson/http/indices/get_mapping.rb +20 -0
  38. data/lib/eson/http/indices/get_settings.rb +18 -0
  39. data/lib/eson/http/indices/get_template.rb +14 -0
  40. data/lib/eson/http/indices/open_index.rb +14 -0
  41. data/lib/eson/http/indices/optimize.rb +18 -0
  42. data/lib/eson/http/indices/put_mapping.rb +16 -0
  43. data/lib/eson/http/indices/put_template.rb +14 -0
  44. data/lib/eson/http/indices/refresh.rb +18 -0
  45. data/lib/eson/http/indices/segments.rb +18 -0
  46. data/lib/eson/http/indices/snapshot.rb +18 -0
  47. data/lib/eson/http/indices/stats.rb +18 -0
  48. data/lib/eson/http/indices/status.rb +18 -0
  49. data/lib/eson/http/indices/update_settings.rb +18 -0
  50. data/lib/eson/http/request.rb +95 -0
  51. data/lib/eson/modules/response_parser.rb +22 -0
  52. data/lib/eson/modules/status_handler.rb +24 -0
  53. data/log4j.properties +18 -0
  54. data/test/http/client_test.rb +14 -0
  55. data/test/http/cluster_test.rb +58 -0
  56. data/test/http/index_test.rb +180 -0
  57. data/test/http/indices/basics_test.rb +257 -0
  58. data/test/http/query_test.rb +70 -0
  59. data/test/modules/query_plugin_test.rb +40 -0
  60. data/test/seeds/seeds.rb +30 -0
  61. data/test/test_config.rb +33 -0
  62. metadata +202 -0
@@ -0,0 +1,26 @@
1
+ module Eson
2
+ module HTTP
3
+ module Count
4
+ include Shared::Search
5
+ extend API
6
+
7
+ request_method :post
8
+
9
+ def bare_path
10
+ unless types.empty?
11
+ path = "{-list|,|indices}/{-list|,|types}/"
12
+ else
13
+ path = "{-list|,|indices}/"
14
+ end
15
+ end
16
+
17
+ def path
18
+ path = bare_path + "_count"
19
+ end
20
+
21
+ def source
22
+ MultiJson.encode(query)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,14 @@
1
+ module Eson
2
+ module HTTP
3
+ module Delete
4
+ include Shared::Delete
5
+ extend API
6
+
7
+ request_method :delete
8
+
9
+ def path
10
+ "/{index}/{type}/{id}"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,22 @@
1
+ module Eson
2
+ module HTTP
3
+ module DeleteByQuery
4
+ extend API
5
+ include Shared::DeleteByQuery
6
+
7
+ request_method :delete
8
+
9
+ def bare_path
10
+ unless types.empty?
11
+ path = "{-list|,|indices}/{-list|,|types}/"
12
+ else
13
+ path = "{-list|,|indices}/"
14
+ end
15
+ end
16
+
17
+ def path
18
+ bare_path + "_query"
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,15 @@
1
+ module Eson
2
+ module HTTP
3
+ module Get
4
+ include Shared::Get
5
+ extend API
6
+
7
+ request_method :get
8
+
9
+ def path
10
+ "{index}/{type}/{id}"
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,26 @@
1
+ module Eson
2
+ module HTTP
3
+ module Index
4
+ include Shared::Index
5
+ extend API
6
+
7
+ request_method :put
8
+
9
+ def path
10
+ if id
11
+ "/{index}/{type}/{id}"
12
+ else
13
+ "/{index}/{type}"
14
+ end
15
+ end
16
+
17
+ def request_method
18
+ if id
19
+ :put
20
+ else
21
+ :post
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,23 @@
1
+ module Eson
2
+ module HTTP
3
+ module MultiGet
4
+ include Shared::MultiGet
5
+ extend API
6
+
7
+ request_method :get
8
+
9
+ def bare_path
10
+ unless type
11
+ path = "{index}/{type}/"
12
+ else
13
+ path = "{index}/"
14
+ end
15
+ end
16
+
17
+ def path
18
+ path = bare_path + "_mget"
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,14 @@
1
+ module Eson
2
+ module HTTP
3
+ module MoreLikeThis
4
+ include Shared::MoreLikeThis
5
+ extend API
6
+
7
+ request_method :get
8
+
9
+ def path
10
+ "{index}/{type}/{id}/_mlt"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,47 @@
1
+ module Eson
2
+ module HTTP
3
+ module MultiSearch
4
+ include Shared::MultiSearch
5
+ extend API
6
+
7
+ request_method :post
8
+
9
+ def path
10
+ '/_msearch'
11
+ end
12
+
13
+ def source
14
+ msearch.map {|r| serialize_request(r)}.join
15
+ end
16
+
17
+ def serialize_request(request)
18
+ case request
19
+ when Eson::HTTP::Search
20
+ MultiJson.encode(to_params_hash(request)) << "\n" << request.source << "\n"
21
+ else
22
+ warn("Unserializable request #{request.inspect}")
23
+ end
24
+ end
25
+
26
+ def to_params_hash(r)
27
+ r.url_params.inject({}) do |h, p|
28
+ val = r.send(p)
29
+ if val
30
+ h[p] = val unless val.respond_to?(:empty?) && val.empty?
31
+ end
32
+ h
33
+ end
34
+ end
35
+
36
+ def path
37
+ unless types.empty?
38
+ path = "{-list|,|indices}/{-list|,|types}/"
39
+ else
40
+ path = "{-list|,|indices}/"
41
+ end
42
+
43
+ path << "_msearch"
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,16 @@
1
+ module Eson
2
+ module HTTP
3
+ module Percolate
4
+ include Shared::Percolate
5
+ extend API
6
+
7
+ def path
8
+ '/{index}/{type}/_percolate'
9
+ end
10
+
11
+ def request_method
12
+ :post
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,29 @@
1
+ module Eson
2
+ module HTTP
3
+ module Search
4
+ include Shared::Search
5
+ extend API
6
+
7
+ request_method :post
8
+
9
+ def bare_path
10
+ unless types.empty?
11
+ path = "{-list|,|indices}/{-list|,|types}/"
12
+ else
13
+ path = "{-list|,|indices}/"
14
+ end
15
+ end
16
+
17
+ def path
18
+ path = bare_path + "_search"
19
+
20
+ if scroll
21
+ path << "/scroll"
22
+ end
23
+
24
+ path
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,18 @@
1
+ module Eson
2
+ module HTTP
3
+ module SimpleSearch
4
+ include Shared::SimpleSearch
5
+ extend API
6
+
7
+ request_method :get
8
+
9
+ def path
10
+ unless types.empty?
11
+ "{-list|,|indices}/{-list|,|types}/_search"
12
+ else
13
+ "{-list|,|indices}/_search"
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ module Eson
2
+ module HTTP
3
+ module Aliases
4
+ include Shared::Aliases
5
+ extend API
6
+
7
+ request_method :post
8
+
9
+ def path
10
+ '/_aliases'
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module Eson
2
+ module HTTP
3
+ module Analyze
4
+ include Shared::Analyze
5
+ extend API
6
+
7
+ request_method :put
8
+
9
+ def path
10
+ '/{index}/_analyze'
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ module Eson
2
+ module HTTP
3
+ module ClearCache
4
+ include Shared::ClearCache
5
+ extend API
6
+
7
+ request_method :post
8
+
9
+ def path
10
+ if index
11
+ "/{-list|,|indices}/_cache/clear"
12
+ else
13
+ "/_cache/clear"
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ module Eson
2
+ module HTTP
3
+ module CloseIndex
4
+ include Shared::CloseIndex
5
+ extend API
6
+
7
+ request_method :post
8
+
9
+ def path
10
+ "/{-list|,|indices}/_close"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module Eson
2
+ module HTTP
3
+ module CreateIndex
4
+ include Shared::CreateIndex
5
+ extend API
6
+
7
+ request_method :put
8
+
9
+ def path
10
+ '/{index}'
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module Eson
2
+ module HTTP
3
+ module DeleteIndex
4
+ include Shared::DeleteIndex
5
+ extend API
6
+
7
+ request_method :delete
8
+
9
+ def path
10
+ "/{-list|,|indices}"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ module Eson
2
+ module HTTP
3
+ module DeleteMapping
4
+ include Shared::DeleteMapping
5
+ extend API
6
+
7
+ request_method :delete
8
+
9
+
10
+ def path
11
+ if type && !indices.empty?
12
+ "/{-list|,|indices}/{type}"
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,14 @@
1
+ module Eson
2
+ module HTTP
3
+ module DeleteTemplate
4
+ include Shared::DeleteTemplate
5
+ extend API
6
+
7
+ request_method :delete
8
+
9
+ def path
10
+ "/_template/{name}"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module Eson
2
+ module HTTP
3
+ module IndexExists
4
+ include Shared::IndexExists
5
+ extend API
6
+
7
+ request_method :head
8
+
9
+ def path
10
+ "/{-list|,|indices}"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ module Eson
2
+ module HTTP
3
+ module Flush
4
+ include Shared::Flush
5
+ extend API
6
+
7
+ request_method :post
8
+
9
+ def path
10
+ unless indices.empty?
11
+ "/{-list|,|indices}/_flush"
12
+ else
13
+ "/_flush"
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ module Eson
2
+ module HTTP
3
+ module GetMapping
4
+ include Shared::GetMapping
5
+ extend API
6
+
7
+ request_method :get
8
+
9
+ def path
10
+ if !types.empty? && !indices.empty?
11
+ "/{-list|,|indices}/{-list|,|types}/_mapping"
12
+ elsif !indices.empty?
13
+ "/{-list|,|indices}/_mapping"
14
+ else
15
+ "/_mapping"
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end