cubes 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +78 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/cubes.gemspec +27 -0
- data/lib/cubes.rb +20 -0
- data/lib/cubes/client.rb +55 -0
- data/lib/cubes/cube.rb +41 -0
- data/lib/cubes/error.rb +6 -0
- data/lib/cubes/middleware/raise_error.rb +20 -0
- data/lib/cubes/request.rb +43 -0
- data/lib/cubes/version.rb +3 -0
- metadata +158 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b724e61d4d283acafb582763008021ed39587c30
|
4
|
+
data.tar.gz: ee821dffaf098c5b6da1207651a602fa2fd0f325
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f418215aade8affc24d7211f8319ed7bb5b7df16dc6aa75359bc29b5d99b7d254bba286836fa45bcf1e7d8add06d319e821080f9adbd2cd2a9731dc224a53249
|
7
|
+
data.tar.gz: 471dd091630673494157e07cda5151a3f3bf82d8e0aa5e9b64c9977aec93efedb26268fc5c77a8abc2e5e84ec5ef23eb1c43df952cba5a1ddcb8fa2144b8117d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 David Guilherme
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# Cubes
|
2
|
+
|
3
|
+
A wrapper for [Cubes OLAP Server](https://github.com/DataBrewery/cubes).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'cubes'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install cubes
|
20
|
+
|
21
|
+
## Configuration
|
22
|
+
|
23
|
+
You can configure the Cubes::Client pass configuration options to the constructor.
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
client = Cubes::Client.new(base_url: 'http://your-cubes-server:5000')
|
27
|
+
```
|
28
|
+
|
29
|
+
By default, the client uses: `base_url: 'http://localhost:5000'`.
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
*List all cubes*
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
client.cubes
|
37
|
+
```
|
38
|
+
|
39
|
+
*Fetching the model specification of a cube*
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
cube = client.cube('sales')
|
43
|
+
cube.model
|
44
|
+
```
|
45
|
+
|
46
|
+
*Aggregate the measures of a cube
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
cube = client.cube('sales')
|
50
|
+
cube.aggregate(cut: 'date:2016')
|
51
|
+
cube.aggregate(cut: 'date:2016,5', drilldown: 'date')
|
52
|
+
```
|
53
|
+
|
54
|
+
*Generating reports*
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
report = {
|
58
|
+
summary: {
|
59
|
+
query: :aggregate
|
60
|
+
},
|
61
|
+
by_year: {
|
62
|
+
query: :aggregate
|
63
|
+
drilldown: [:date],
|
64
|
+
rollup: :date
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
cube = client.cube('sales')
|
69
|
+
cube.report(report_data, cut: 'date:2016')
|
70
|
+
```
|
71
|
+
## Contributing
|
72
|
+
|
73
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ntxcode/cubes.
|
74
|
+
|
75
|
+
## License
|
76
|
+
|
77
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
78
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "cubes"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/cubes.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cubes/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'cubes'
|
8
|
+
spec.version = Cubes::VERSION
|
9
|
+
spec.authors = ['David Guilherme']
|
10
|
+
spec.email = ['davidlguilherme@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'A Ruby wrapper for Cubes OLAP Server'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
spec.bindir = 'exe'
|
17
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
21
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
22
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
23
|
+
spec.add_development_dependency 'webmock'
|
24
|
+
spec.add_development_dependency 'byebug'
|
25
|
+
spec.add_dependency 'faraday'
|
26
|
+
spec.add_dependency 'net-http-persistent', '~> 2.9.4'
|
27
|
+
end
|
data/lib/cubes.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative 'cubes/version'
|
2
|
+
require_relative 'cubes/client'
|
3
|
+
require_relative 'cubes/request'
|
4
|
+
require_relative 'cubes/cube'
|
5
|
+
require_relative 'cubes/error'
|
6
|
+
require_relative 'cubes/middleware/raise_error'
|
7
|
+
|
8
|
+
module Cubes
|
9
|
+
class << self
|
10
|
+
attr_writer :client
|
11
|
+
|
12
|
+
def client
|
13
|
+
@client ||= Cubes::Client.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def cube(name)
|
17
|
+
@client.cube(name)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/cubes/client.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module Cubes
|
4
|
+
class Client
|
5
|
+
DEFAULT_BASE_URL = 'http://localhost:5000'
|
6
|
+
|
7
|
+
# Initializes a new Client
|
8
|
+
#
|
9
|
+
# @param options [Hash]
|
10
|
+
# @return [Cubes::Client]
|
11
|
+
def initialize(options = {})
|
12
|
+
@base_url = options[:base_url] || DEFAULT_BASE_URL
|
13
|
+
@conn = Faraday.new(url: @base_url, headers: { 'Content-Type' => 'application/json' }) do |config|
|
14
|
+
config.use Cubes::Middleware::RaiseError
|
15
|
+
config.adapter :net_http_persistent
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Return server information
|
20
|
+
#
|
21
|
+
# @return [Hash]
|
22
|
+
def info
|
23
|
+
request.get('info')
|
24
|
+
end
|
25
|
+
|
26
|
+
# Return server version
|
27
|
+
#
|
28
|
+
# @return [Hash]
|
29
|
+
def version
|
30
|
+
request.get('version')
|
31
|
+
end
|
32
|
+
|
33
|
+
# List all cubes
|
34
|
+
#
|
35
|
+
# @return [Array]
|
36
|
+
def cubes
|
37
|
+
request.get('cubes')
|
38
|
+
end
|
39
|
+
|
40
|
+
# Instantiating a cube api
|
41
|
+
#
|
42
|
+
# @param name [String]
|
43
|
+
# @return [Cubes::Cube]
|
44
|
+
def cube(name)
|
45
|
+
Cubes::Cube.new(name, @conn)
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
# @return [Cubes::Request]
|
51
|
+
def request
|
52
|
+
Cubes::Request.new(@conn)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/cubes/cube.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
module Cubes
|
2
|
+
class Cube
|
3
|
+
def initialize(name, conn)
|
4
|
+
@name = name
|
5
|
+
@conn = conn
|
6
|
+
|
7
|
+
# preload the model
|
8
|
+
model
|
9
|
+
end
|
10
|
+
|
11
|
+
def aggregate(params = {})
|
12
|
+
request.get('aggregate', params)
|
13
|
+
end
|
14
|
+
|
15
|
+
def model
|
16
|
+
@model ||= request.get('model')
|
17
|
+
end
|
18
|
+
|
19
|
+
def facts(params = {})
|
20
|
+
request.get('facts', params)
|
21
|
+
end
|
22
|
+
|
23
|
+
def fact(id)
|
24
|
+
request.get("fact/#{id}")
|
25
|
+
end
|
26
|
+
|
27
|
+
def members(dim, params = {})
|
28
|
+
request.get("members/#{dim}", params)
|
29
|
+
end
|
30
|
+
|
31
|
+
def report(data = {}, params = {})
|
32
|
+
request.post('report', { queries: data }, params)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def request
|
38
|
+
Cubes::Request.new(@conn, prefix: "/cube/#{@name}")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/cubes/error.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Cubes
|
2
|
+
module Middleware
|
3
|
+
class RaiseError < Faraday::Response::Middleware
|
4
|
+
# Handle client errors
|
5
|
+
#
|
6
|
+
# @param env [Env]
|
7
|
+
def on_complete(env)
|
8
|
+
response = JSON.parse env.body
|
9
|
+
|
10
|
+
if response.is_a?(Hash) && response['error'] == 'not_found'
|
11
|
+
raise Cubes::Error::ResourceNotFound.new(response[:message])
|
12
|
+
end
|
13
|
+
|
14
|
+
if env[:status] == 404
|
15
|
+
raise Cubes::Error::RouteNotFound.new('Route not found.')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Cubes
|
4
|
+
class Request
|
5
|
+
# Initialize a Request
|
6
|
+
#
|
7
|
+
# @param conn [Faraday::Connection]
|
8
|
+
# @param options [Hash]
|
9
|
+
# @return [Cubes::Request]
|
10
|
+
def initialize(conn, options = {})
|
11
|
+
@conn = conn
|
12
|
+
@prefix = options.fetch(:prefix, '/')
|
13
|
+
end
|
14
|
+
|
15
|
+
# Send a get request
|
16
|
+
#
|
17
|
+
# @param path [String]
|
18
|
+
# @param params [Hash]
|
19
|
+
# @return [JSON]
|
20
|
+
def get(path, params = {})
|
21
|
+
path = File.join(@prefix, path)
|
22
|
+
JSON.parse @conn.get(path, params).body
|
23
|
+
end
|
24
|
+
|
25
|
+
# Send a post request
|
26
|
+
#
|
27
|
+
# @param path [String]
|
28
|
+
# @param data [Hash]
|
29
|
+
# @param params [Hash]
|
30
|
+
# @return [JSON]
|
31
|
+
def post(path, data = {}, params = {})
|
32
|
+
body = data.to_json
|
33
|
+
path = File.join(@prefix, path)
|
34
|
+
|
35
|
+
response = @conn.post(path, body) do |req|
|
36
|
+
req.params = params
|
37
|
+
req.headers['Content-Type'] = 'application/json'
|
38
|
+
end
|
39
|
+
|
40
|
+
JSON.parse response.body
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cubes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Guilherme
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
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: byebug
|
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: faraday
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
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: net-http-persistent
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 2.9.4
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 2.9.4
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- davidlguilherme@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE.txt
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- bin/console
|
125
|
+
- bin/setup
|
126
|
+
- cubes.gemspec
|
127
|
+
- lib/cubes.rb
|
128
|
+
- lib/cubes/client.rb
|
129
|
+
- lib/cubes/cube.rb
|
130
|
+
- lib/cubes/error.rb
|
131
|
+
- lib/cubes/middleware/raise_error.rb
|
132
|
+
- lib/cubes/request.rb
|
133
|
+
- lib/cubes/version.rb
|
134
|
+
homepage:
|
135
|
+
licenses:
|
136
|
+
- MIT
|
137
|
+
metadata: {}
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
requirements: []
|
153
|
+
rubyforge_project:
|
154
|
+
rubygems_version: 2.5.1
|
155
|
+
signing_key:
|
156
|
+
specification_version: 4
|
157
|
+
summary: A Ruby wrapper for Cubes OLAP Server
|
158
|
+
test_files: []
|