elastomer-client 3.0.1 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +4 -0
  4. data/lib/elastomer/client/bulk.rb +1 -1
  5. data/lib/elastomer/client/cluster.rb +10 -22
  6. data/lib/elastomer/client/docs.rb +46 -55
  7. data/lib/elastomer/client/index.rb +33 -33
  8. data/lib/elastomer/client/multi_percolate.rb +9 -9
  9. data/lib/elastomer/client/multi_search.rb +5 -5
  10. data/lib/elastomer/client/native_delete_by_query.rb +2 -22
  11. data/lib/elastomer/client/nodes.rb +8 -22
  12. data/lib/elastomer/client/percolator.rb +5 -5
  13. data/lib/elastomer/client/repository.rb +7 -7
  14. data/lib/elastomer/client/rest_api_spec/api_spec.rb +119 -0
  15. data/lib/elastomer/client/rest_api_spec/api_spec_v2_3.rb +2232 -0
  16. data/lib/elastomer/client/rest_api_spec/api_spec_v2_4.rb +2250 -0
  17. data/lib/elastomer/client/rest_api_spec/api_spec_v5_6.rb +2491 -0
  18. data/lib/elastomer/client/rest_api_spec/rest_api.rb +59 -0
  19. data/lib/elastomer/client/rest_api_spec.rb +44 -0
  20. data/lib/elastomer/client/scroller.rb +10 -10
  21. data/lib/elastomer/client/snapshot.rb +7 -7
  22. data/lib/elastomer/client/tasks.rb +45 -51
  23. data/lib/elastomer/client/template.rb +8 -8
  24. data/lib/elastomer/client/warmer.rb +11 -4
  25. data/lib/elastomer/client.rb +31 -7
  26. data/lib/elastomer/version.rb +1 -1
  27. data/lib/elastomer/version_support.rb +35 -46
  28. data/script/generate-rest-api-spec +152 -0
  29. data/test/client/rest_api_spec/api_spec_test.rb +55 -0
  30. data/test/client/rest_api_spec/rest_api_test.rb +96 -0
  31. data/test/client/stubbed_client_test.rb +1 -19
  32. data/test/middleware/opaque_id_test.rb +1 -3
  33. data/test/notifications_test.rb +0 -5
  34. data/test/test_helper.rb +5 -4
  35. data/test/version_support_test.rb +3 -21
  36. metadata +13 -2
@@ -0,0 +1,119 @@
1
+
2
+ module Elastomer::Client::RestApiSpec
3
+
4
+ # This is the superclass for the version specific API Spec classes that will
5
+ # be generated using the `script/generate-rest-api-spec` script. Each version
6
+ # of Elasticsarch we support will have it's own ApiSpec class that will
7
+ # validate the API request aprams for that particular version.
8
+ class ApiSpec
9
+
10
+ attr_reader :rest_apis
11
+ attr_reader :common_params
12
+
13
+ def initialize
14
+ @rest_apis ||= {}
15
+ @common_params ||= {}
16
+ @common_params_set = Set.new(@common_params.keys)
17
+ end
18
+
19
+ # Given an API descriptor name and a set of request parameters, select those
20
+ # params that are accepted by the API endpoint.
21
+ #
22
+ # api - the api descriptor name as a String
23
+ # from - the Hash containing the request params
24
+ #
25
+ # Returns a new Hash containing the valid params for the api
26
+ def select_params(api:, from:)
27
+ rest_api = get(api)
28
+ return from if rest_api.nil?
29
+ rest_api.select_params(from: from)
30
+ end
31
+
32
+ # Given an API descriptor name and a single request parameter, returns
33
+ # `true` if the parameter is valid for the given API. This method always
34
+ # returns `true` if the API is unknown.
35
+ #
36
+ # api - the api descriptor name as a String
37
+ # param - the request parameter name as a String
38
+ #
39
+ # Returns `true` if the param is valid for the API.
40
+ def valid_param?(api:, param:)
41
+ rest_api = get(api)
42
+ return true if rest_api.nil?
43
+ rest_api.valid_param?(param)
44
+ end
45
+
46
+ # Given an API descriptor name and a set of request path parts, select those
47
+ # parts that are accepted by the API endpoint.
48
+ #
49
+ # api - the api descriptor name as a String
50
+ # from - the Hash containing the path parts
51
+ #
52
+ # Returns a new Hash containing the valid path parts for the api
53
+ def select_parts(api:, from:)
54
+ rest_api = get(api)
55
+ return from if rest_api.nil?
56
+ rest_api.select_parts(from: from)
57
+ end
58
+
59
+ # Given an API descriptor name and a single path part, returns `true` if the
60
+ # path part is valid for the given API. This method always returns `true` if
61
+ # the API is unknown.
62
+ #
63
+ # api - the api descriptor name as a String
64
+ # part - the path part name as a String
65
+ #
66
+ # Returns `true` if the path part is valid for the API.
67
+ def valid_part?(api:, part:)
68
+ rest_api = get(api)
69
+ return true if rest_api.nil?
70
+ rest_api.valid_part?(part)
71
+ end
72
+
73
+ # Select the common request parameters from the given params.
74
+ #
75
+ # from - the Hash containing the request params
76
+ #
77
+ # Returns a new Hash containing the valid common request params
78
+ def select_common_params(from:)
79
+ return from if @common_params.empty?
80
+ from.select {|k,v| valid_common_param?(k)}
81
+ end
82
+
83
+ # Returns `true` if the param is a common request parameter.
84
+ def valid_common_param?(param)
85
+ @common_params_set.include?(param.to_s)
86
+ end
87
+
88
+ # Given an API descriptor name and a set of request parameters, ensure that
89
+ # all the request parameters are valid for the API endpoint. If an invalid
90
+ # parameter is found then an IllegalArgument exception is raised.
91
+ #
92
+ # api - the api descriptor name as a String
93
+ # from - the Hash containing the request params
94
+ #
95
+ # Returns the params unmodified
96
+ # Raises an IllegalArgument exception if an invalid parameter is found.
97
+ def validate_params!(api:, params:)
98
+ rest_api = get(api)
99
+ return params if rest_api.nil?
100
+
101
+ params.keys.each do |key|
102
+ unless rest_api.valid_param?(key) || valid_common_param?(key)
103
+ raise ::Elastomer::Client::IllegalArgument, "'#{key}' is not a valid parameter for the '#{api}' API"
104
+ end
105
+ end
106
+ params
107
+ end
108
+
109
+ # Internal: Retrieve the `RestApi` descriptor for the given named `api`. If
110
+ # an unkonwn `api` is passed in, then `nil` is returned.
111
+ #
112
+ # api - the api descriptor name as a String
113
+ #
114
+ # Returns a RestApi instance or nil.
115
+ def get(api)
116
+ rest_apis[api]
117
+ end
118
+ end
119
+ end