antbird 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56a81ea3bc3c0562a4cd6ddc1f28ca6bc4f5c0410b1000a993de1fc08359dfdc
4
- data.tar.gz: 87dda0403daf7fb26da4300dc4c096b8ba0d927bfcd21e27b6d9792d57af98b9
3
+ metadata.gz: 2b134c730af7d5ff2f88b64158aba346bf92e412439de8501df3608bc52dba06
4
+ data.tar.gz: 75efcb9f9e87f3371ef48e793fbfd630a122213719e79c43d276cf48186ef69b
5
5
  SHA512:
6
- metadata.gz: 5159c0f56e0d2155cc9e6dc731757c3469e98d866bc57c5c651de42f322e6069740233cd1dd3930640f7cf910d2df9988fa18ecbd78c7bced8da344eedd33806
7
- data.tar.gz: 57255629436a0664cc68876e38f0c0219f372f45d41518422bc51a62328e0980bb91a48750fbe34355d7fea98416cbfd52c06f2f01f4da38f23ab6c7e9b114df
6
+ metadata.gz: 0d2b4cde70a9eefe2ca1e5776c6bb1743ec7c0a57d77bf8487fc3098f37499a12402597a18afd31b12d815bee7bedf08f808e3877aff490295a554b5365c904e
7
+ data.tar.gz: dea3a216fb467d5aa03be1ee51ad14f6955f4dfdc23653b122d574f373c94aabde8f31e385665ad15ba29aedbffc0e54205f55faac495fd0e29f9bc754a5c413
data/.rspec CHANGED
@@ -1,4 +1,3 @@
1
1
  --format progress
2
- --format Nc
3
2
  --color
4
3
  --require spec_helper
data/.travis.yml CHANGED
@@ -1,5 +1,19 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.5.0
4
+ - 2.5.1
5
+ env:
6
+ - ES_VERSION=6.2.4
7
+ - ES_VERSION=6.1.4
8
+ - ES_VERSION=5.6.9
9
+ - ES_VERSION=5.5.3
10
+
5
11
  before_install: gem install bundler -v 1.16.1
12
+ install:
13
+ - wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ES_VERSION}.tar.gz
14
+ - tar -xzf elasticsearch-${ES_VERSION}.tar.gz
15
+ - ./elasticsearch-${ES_VERSION}/bin/elasticsearch &
16
+ - bundle install
17
+ - wget --quiet --waitretry=1 --retry-connrefused --timeout=10 --output-document=- http://127.0.0.1:9200
18
+
19
+ script: bundle exec rspec
data/Guardfile CHANGED
@@ -1,4 +1,4 @@
1
- guard :rspec, cmd: "bundle exec rspec" do
1
+ guard :rspec, cmd: "bundle exec rspec --format progress --format Nc" do
2
2
  require "guard/rspec/dsl"
3
3
  dsl = Guard::RSpec::Dsl.new(self)
4
4
 
data/README.md CHANGED
@@ -33,7 +33,6 @@ client = Antbird::Client.new.scoped(index: 'test-index', type: 'test-type')
33
33
 
34
34
  client = Antbird::Client.new(
35
35
  url: 'http://localhost:9200',
36
- version: '6.2.3'
37
36
  scope: {
38
37
  index: 'test-index',
39
38
  type: 'test-type'
@@ -0,0 +1,22 @@
1
+ module Antbird
2
+ class Client
3
+ class Error < StandardError; end
4
+
5
+ class ApiError < Error
6
+ def initialize(response)
7
+ @response = response
8
+ @status = response.status
9
+
10
+ body = response.body
11
+ @error = body["error"] if body.is_a?(Hash) && body.key?("error")
12
+
13
+ message = @error || body.to_s
14
+ super message
15
+ end
16
+ attr_reader :response, :status
17
+ end
18
+
19
+ class ServerError < ApiError; end
20
+ class RequestError < ApiError; end
21
+ end
22
+ end
@@ -1,27 +1,26 @@
1
1
  require 'faraday'
2
2
  require 'faraday_middleware'
3
+ require 'antbird/client/errors'
3
4
 
4
5
  module Antbird
5
6
  class Client
6
- DEFAULT_VERSION = '6.2.3'
7
-
8
7
  def initialize(
9
8
  scope: {},
10
9
  url: "http://localhost:9200",
11
- version: DEFAULT_VERSION,
10
+ version: nil,
12
11
  read_timeout: 5,
13
- open_timeout: 2
14
- )
15
- @scope = scope.transform_keys(&:to_sym)
16
- @url = url
17
- @version = version
12
+ open_timeout: 2)
18
13
 
19
14
  @read_timeout = read_timeout
20
15
  @open_timeout = open_timeout
16
+ @url = url
17
+
18
+ @scope = scope.transform_keys(&:to_sym)
19
+ @version = version || fetch_version
21
20
 
22
21
  @api_specs = {}
23
22
 
24
- class_version = version.split('.')[0,2].join('_')
23
+ class_version = @version.split('.')[0,2].join('_')
25
24
 
26
25
  require "antbird/rest_api/rest_api_v#{class_version}"
27
26
  extend Antbird::RestApi.const_get "RestApiV#{class_version}"
@@ -41,6 +40,8 @@ module Antbird
41
40
  end
42
41
 
43
42
  def request(api_name, api_spec, params)
43
+ validate_params(api_spec, params)
44
+
44
45
  body = extract_body(params)
45
46
  scopes = extract_scopes(params)
46
47
 
@@ -85,23 +86,20 @@ module Antbird
85
86
  req.options[:timeout] = read_timeout if read_timeout
86
87
  end
87
88
  else
88
- raise ArgumentError, "unknown HTTP request method: #{method.inspect}"
89
+ raise ArgumentError, "Unknown HTTP request method: #{method.inspect}"
89
90
  end
90
91
 
91
92
  if method == :head
92
93
  case response.status
93
94
  when 200
94
- true
95
+ return true
95
96
  when 404
96
- false
97
- else
98
- raise 'error'
97
+ return false
99
98
  end
100
- else
101
- response.body
102
99
  end
103
100
 
104
- # TODO: handle errors
101
+ handle_errors!(response)
102
+ response.body
105
103
  end
106
104
 
107
105
  def extract_scopes(params)
@@ -148,5 +146,28 @@ module Antbird
148
146
  conn.adapter Faraday.default_adapter
149
147
  end
150
148
  end
149
+
150
+ private
151
+
152
+ def handle_errors!(response)
153
+ if response.status >= 500
154
+ raise ServerError, response
155
+ elsif response.body.is_a?(Hash) && response.body.key?("error")
156
+ raise RequestError, response
157
+ end
158
+ end
159
+
160
+ def validate_params(api_spec, params)
161
+ # TODO case: required parameter is missing
162
+ # TODO case: invalid parameter name
163
+ # TODO case: invalid parameter format
164
+ if api_spec.dig('body', 'required') && !params.key?(:body)
165
+ raise ArgumentError, 'Body is missing'
166
+ end
167
+ end
168
+
169
+ def fetch_version
170
+ connection.get('/').body.dig('version', 'number')
171
+ end
151
172
  end
152
173
  end
@@ -1,5 +1,5 @@
1
1
  # Generated REST API methods file - DO NOT EDIT!
2
- # Date: 2018-04-05
2
+ # Date: 2018-04-20
3
3
  # ES version: 5.5.3
4
4
 
5
5
  module Antbird
@@ -1,6 +1,6 @@
1
1
  # Generated REST API methods file - DO NOT EDIT!
2
- # Date: 2018-04-05
3
- # ES version: 5.6.8
2
+ # Date: 2018-04-20
3
+ # ES version: 5.6.9
4
4
 
5
5
  module Antbird
6
6
  module RestApi
@@ -1,5 +1,5 @@
1
1
  # Generated REST API methods file - DO NOT EDIT!
2
- # Date: 2018-04-05
2
+ # Date: 2018-04-20
3
3
  # ES version: 6.1.4
4
4
 
5
5
  module Antbird
@@ -1,6 +1,6 @@
1
1
  # Generated REST API methods file - DO NOT EDIT!
2
- # Date: 2018-04-05
3
- # ES version: 6.2.3
2
+ # Date: 2018-04-20
3
+ # ES version: 6.2.4
4
4
 
5
5
  module Antbird
6
6
  module RestApi
@@ -475,7 +475,7 @@ module Antbird
475
475
  # http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-forcemerge.html
476
476
  def indices_forcemerge(params = {})
477
477
  api_name = 'indices.forcemerge'
478
- api_spec = @api_specs[api_name] ||= {"documentation"=>"http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-forcemerge.html", "methods"=>["POST"], "url"=>{"path"=>"/_forcemerge", "paths"=>["/_forcemerge", "/{index}/_forcemerge"], "parts"=>{"index"=>{"type"=>"list", "description"=>"A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices"}}, "params"=>{"flush"=>{"type"=>"boolean", "description"=>"Specify whether the index should be flushed after performing the operation (default: true)"}, "ignore_unavailable"=>{"type"=>"boolean", "description"=>"Whether specified concrete indices should be ignored when unavailable (missing or closed)"}, "allow_no_indices"=>{"type"=>"boolean", "description"=>"Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)"}, "expand_wildcards"=>{"type"=>"enum", "options"=>["open", "closed", "none", "all"], "default"=>"open", "description"=>"Whether to expand wildcard expression to concrete indices that are open, closed or both."}, "max_num_segments"=>{"type"=>"number", "description"=>"The number of segments the index should be merged into (default: dynamic)"}, "only_expunge_deletes"=>{"type"=>"boolean", "description"=>"Specify whether the operation should only expunge deleted documents"}, "wait_for_merge"=>{"type"=>"boolean", "description"=>"Specify whether the request should block until the merge process is finished (default: true)"}}}, "body"=>nil}
478
+ api_spec = @api_specs[api_name] ||= {"documentation"=>"http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-forcemerge.html", "methods"=>["POST"], "url"=>{"path"=>"/_forcemerge", "paths"=>["/_forcemerge", "/{index}/_forcemerge"], "parts"=>{"index"=>{"type"=>"list", "description"=>"A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices"}}, "params"=>{"flush"=>{"type"=>"boolean", "description"=>"Specify whether the index should be flushed after performing the operation (default: true)"}, "ignore_unavailable"=>{"type"=>"boolean", "description"=>"Whether specified concrete indices should be ignored when unavailable (missing or closed)"}, "allow_no_indices"=>{"type"=>"boolean", "description"=>"Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)"}, "expand_wildcards"=>{"type"=>"enum", "options"=>["open", "closed", "none", "all"], "default"=>"open", "description"=>"Whether to expand wildcard expression to concrete indices that are open, closed or both."}, "max_num_segments"=>{"type"=>"number", "description"=>"The number of segments the index should be merged into (default: dynamic)"}, "only_expunge_deletes"=>{"type"=>"boolean", "description"=>"Specify whether the operation should only expunge deleted documents"}}}, "body"=>nil}
479
479
  request(api_name, api_spec, params)
480
480
  end
481
481
 
@@ -1,3 +1,3 @@
1
1
  module Antbird
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/antbird.rb CHANGED
@@ -1,2 +1,2 @@
1
- require "antbird/version"
1
+ require 'antbird/version'
2
2
  require 'antbird/client'
@@ -41,4 +41,8 @@ class ApiMethodsGenerator
41
41
  end
42
42
  end
43
43
 
44
- puts ApiMethodsGenerator.new(*ARGV).run
44
+ travis_yaml = YAML.load_file('.travis.yml')
45
+ versions = travis_yaml['env'].map { |v| v.scan(/ES_VERSION=([\d\.]+)/) }.flatten.uniq
46
+ versions.each do |version|
47
+ ApiMethodsGenerator.new(version).run
48
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: antbird
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - fukayatsu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-05 00:00:00.000000000 Z
11
+ date: 2018-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -157,6 +157,7 @@ files:
157
157
  - bin/setup
158
158
  - lib/antbird.rb
159
159
  - lib/antbird/client.rb
160
+ - lib/antbird/client/errors.rb
160
161
  - lib/antbird/rest_api/rest_api_v5_5.rb
161
162
  - lib/antbird/rest_api/rest_api_v5_6.rb
162
163
  - lib/antbird/rest_api/rest_api_v6_1.rb