embulk-input-redash 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d1d42839e0f5cf37c46e861248891cb07c0e8570
4
+ data.tar.gz: 79aa8f785f59ebcb2da89399e4187e95b7f54565
5
+ SHA512:
6
+ metadata.gz: a65dd5913911bc6641cf0347be0181db291726dec4d3ca2db2845bda35889d1eab056f0a9e98e5155e9e0f07673c97fe991e4b54692644648837793462d04f75
7
+ data.tar.gz: 8344f3104c2ed9535369fbc20f226dbaa03e3f761c405e55e3fd91c26d21d17e5dc403485672c72d57a7b6dc29ed6b944360c91b20e35b40eb233b4e00bce473
@@ -0,0 +1,5 @@
1
+ *~
2
+ /pkg/
3
+ /tmp/
4
+ /.bundle/
5
+ /Gemfile.lock
@@ -0,0 +1 @@
1
+ jruby-9.1.5.0
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org/'
2
+ gemspec
@@ -0,0 +1,21 @@
1
+
2
+ MIT License
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,30 @@
1
+ # Redash input plugin for Embulk
2
+
3
+ embulk-input-redash is the Embulk input plugin for [Redash](https://redash.io).
4
+
5
+ ## Overview
6
+
7
+ * **Plugin type**: input
8
+ * **Resume supported**: yes
9
+ * **Cleanup supported**: yes
10
+ * **Guess supported**: yes
11
+
12
+ ## Configuration
13
+
14
+ - **url**: description (string, required)
15
+ - **api_key**: description (string, required)
16
+
17
+ ## Example
18
+
19
+ ```yaml
20
+ in:
21
+ type: redash
22
+ url: https://localhost:5000/api/queries/1234/results.json
23
+ api_key: YOUR_REDASH_API_KEY
24
+ ```
25
+
26
+ ## Build
27
+
28
+ ```
29
+ $ rake
30
+ ```
@@ -0,0 +1,3 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task default: :build
@@ -0,0 +1,20 @@
1
+
2
+ Gem::Specification.new do |spec|
3
+ spec.name = "embulk-input-redash"
4
+ spec.version = "0.1.0"
5
+ spec.authors = ["ariarijp"]
6
+ spec.summary = "Redash input plugin for Embulk"
7
+ spec.description = "Loads records from Redash."
8
+ spec.email = ["takuya.arita@gmail.com"]
9
+ spec.licenses = ["MIT"]
10
+ spec.homepage = "https://github.com/ariarijp/embulk-input-redash"
11
+
12
+ spec.files = `git ls-files`.split("\n") + Dir["classpath/*.jar"]
13
+ spec.test_files = spec.files.grep(%r{^(test|spec)/})
14
+ spec.require_paths = ["lib"]
15
+
16
+ spec.add_dependency 'rest-client'
17
+ spec.add_development_dependency 'embulk', ['>= 0.8.17']
18
+ spec.add_development_dependency 'bundler', ['>= 1.10.6']
19
+ spec.add_development_dependency 'rake', ['>= 10.0']
20
+ end
@@ -0,0 +1,8 @@
1
+ require 'embulk/input/redash/plugin'
2
+
3
+ module Embulk
4
+ module Input
5
+ module Redash
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,72 @@
1
+ require 'rest-client'
2
+
3
+ module Embulk
4
+ module Input
5
+ module Redash
6
+ class Plugin < InputPlugin
7
+ ::Embulk::Plugin.register_input('redash', self)
8
+
9
+ def self.transaction(config, &control)
10
+ task = {
11
+ 'url' => config.param('url', :string),
12
+ 'api_key' => config.param('api_key', :string)
13
+ }
14
+
15
+ columns = embulk_columns(config)
16
+
17
+ resume(task, columns, 1, &control)
18
+ end
19
+
20
+ def self.resume(task, columns, count)
21
+ task_reports = yield(task, columns, count)
22
+
23
+ next_config_diff = {}
24
+ next_config_diff
25
+ end
26
+
27
+ def self.guess(_config)
28
+ sample_records = get_rows(_config['url'], _config['api_key']).first(10)
29
+ columns = Guess::SchemaGuess.from_hash_records(sample_records)
30
+ { 'columns' => columns }
31
+ end
32
+
33
+ def init
34
+ @url = task['url']
35
+ @api_key = task['api_key']
36
+ end
37
+
38
+ def run
39
+ column_names = @schema.map(&:name)
40
+
41
+ Plugin.get_rows(@url, @api_key).each do |row|
42
+ page_builder.add(row.values_at(*column_names))
43
+ end
44
+
45
+ page_builder.finish
46
+
47
+ task_report = {}
48
+
49
+ task_report
50
+ end
51
+
52
+ def self.embulk_columns(config)
53
+ config.param(:columns, :array).map do |column|
54
+ name = column['name']
55
+ type = column['type'].to_sym
56
+
57
+ Column.new(nil, name, type, column['format'])
58
+ end
59
+ end
60
+
61
+ private
62
+
63
+ def self.get_rows(url, api_key)
64
+ res = RestClient.get(url, params: { 'api_key' => api_key })
65
+ data = JSON.parse(res.body)
66
+
67
+ data['query_result']['data']['rows']
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: embulk-input-redash
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ariarijp
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: embulk
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.8.17
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.8.17
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 1.10.6
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 1.10.6
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: Loads records from Redash.
70
+ email:
71
+ - takuya.arita@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".ruby-version"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - embulk-input-redash.gemspec
83
+ - lib/embulk/input/redash.rb
84
+ - lib/embulk/input/redash/plugin.rb
85
+ homepage: https://github.com/ariarijp/embulk-input-redash
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.6.8
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: Redash input plugin for Embulk
109
+ test_files: []