antbird 0.0.7 → 0.2.0

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.
@@ -1,48 +0,0 @@
1
- #!/usr/bin/env bundle exec ruby
2
-
3
- require 'octokit'
4
- require 'base64'
5
- require 'json'
6
- require 'yaml'
7
- require 'erb'
8
-
9
- class ApiMethodsGenerator
10
- def initialize(version = '6.2.3')
11
- @version = version
12
-
13
- sliced = @version.split(".").slice(0,2)
14
- @short_version = sliced.join(".")
15
- @class_version = sliced.join("_")
16
- end
17
- attr_reader :version, :short_version, :class_version
18
-
19
- def run
20
- api_spec = fetch_api_spec("v#{version}")
21
- File.open("lib/antbird/rest_api/rest_api_v#{class_version}.rb", "w") do |f|
22
- f.puts ERB.new(File.read('script/rest_api_template.erb'), 0, "<>").result(binding)
23
- end
24
- end
25
-
26
- def fetch_api_spec(ref)
27
- cache_file = "tmp/api_spec_#{ref}.yml"
28
- return YAML.load_file(cache_file) if File.exists?(cache_file)
29
-
30
- client = Octokit::Client.new(access_token: ENV['GITHUB_TOKEN'])
31
- files = client.contents('elastic/elasticsearch', path: 'rest-api-spec/src/main/resources/rest-api-spec/api', query: {ref: ref})
32
- api_spec = {}
33
- files.each do |f|
34
- puts f.url
35
- file = client.content('elastic/elasticsearch', path: f.path, query: { ref: ref })
36
- api_spec[File.basename(file.name)] = JSON.parse(Base64.decode64(file.content))
37
- end
38
-
39
- File.open(cache_file, 'w') { |f| f.write(api_spec.to_yaml) }
40
- api_spec
41
- end
42
- end
43
-
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
@@ -1,29 +0,0 @@
1
- # Generated REST API methods file - DO NOT EDIT!
2
- # Date: <%= Time.now.strftime("%Y-%m-%d") %>
3
- # ES version: <%= version %>
4
-
5
- module Antbird
6
- module RestApi
7
- module RestApiV<%= class_version %>
8
- def common_params
9
- @common_params ||= <%= api_spec['_common.json'] || {} %>
10
- end
11
- <% api_spec.each do |file_name, file_content| %>
12
- <% next if file_name == '_common.json' %>
13
- <% file_content.each do |api_name, api_spec| %>
14
-
15
- # <%= api_name %> <%= api_spec['methods'] %>
16
- # <%= api_spec['documentation'] %>
17
- def <%= api_name.tr('.', '_') %>(params = {})
18
- api_name = '<%= api_name %>'
19
- api_spec = @api_specs[api_name] ||= <%= api_spec %>
20
- request(api_name, api_spec, params)
21
- end
22
- <% if api_spec['methods'] == ['HEAD'] %>
23
- alias :<%= api_name.tr('.', '_') %>? :<%= api_name.tr('.', '_') %>
24
- <% end %>
25
- <% end # file_content.each %>
26
- <% end # api_spec.each %>
27
- end
28
- end
29
- end