metabase 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9cd5497b17c4b5f26ff1ca073954a7eceaeb791dc2c78e946ae00be1911004ad
4
+ data.tar.gz: 4c0f63527ff65f63c2a51ebec23b99d2b7ce2cdf42eb8023f7c1503efdf51b31
5
+ SHA512:
6
+ metadata.gz: 28d3439dd61deb965936693503df407ec3e7c80232cfd881b29862323bb4442daecc32a201c7bea1dc3572b1916737c294a01a359e7adb678db50ea6adbbb45a
7
+ data.tar.gz: 539344d952ff67c4c2bcc7be1f7cbede918f4cb245c56e7e2ee978d49b9c6dd74f0cff828edc241b981e5213ef8792ab28da6089f5a4406f2d16a758728719f4
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /vendor/bundle/
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,17 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
3
+
4
+ Style/Documentation:
5
+ Enabled: false
6
+
7
+ Metrics/BlockLength:
8
+ Exclude:
9
+ - spec/**/*.rb
10
+ - '*.gemspec'
11
+
12
+ Metrics/CyclomaticComplexity:
13
+ Exclude:
14
+ - lib/metabase/error.rb
15
+
16
+ Metrics/MethodLength:
17
+ Max: 20
@@ -0,0 +1,18 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.5
4
+ - 2.4
5
+ - 2.3
6
+
7
+ script:
8
+ - bundle exec rubocop
9
+ - bundle exec rake spec
10
+
11
+ cache: bundler
12
+
13
+ branches:
14
+ only:
15
+ - master
16
+
17
+ notifications:
18
+ email: false
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ gemspec
@@ -0,0 +1,90 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ metabase (0.2.0)
5
+ faraday (~> 0.8)
6
+ faraday_middleware
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.5.2)
12
+ public_suffix (>= 2.0.2, < 4.0)
13
+ ast (2.4.0)
14
+ awesome_print (1.8.0)
15
+ coderay (1.1.2)
16
+ crack (0.4.3)
17
+ safe_yaml (~> 1.0.0)
18
+ diff-lcs (1.3)
19
+ docile (1.3.1)
20
+ faraday (0.15.2)
21
+ multipart-post (>= 1.2, < 3)
22
+ faraday_middleware (0.12.2)
23
+ faraday (>= 0.7.4, < 1.0)
24
+ hashdiff (0.3.7)
25
+ json (2.1.0)
26
+ method_source (0.9.0)
27
+ multipart-post (2.0.0)
28
+ parallel (1.12.1)
29
+ parser (2.5.1.0)
30
+ ast (~> 2.4.0)
31
+ powerpack (0.1.1)
32
+ pry (0.11.3)
33
+ coderay (~> 1.1.0)
34
+ method_source (~> 0.9.0)
35
+ public_suffix (3.0.2)
36
+ rainbow (3.0.0)
37
+ rake (12.3.1)
38
+ rspec (3.7.0)
39
+ rspec-core (~> 3.7.0)
40
+ rspec-expectations (~> 3.7.0)
41
+ rspec-mocks (~> 3.7.0)
42
+ rspec-core (3.7.1)
43
+ rspec-support (~> 3.7.0)
44
+ rspec-expectations (3.7.0)
45
+ diff-lcs (>= 1.2.0, < 2.0)
46
+ rspec-support (~> 3.7.0)
47
+ rspec-mocks (3.7.0)
48
+ diff-lcs (>= 1.2.0, < 2.0)
49
+ rspec-support (~> 3.7.0)
50
+ rspec-support (3.7.1)
51
+ rubocop (0.56.0)
52
+ parallel (~> 1.10)
53
+ parser (>= 2.5)
54
+ powerpack (~> 0.1)
55
+ rainbow (>= 2.2.2, < 4.0)
56
+ ruby-progressbar (~> 1.7)
57
+ unicode-display_width (~> 1.0, >= 1.0.1)
58
+ ruby-progressbar (1.9.0)
59
+ safe_yaml (1.0.4)
60
+ simplecov (0.16.1)
61
+ docile (~> 1.1)
62
+ json (>= 1.8, < 3)
63
+ simplecov-html (~> 0.10.0)
64
+ simplecov-html (0.10.2)
65
+ unicode-display_width (1.3.2)
66
+ vcr (4.0.0)
67
+ webmock (3.4.1)
68
+ addressable (>= 2.3.6)
69
+ crack (>= 0.3.2)
70
+ hashdiff
71
+ yard (0.9.12)
72
+
73
+ PLATFORMS
74
+ ruby
75
+
76
+ DEPENDENCIES
77
+ awesome_print
78
+ bundler
79
+ metabase!
80
+ pry
81
+ rake
82
+ rspec
83
+ rubocop
84
+ simplecov
85
+ vcr
86
+ webmock
87
+ yard
88
+
89
+ BUNDLED WITH
90
+ 1.16.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Hiroshi Shimoju
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,82 @@
1
+ # Metabase Ruby Client
2
+
3
+ Ruby client library for Metabase API
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'metabase'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```
22
+ $ gem install metabase
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ### Authentication
28
+
29
+ ```ruby
30
+ client = Metabase::Client.new(
31
+ url: 'https://example.com',
32
+ username: 'mb@example.com',
33
+ password: 'p@ssw0rd'
34
+ )
35
+
36
+ # Authenticate
37
+ client.login
38
+
39
+ # Fetch the current user
40
+ client.current_user
41
+ ```
42
+
43
+ Or specify valid session token:
44
+
45
+ ```ruby
46
+ client = Metabase::Client.new(
47
+ url: 'https://example.com',
48
+ token: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
49
+ )
50
+
51
+ client.current_user
52
+ ```
53
+
54
+ ### Query results
55
+
56
+ ```ruby
57
+ # Fetch query results of the card
58
+ card_id = 1
59
+ client.query_card(card_id)
60
+
61
+ # Specify export format (csv, json, xlsx)
62
+ client.query_card(card_id, format: :csv)
63
+
64
+ # Fetch query results of the public card
65
+ card_uuid = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
66
+ client.query_public_card(card_uuid)
67
+ client.query_public_card(card_uuid, format: :csv)
68
+ ```
69
+
70
+ ## Development
71
+
72
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
73
+
74
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
75
+
76
+ ## Contributing
77
+
78
+ Bug reports and pull requests are welcome on GitHub at https://github.com/shimoju/metabase-ruby.
79
+
80
+ ## License
81
+
82
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'metabase'
6
+ require 'pry'
7
+
8
+ Pry.start
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -0,0 +1,29 @@
1
+ version: '3'
2
+ services:
3
+ metabase:
4
+ image: metabase/metabase:v0.29.3
5
+ environment:
6
+ MB_DB_TYPE: postgres
7
+ MB_DB_DBNAME: metabase
8
+ MB_DB_PORT: 5432
9
+ MB_DB_USER: postgres
10
+ MB_DB_PASS: NOmEh1tcxKojeDAY6bV5icFpuhEp0xUkhykvynNTPc7bTiOKIyjk2O3IYmEmvfIK
11
+ MB_DB_HOST: db
12
+ MB_PASSWORD_COMPLEXITY: normal
13
+ MB_PASSWORD_LENGTH: 8
14
+ MB_ENCRYPTION_SECRET_KEY: JjN8BPWVlGoDTtifSbgP12GC8wsVUQni3nocbhiCsEgIldsmGNn6yRrqZDMJSQxO
15
+ ports:
16
+ - 3030:3000
17
+ depends_on:
18
+ - db
19
+
20
+ db:
21
+ image: postgres:10-alpine
22
+ environment:
23
+ POSTGRES_DB: metabase
24
+ POSTGRES_PASSWORD: NOmEh1tcxKojeDAY6bV5icFpuhEp0xUkhykvynNTPc7bTiOKIyjk2O3IYmEmvfIK
25
+ volumes:
26
+ - postgres:/var/lib/postgresql/data
27
+
28
+ volumes:
29
+ postgres:
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'metabase/version'
4
+ require 'metabase/client'
5
+
6
+ module Metabase
7
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'metabase/connection'
4
+ require 'metabase/endpoint'
5
+
6
+ module Metabase
7
+ class Client
8
+ include Connection
9
+ include Endpoint
10
+
11
+ def initialize(url:, username: nil, password: nil, token: nil)
12
+ @url = url
13
+ @username = username
14
+ @password = password
15
+ @token = token
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'faraday_middleware'
5
+ require 'metabase/error'
6
+
7
+ module Metabase
8
+ module Connection
9
+ def get(path, **params)
10
+ request(:get, path, params)
11
+ end
12
+
13
+ def post(path, **params)
14
+ request(:post, path, params)
15
+ end
16
+
17
+ def put(path, **params)
18
+ request(:put, path, params)
19
+ end
20
+
21
+ def delete(path, **params)
22
+ request(:delete, path, params)
23
+ end
24
+
25
+ def head(path, **params)
26
+ request(:head, path, params)
27
+ end
28
+
29
+ private
30
+
31
+ def request(method, path, params)
32
+ response = connection.public_send(method, path, params) do |request|
33
+ request.headers['X-Metabase-Session'] = @token if @token
34
+ end
35
+
36
+ error = Error.from_response(response)
37
+ raise error if error
38
+ response.body
39
+ end
40
+
41
+ def connection
42
+ @connection ||= Faraday.new(url: @url) do |c|
43
+ c.request :json
44
+ c.response :json, content_type: /\bjson$/
45
+ c.adapter Faraday.default_adapter
46
+ c.headers['User-Agent'] =
47
+ "MetabaseRuby/#{VERSION} (#{RUBY_ENGINE}#{RUBY_VERSION})"
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'metabase/endpoint/activity'
4
+ require 'metabase/endpoint/alert'
5
+ require 'metabase/endpoint/async'
6
+ require 'metabase/endpoint/card'
7
+ require 'metabase/endpoint/collection'
8
+ require 'metabase/endpoint/dashboard'
9
+ require 'metabase/endpoint/database'
10
+ require 'metabase/endpoint/metric'
11
+ require 'metabase/endpoint/permissions'
12
+ require 'metabase/endpoint/public'
13
+ require 'metabase/endpoint/pulse'
14
+ require 'metabase/endpoint/revision'
15
+ require 'metabase/endpoint/segment'
16
+ require 'metabase/endpoint/session'
17
+ require 'metabase/endpoint/setting'
18
+ require 'metabase/endpoint/setup'
19
+ require 'metabase/endpoint/table'
20
+ require 'metabase/endpoint/user'
21
+ require 'metabase/endpoint/util'
22
+ require 'metabase/endpoint/x_ray'
23
+
24
+ module Metabase
25
+ module Endpoint
26
+ include Activity
27
+ include Alert
28
+ include Async
29
+ include Card
30
+ include Collection
31
+ include Dashboard
32
+ include Database
33
+ include Metric
34
+ include Permissions
35
+ include Public
36
+ include Pulse
37
+ include Revision
38
+ include Segment
39
+ include Session
40
+ include Setting
41
+ include Setup
42
+ include Table
43
+ include User
44
+ include Util
45
+ include XRay
46
+ end
47
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metabase
4
+ module Endpoint
5
+ module Activity
6
+ #
7
+ # @param params [Hash] Query string
8
+ # @return [Array<Hash>] Parsed response JSON
9
+ # @see https://github.com/metabase/metabase/blob/master/docs/api-documentation.md#get-apiactivity
10
+ def activities(**params)
11
+ get('/api/activity', params)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metabase
4
+ module Endpoint
5
+ module Alert
6
+ #
7
+ # @param params [Hash] Query string
8
+ # @return [Array<Hash>] Parsed response JSON
9
+ # @see https://github.com/metabase/metabase/blob/master/docs/api-documentation.md#get-apialert
10
+ def alerts(**params)
11
+ get('/api/alert', params)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metabase
4
+ module Endpoint
5
+ module Async
6
+ #
7
+ # @param params [Hash] Query string
8
+ # @return [Array<Integer>] Parsed response JSON
9
+ # @see https://github.com/metabase/metabase/blob/master/docs/api-documentation.md#get-apiasyncrunning-jobs
10
+ def running_jobs(**params)
11
+ get('/api/async/running-jobs', params)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metabase
4
+ module Endpoint
5
+ module Card
6
+ #
7
+ # @param params [Hash] Query string
8
+ # @return [Array<Hash>] Parsed response JSON
9
+ # @see https://github.com/metabase/metabase/blob/master/docs/api-documentation.md#get-apicard
10
+ def cards(**params)
11
+ get('/api/card', params)
12
+ end
13
+
14
+ #
15
+ # @param card_id [Integer, String] Card ID
16
+ # @param params [Hash] Query string
17
+ # @return [Hash] Parsed response JSON
18
+ # @see https://github.com/metabase/metabase/blob/master/docs/api-documentation.md#get-apicardid
19
+ def card(card_id, **params)
20
+ get("/api/card/#{card_id}", params)
21
+ end
22
+
23
+ #
24
+ # @param card_id [Integer, String] Card ID
25
+ # @param params [Hash] Request body
26
+ # @return [Hash] Parsed response JSON
27
+ # @see https://github.com/metabase/metabase/blob/master/docs/api-documentation.md#post-apicardcard-idquery
28
+ def query_card_with_metadata(card_id, **params)
29
+ post("/api/card/#{card_id}/query", params)
30
+ end
31
+
32
+ #
33
+ # @param card_id [Integer, String] Card ID
34
+ # @param format [Symbol, String] Export format (csv, json, xlsx)
35
+ # @param params [Hash] Request body
36
+ # @return [Array<Hash>, String] Query results
37
+ # @see https://github.com/metabase/metabase/blob/master/docs/api-documentation.md#post-apicardcard-idqueryexport-format
38
+ def query_card(card_id, format: :json, **params)
39
+ post("/api/card/#{card_id}/query/#{format}", params)
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metabase
4
+ module Endpoint
5
+ module Collection
6
+ #
7
+ # @param params [Hash] Query string
8
+ # @return [Array<Hash>] Parsed response JSON
9
+ # @see https://github.com/metabase/metabase/blob/master/docs/api-documentation.md#get-apicollection
10
+ def collections(**params)
11
+ get('/api/collection', params)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metabase
4
+ module Endpoint
5
+ module Dashboard
6
+ #
7
+ # @param params [Hash] Query string
8
+ # @return [Array<Hash>] Parsed response JSON
9
+ # @see https://github.com/metabase/metabase/blob/master/docs/api-documentation.md#get-apidashboard
10
+ def dashboards(**params)
11
+ get('/api/dashboard', params)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metabase
4
+ module Endpoint
5
+ module Database
6
+ #
7
+ # @param params [Hash] Query string
8
+ # @return [Array<Hash>] Parsed response JSON
9
+ # @see https://github.com/metabase/metabase/blob/master/docs/api-documentation.md#get-apidatabase
10
+ def databases(**params)
11
+ get('/api/database', params)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metabase
4
+ module Endpoint
5
+ module Metric
6
+ #
7
+ # @param params [Hash] Query string
8
+ # @return [Array<Hash>] Parsed response JSON
9
+ # @see https://github.com/metabase/metabase/blob/master/docs/api-documentation.md#get-apimetric
10
+ def metrics(**params)
11
+ get('/api/metric', params)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metabase
4
+ module Endpoint
5
+ module Permissions
6
+ #
7
+ # @param params [Hash] Query string
8
+ # @return [Array<Hash>] Parsed response JSON
9
+ # @see https://github.com/metabase/metabase/blob/master/docs/api-documentation.md#get-apipermissionsgroup
10
+ def groups(**params)
11
+ get('/api/permissions/group', params)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metabase
4
+ module Endpoint
5
+ module Public
6
+ #
7
+ # @param card_uuid [String] Card UUID
8
+ # @param params [Hash] Query string
9
+ # @return [Hash] Parsed response JSON
10
+ # @see https://github.com/metabase/metabase/blob/master/docs/api-documentation.md#get-apipubliccarduuid
11
+ def public_card(card_uuid, **params)
12
+ get("/api/public/card/#{card_uuid}", params)
13
+ end
14
+
15
+ #
16
+ # @param card_uuid [String] Card UUID
17
+ # @param params [Hash] Query string
18
+ # @return [Hash] Parsed response JSON
19
+ # @see https://github.com/metabase/metabase/blob/master/docs/api-documentation.md#get-apipubliccarduuidquery
20
+ def query_public_card_with_metadata(card_uuid, **params)
21
+ get("/api/public/card/#{card_uuid}/query", params)
22
+ end
23
+
24
+ #
25
+ # @param card_uuid [String] Card UUID
26
+ # @param format [Symbol, String] Export format (csv, json, xlsx)
27
+ # @param params [Hash] Query string
28
+ # @return [Array<Hash>, String] Query results
29
+ # @see https://github.com/metabase/metabase/blob/master/docs/api-documentation.md#get-apipubliccarduuidqueryexport-format
30
+ def query_public_card(card_uuid, format: :json, **params)
31
+ get("/api/public/card/#{card_uuid}/query/#{format}", params)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metabase
4
+ module Endpoint
5
+ module Pulse
6
+ #
7
+ # @param params [Hash] Query string
8
+ # @return [Array<Hash>] Parsed response JSON
9
+ # @see https://github.com/metabase/metabase/blob/master/docs/api-documentation.md#get-apipulse
10
+ def pulses(**params)
11
+ get('/api/pulse', params)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metabase
4
+ module Endpoint
5
+ module Revision
6
+ #
7
+ # @param params [Hash] Query string
8
+ # @return [Array<Hash>] Parsed response JSON
9
+ # @see https://github.com/metabase/metabase/blob/master/docs/api-documentation.md#get-apirevision
10
+ def revisions(**params)
11
+ get('/api/revision', params)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metabase
4
+ module Endpoint
5
+ module Segment
6
+ #
7
+ # @param params [Hash] Query string
8
+ # @return [Array<Hash>] Parsed response JSON
9
+ # @see https://github.com/metabase/metabase/blob/master/docs/api-documentation.md#get-apisegment
10
+ def segments(**params)
11
+ get('/api/segment', params)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metabase
4
+ module Endpoint
5
+ module Session
6
+ # Login to Metabase.
7
+ #
8
+ # @param params [Hash] Request body
9
+ # @return [String] Session token
10
+ # @see https://github.com/metabase/metabase/blob/master/docs/api-documentation.md#post-apisession
11
+ def login(**params)
12
+ params = { username: @username, password: @password }.merge(params)
13
+ response = post('/api/session', params)
14
+ @token = response['id']
15
+ end
16
+
17
+ #
18
+ # @param params [Hash] Request body
19
+ # @return [true] Always returns true
20
+ # @see https://github.com/metabase/metabase/blob/master/docs/api-documentation.md#delete-apisession
21
+ def logout(**params)
22
+ params = { session_id: @token }.merge(params)
23
+ delete('/api/session', params)
24
+ @token = nil
25
+ true
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metabase
4
+ module Endpoint
5
+ module Setting
6
+ #
7
+ # @param params [Hash] Query string
8
+ # @return [Array<Hash>] Parsed response JSON
9
+ # @see https://github.com/metabase/metabase/blob/master/docs/api-documentation.md#get-apisetting
10
+ def settings(**params)
11
+ get('/api/setting', params)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metabase
4
+ module Endpoint
5
+ module Setup
6
+ #
7
+ # @param params [Hash] Query string
8
+ # @return [Array<Hash>] Parsed response JSON
9
+ # @see https://github.com/metabase/metabase/blob/master/docs/api-documentation.md#get-apisetupadmin_checklist
10
+ def admin_checklists(**params)
11
+ get('/api/setup/admin_checklist', params)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metabase
4
+ module Endpoint
5
+ module Table
6
+ #
7
+ # @param params [Hash] Query string
8
+ # @return [Array<Hash>] Parsed response JSON
9
+ # @see https://github.com/metabase/metabase/blob/master/docs/api-documentation.md#get-apitable
10
+ def tables(**params)
11
+ get('/api/table', params)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metabase
4
+ module Endpoint
5
+ module User
6
+ #
7
+ # @param params [Hash] Query string
8
+ # @return [Array<Hash>] Parsed response JSON
9
+ # @see https://github.com/metabase/metabase/blob/master/docs/api-documentation.md#get-apiuser
10
+ def users(**params)
11
+ get('/api/user', params)
12
+ end
13
+
14
+ #
15
+ # @param params [Hash] Query string
16
+ # @return [Hash] Parsed response JSON
17
+ # @see https://github.com/metabase/metabase/blob/master/docs/api-documentation.md#get-apiusercurrent
18
+ def current_user(**params)
19
+ get('/api/user/current', params)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metabase
4
+ module Endpoint
5
+ module Util
6
+ #
7
+ # @param params [Hash] Query string
8
+ # @return [Array<String>] Parsed response JSON
9
+ # @see https://github.com/metabase/metabase/blob/master/docs/api-documentation.md#get-apiutillogs
10
+ def logs(**params)
11
+ get('/api/util/logs', params)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metabase
4
+ module Endpoint
5
+ module XRay
6
+ #
7
+ # @param card_id [Integer, String] Card ID
8
+ # @param params [Hash] Query string
9
+ # @return [Hash] Parsed response JSON
10
+ # @see https://github.com/metabase/metabase/blob/master/docs/api-documentation.md#get-apix-raycardid
11
+ def x_ray_card(card_id, **params)
12
+ get("/api/x-ray/card/#{card_id}", params)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metabase
4
+ class Error < StandardError
5
+ def self.from_response(response)
6
+ klass =
7
+ case response.status
8
+ when 400 then BadRequest
9
+ when 401 then Unauthorized
10
+ when 403 then Forbidden
11
+ when 404 then NotFound
12
+ when 400..499 then ClientError
13
+ when 500 then InternalServerError
14
+ when 502 then BadGateway
15
+ when 503 then ServiceUnavailable
16
+ when 500..599 then ServerError
17
+ end
18
+ klass&.new(response)
19
+ end
20
+
21
+ def initialize(response = nil)
22
+ @response = response
23
+ super(build_error_message)
24
+ end
25
+
26
+ private
27
+
28
+ def build_error_message
29
+ return nil if @response.nil?
30
+
31
+ "#{@response.env.method.upcase} #{@response.env.url}: " \
32
+ "#{@response.status} - #{@response.body}"
33
+ end
34
+ end
35
+
36
+ class ClientError < Error; end
37
+ class BadRequest < Error; end
38
+ class Unauthorized < Error; end
39
+ class Forbidden < Error; end
40
+ class NotFound < Error; end
41
+
42
+ class ServerError < Error; end
43
+ class InternalServerError < Error; end
44
+ class BadGateway < Error; end
45
+ class ServiceUnavailable < Error; end
46
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Metabase
4
+ VERSION = '0.2.0'
5
+ end
@@ -0,0 +1,41 @@
1
+
2
+ # frozen_string_literal: true
3
+
4
+ lib = File.expand_path('lib', __dir__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+ require 'metabase/version'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'metabase'
10
+ spec.version = Metabase::VERSION
11
+ spec.authors = ['Hiroshi Shimoju']
12
+ spec.email = ['hiroshi.shimoju@gmail.com']
13
+
14
+ spec.summary = 'Ruby client library for Metabase API'
15
+ spec.description = 'Ruby client library for Metabase API'
16
+ spec.homepage = 'https://github.com/shimoju/metabase-ruby'
17
+ spec.license = 'MIT'
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
+ f.match(%r{^(test|spec|features)/})
21
+ end
22
+ spec.bindir = 'exe'
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ['lib']
25
+
26
+ spec.required_ruby_version = '>= 2.3'
27
+
28
+ spec.add_runtime_dependency 'faraday', '~> 0.8'
29
+ spec.add_runtime_dependency 'faraday_middleware'
30
+
31
+ spec.add_development_dependency 'awesome_print'
32
+ spec.add_development_dependency 'bundler'
33
+ spec.add_development_dependency 'pry'
34
+ spec.add_development_dependency 'rake'
35
+ spec.add_development_dependency 'rspec'
36
+ spec.add_development_dependency 'rubocop'
37
+ spec.add_development_dependency 'simplecov'
38
+ spec.add_development_dependency 'vcr'
39
+ spec.add_development_dependency 'webmock'
40
+ spec.add_development_dependency 'yard'
41
+ end
metadata ADDED
@@ -0,0 +1,251 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: metabase
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Hiroshi Shimoju
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-05-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: awesome_print
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: simplecov
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: vcr
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: webmock
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: yard
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ description: Ruby client library for Metabase API
182
+ email:
183
+ - hiroshi.shimoju@gmail.com
184
+ executables: []
185
+ extensions: []
186
+ extra_rdoc_files: []
187
+ files:
188
+ - ".gitignore"
189
+ - ".rspec"
190
+ - ".rubocop.yml"
191
+ - ".travis.yml"
192
+ - Gemfile
193
+ - Gemfile.lock
194
+ - LICENSE.txt
195
+ - README.md
196
+ - Rakefile
197
+ - bin/console
198
+ - bin/setup
199
+ - docker-compose.yml
200
+ - lib/metabase.rb
201
+ - lib/metabase/client.rb
202
+ - lib/metabase/connection.rb
203
+ - lib/metabase/endpoint.rb
204
+ - lib/metabase/endpoint/activity.rb
205
+ - lib/metabase/endpoint/alert.rb
206
+ - lib/metabase/endpoint/async.rb
207
+ - lib/metabase/endpoint/card.rb
208
+ - lib/metabase/endpoint/collection.rb
209
+ - lib/metabase/endpoint/dashboard.rb
210
+ - lib/metabase/endpoint/database.rb
211
+ - lib/metabase/endpoint/metric.rb
212
+ - lib/metabase/endpoint/permissions.rb
213
+ - lib/metabase/endpoint/public.rb
214
+ - lib/metabase/endpoint/pulse.rb
215
+ - lib/metabase/endpoint/revision.rb
216
+ - lib/metabase/endpoint/segment.rb
217
+ - lib/metabase/endpoint/session.rb
218
+ - lib/metabase/endpoint/setting.rb
219
+ - lib/metabase/endpoint/setup.rb
220
+ - lib/metabase/endpoint/table.rb
221
+ - lib/metabase/endpoint/user.rb
222
+ - lib/metabase/endpoint/util.rb
223
+ - lib/metabase/endpoint/x_ray.rb
224
+ - lib/metabase/error.rb
225
+ - lib/metabase/version.rb
226
+ - metabase.gemspec
227
+ homepage: https://github.com/shimoju/metabase-ruby
228
+ licenses:
229
+ - MIT
230
+ metadata: {}
231
+ post_install_message:
232
+ rdoc_options: []
233
+ require_paths:
234
+ - lib
235
+ required_ruby_version: !ruby/object:Gem::Requirement
236
+ requirements:
237
+ - - ">="
238
+ - !ruby/object:Gem::Version
239
+ version: '2.3'
240
+ required_rubygems_version: !ruby/object:Gem::Requirement
241
+ requirements:
242
+ - - ">="
243
+ - !ruby/object:Gem::Version
244
+ version: '0'
245
+ requirements: []
246
+ rubyforge_project:
247
+ rubygems_version: 2.7.7
248
+ signing_key:
249
+ specification_version: 4
250
+ summary: Ruby client library for Metabase API
251
+ test_files: []