gooddata 0.6.0.pre10 → 0.6.0.pre11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +7 -0
  2. data/.autotest +2 -0
  3. data/.gitignore +3 -0
  4. data/.travis.yml +7 -0
  5. data/.yardopts +3 -2
  6. data/README.md +8 -145
  7. data/Rakefile +23 -6
  8. data/bin/gooddata +3 -400
  9. data/doc/pages/GET_STARTED.md +5 -4
  10. data/doc/pages/HOMEPAGE.md +2 -0
  11. data/doc/pages/TUTORIALS.md +3 -3
  12. data/doc/pages/tutorial/BRICKS.md +4 -1
  13. data/doc/pages/tutorial/CREATING_A_MODEL.md +2 -0
  14. data/doc/pages/tutorial/CRUNCHING_NUMBERS.md +1 -3
  15. data/doc/pages/tutorial/TEST_DRIVEN_DEVELOPMENT.md +2 -0
  16. data/doc/pages/tutorial/YOUR_FIRST_PROJECT.md +4 -3
  17. data/doc/templates/default/class/setup.rb +1 -0
  18. data/doc/templates/default/method_details/setup.rb +2 -1
  19. data/doc/templates/default/module/setup.rb +1 -1
  20. data/gooddata +7 -0
  21. data/gooddata.gemspec +1 -0
  22. data/lib/gooddata.rb +15 -4
  23. data/lib/gooddata/bricks/base_downloader.rb +1 -0
  24. data/lib/gooddata/bricks/brick.rb +17 -12
  25. data/lib/gooddata/bricks/bricks.rb +7 -0
  26. data/lib/gooddata/bricks/middleware/base_middleware.rb +13 -0
  27. data/lib/gooddata/bricks/middleware/bench_middleware.rb +1 -0
  28. data/lib/gooddata/bricks/middleware/bulk_salesforce_middleware.rb +2 -1
  29. data/lib/gooddata/bricks/middleware/fs_upload_middleware.rb +30 -0
  30. data/lib/gooddata/bricks/middleware/gooddata_middleware.rb +10 -8
  31. data/lib/gooddata/bricks/middleware/logger_middleware.rb +3 -2
  32. data/lib/gooddata/bricks/middleware/middleware.rb +4 -11
  33. data/lib/gooddata/bricks/middleware/restforce_middleware.rb +2 -0
  34. data/lib/gooddata/bricks/middleware/stdout_middleware.rb +2 -0
  35. data/lib/gooddata/bricks/middleware/twitter_middleware.rb +2 -0
  36. data/lib/gooddata/cli/cli.rb +28 -0
  37. data/lib/gooddata/cli/commands/api_cmd.rb +30 -0
  38. data/lib/gooddata/cli/commands/auth_cmd.rb +17 -0
  39. data/lib/gooddata/cli/commands/console_cmd.rb +17 -0
  40. data/lib/gooddata/cli/commands/process_cmd.rb +55 -0
  41. data/lib/gooddata/cli/commands/profile_cmd.rb +22 -0
  42. data/lib/gooddata/cli/commands/project_cmd.rb +143 -0
  43. data/lib/gooddata/cli/commands/run_ruby_cmd.rb +55 -0
  44. data/lib/gooddata/cli/commands/scaffold_cmd.rb +32 -0
  45. data/lib/gooddata/cli/hooks.rb +43 -0
  46. data/lib/gooddata/cli/shared.rb +51 -0
  47. data/lib/gooddata/client.rb +37 -24
  48. data/lib/gooddata/commands/api.rb +1 -0
  49. data/lib/gooddata/commands/auth.rb +8 -4
  50. data/lib/gooddata/commands/base.rb +2 -80
  51. data/lib/gooddata/commands/commands.rb +4 -9
  52. data/lib/gooddata/commands/datasets.rb +1 -1
  53. data/lib/gooddata/commands/runners.rb +6 -7
  54. data/lib/gooddata/connection.rb +40 -35
  55. data/lib/gooddata/core/core.rb +8 -0
  56. data/lib/gooddata/exceptions.rb +1 -1
  57. data/lib/gooddata/goodzilla/goodzilla.rb +12 -0
  58. data/lib/gooddata/models/attribute.rb +2 -0
  59. data/lib/gooddata/models/dashboard.rb +9 -2
  60. data/lib/gooddata/models/data_result.rb +3 -256
  61. data/lib/gooddata/models/data_set.rb +2 -0
  62. data/lib/gooddata/models/display_form.rb +2 -0
  63. data/lib/gooddata/models/empty_result.rb +37 -0
  64. data/lib/gooddata/models/fact.rb +2 -0
  65. data/lib/gooddata/models/metadata.rb +6 -1
  66. data/lib/gooddata/models/metric.rb +2 -1
  67. data/lib/gooddata/{model.rb → models/model.rb} +1 -1
  68. data/lib/gooddata/models/models.rb +4 -0
  69. data/lib/gooddata/models/project.rb +10 -6
  70. data/lib/gooddata/models/report.rb +6 -0
  71. data/lib/gooddata/models/report_data_result.rb +167 -0
  72. data/lib/gooddata/models/report_definition.rb +2 -0
  73. data/lib/gooddata/version.rb +15 -1
  74. data/spec/bricks/bricks_spec.rb +39 -0
  75. data/spec/helpers/blueprint_helper.rb +1 -1
  76. data/spec/helpers/connection_helper.rb +12 -0
  77. data/spec/{project_build_and_update_spec.rb → integration/command_projects_spec.rb} +0 -3
  78. data/spec/{full_project_spec.rb → integration/full_project_spec.rb} +0 -3
  79. data/spec/logging_in_logging_out_spec.rb +17 -0
  80. data/spec/spec_helper.rb +6 -1
  81. data/spec/unit/bricks/bricks_spec.rb +23 -0
  82. data/spec/unit/bricks/middleware/bench_middleware_spec.rb +9 -0
  83. data/spec/unit/bricks/middleware/bulk_salesforce_middleware_spec.rb +9 -0
  84. data/spec/unit/bricks/middleware/gooddata_middleware_spec.rb +9 -0
  85. data/spec/unit/bricks/middleware/logger_middleware_spec.rb +9 -0
  86. data/spec/unit/bricks/middleware/restforce_middleware_spec.rb +9 -0
  87. data/spec/unit/bricks/middleware/stdout_middleware_spec.rb +9 -0
  88. data/spec/unit/bricks/middleware/twitter_middleware_spec.rb +9 -0
  89. data/spec/unit/cli/cli_spec.rb +11 -0
  90. data/spec/unit/cli/commands/cmd_api_spec.rb +11 -0
  91. data/spec/unit/cli/commands/cmd_auth_spec.rb +11 -0
  92. data/spec/unit/cli/commands/cmd_process_spec.rb +11 -0
  93. data/spec/unit/cli/commands/cmd_profile_spec.rb +11 -0
  94. data/spec/unit/cli/commands/cmd_project_spec.rb +11 -0
  95. data/spec/unit/cli/commands/cmd_run_ruby_spec.rb +11 -0
  96. data/spec/unit/cli/commands/cmd_scaffold_spec.rb +11 -0
  97. data/spec/unit/commands/command_api_spec.rb +12 -0
  98. data/spec/unit/commands/command_auth_spec.rb +12 -0
  99. data/spec/unit/commands/command_dataset_spec.rb +12 -0
  100. data/spec/unit/commands/command_process_spec.rb +12 -0
  101. data/spec/unit/commands/command_profile_spec.rb +12 -0
  102. data/spec/unit/commands/command_projects_spec.rb +12 -0
  103. data/spec/unit/commands/command_scaffold_spec.rb +12 -0
  104. data/spec/unit/core/connection_spec.rb +25 -0
  105. data/spec/unit/core/core_spec.rb +7 -0
  106. data/spec/{goodzilla_spec.rb → unit/godzilla/goodzilla_spec.rb} +0 -0
  107. data/spec/{blueprint_spec.rb → unit/model/blueprint_spec.rb} +3 -3
  108. data/spec/{merging_blueprints_spec.rb → unit/model/model_spec.rb} +28 -26
  109. data/spec/{model_spec.rb → unit/model/project_blueprint_spec.rb} +0 -0
  110. data/spec/{model_dsl_spec.rb → unit/model/schema_builder_spec.rb} +1 -1
  111. metadata +77 -61
@@ -0,0 +1,4 @@
1
+ base = Pathname(__FILE__).dirname.expand_path
2
+ Dir.glob(base + '*.rb').each do |file|
3
+ require file
4
+ end
@@ -30,14 +30,18 @@ module GoodData
30
30
  #
31
31
  def [](id)
32
32
  return id if id.respond_to?(:is_project?) && id.is_project?
33
- if id.to_s !~ /^(\/gdc\/(projects|md)\/)?[a-zA-Z\d]+$/
34
- raise ArgumentError.new("wrong type of argument. Should be either project ID or path")
35
- end
33
+ if id == :all
34
+ Project.all
35
+ else
36
+ if id.to_s !~ /^(\/gdc\/(projects|md)\/)?[a-zA-Z\d]+$/
37
+ raise ArgumentError.new("wrong type of argument. Should be either project ID or path")
38
+ end
36
39
 
37
- id = id.match(/[a-zA-Z\d]+$/)[0] if id =~ /\//
40
+ id = id.match(/[a-zA-Z\d]+$/)[0] if id =~ /\//
38
41
 
39
- response = GoodData.get PROJECT_PATH % id
40
- Project.new response
42
+ response = GoodData.get PROJECT_PATH % id
43
+ Project.new response
44
+ end
41
45
  end
42
46
 
43
47
  # Create a project from a given attributes
@@ -1,3 +1,5 @@
1
+ require File.join(File.dirname(__FILE__), "metadata")
2
+
1
3
  module GoodData
2
4
  class Report < GoodData::MdObject
3
5
 
@@ -67,6 +69,10 @@ module GoodData
67
69
  ReportDataResult.new(GoodData.get data_result_uri)
68
70
  end
69
71
 
72
+ def exportable?
73
+ true
74
+ end
75
+
70
76
  def export(format)
71
77
  result = GoodData.post('/gdc/xtab2/executor3', {"report_req" => {"report" => uri}})
72
78
  result1 = GoodData.post('/gdc/exporter/executor', {:result_req => {:format => format, :result => result}})
@@ -0,0 +1,167 @@
1
+ require File.join(File.dirname(__FILE__), "data_result.rb")
2
+
3
+ module GoodData
4
+ class ReportDataResult < DataResult
5
+
6
+ ROW_LIMIT = 10000000
7
+
8
+ attr_reader :row_headers, :column_headers, :table, :headers_height, :headers_width
9
+
10
+ def initialize(data)
11
+ super
12
+ @row_headers = []
13
+ @column_headers = []
14
+ @table = []
15
+
16
+ @row_headers, @headers_width = tabularize_rows
17
+ @column_headers, @headers_height = tabularize_columns
18
+
19
+ assemble_table
20
+ end
21
+
22
+ def without_column_headers
23
+ @table = table.transpose[headers_height, ROW_LIMIT].transpose
24
+ self
25
+ end
26
+
27
+ def to_data_table
28
+ table.transpose[headers_height, ROW_LIMIT].transpose[headers_width, ROW_LIMIT]
29
+ end
30
+
31
+ def each_line
32
+ to_table.each { |line| yield line }
33
+ end
34
+
35
+ alias :each_row :each_line
36
+
37
+ def each_column
38
+ table.each { |line| yield line }
39
+ end
40
+
41
+ def to_a
42
+ table.to_a
43
+ end
44
+
45
+ def to_table
46
+ table.transpose
47
+ end
48
+
49
+ def [](index)
50
+ to_table[index]
51
+ end
52
+
53
+ alias :row :[]
54
+
55
+ def column(index)
56
+ table[index]
57
+ end
58
+
59
+ def include_row?(row)
60
+ to_table.include?(row)
61
+ end
62
+
63
+ def include_column?(row)
64
+ table.include?(row)
65
+ end
66
+
67
+ def == (otherDataResult)
68
+ result = true
69
+ csv_table = to_table
70
+ len = csv_table.length
71
+ table = otherDataResult.respond_to?(:to_table) ? otherDataResult.to_table : otherDataResult
72
+ return false if len != table.length
73
+ diff(otherDataResult).empty?() ? true : false
74
+ end
75
+
76
+ def diff(otherDataResult)
77
+ csv_table = to_table
78
+ other_table = otherDataResult.respond_to?(:to_table) ? otherDataResult.to_table : otherDataResult
79
+ differences = []
80
+
81
+ csv_table.each do |row|
82
+ differences << row unless other_table.detect { |r| r == row }
83
+ end
84
+ differences
85
+ end
86
+
87
+ private
88
+ def each_level(table, level, children, lookup)
89
+ max_level = level + 1
90
+ children.each do |kid|
91
+ first = kid["first"]
92
+ last = kid["last"]
93
+ repetition = last - first + 1
94
+ repetition.times do |i|
95
+ table[first + i] ||= []
96
+ if kid["type"] == 'total'
97
+ table[first + i][level] = kid["id"]
98
+ else
99
+ table[first + i][level] = lookup[level][kid["id"].to_s]
100
+ end
101
+ end
102
+ if (!kid["children"].empty?)
103
+ new_level = each_level(table, level+1, kid["children"], lookup)
104
+ max_level = [max_level, new_level].max
105
+ end
106
+ end
107
+ max_level
108
+ end
109
+
110
+ def tabularize_rows
111
+ rows = data["xtab_data"]["rows"]
112
+ kids = rows["tree"]["children"]
113
+
114
+ if kids.empty? || (kids.size == 1 && kids.first['type'] == 'metric')
115
+ headers, size = [[nil]], 0
116
+ else
117
+ headers = []
118
+ size = each_level(headers, 0, rows["tree"]["children"], rows["lookups"])
119
+ end
120
+ return headers, size
121
+ end
122
+
123
+ def tabularize_columns
124
+ columns = data["xtab_data"]["columns"]
125
+ kids = columns["tree"]["children"]
126
+
127
+ if kids.empty? || (kids.size == 1 && kids.first['type'] == 'metric')
128
+ headers, size = [[nil]], 0
129
+ else
130
+ headers = []
131
+ size = each_level(headers, 0, columns["tree"]["children"], columns["lookups"])
132
+ end
133
+ return headers, size
134
+ end
135
+
136
+ def assemble_table()
137
+ # puts "=== COLUMNS === #{column_headers.size}x#{headers_height}"
138
+ (column_headers.size).times do |i|
139
+ (headers_height).times do |j|
140
+ table[headers_width + i] ||= []
141
+ # puts "[#{headers_width + i}][#{j}] #{column_headers[i][j]}"
142
+ table[headers_width + i][j] = column_headers[i][j]
143
+ end
144
+ end
145
+
146
+ # puts "=== ROWS ==="
147
+ (row_headers.size).times do |i|
148
+ (headers_width).times do |j|
149
+ table[j] ||= []
150
+ # puts "[#{j}][#{headers_height + i}] #{row_headers[i][j]}"
151
+ table[j][headers_height + i] = row_headers[i][j]
152
+ end
153
+ end
154
+
155
+ xtab_data = data["xtab_data"]["data"]
156
+ # puts "=== DATA === #{column_headers.size}x#{row_headers.size}"
157
+ (column_headers.size).times do |i|
158
+ (row_headers.size).times do |j|
159
+ table[headers_width + i] ||= []
160
+ # puts "[#{headers_width + i}, #{headers_height + j}] [#{i}][#{j}]=#{xtab_data[j][i]}"
161
+ val = xtab_data[j][i]
162
+ table[headers_width + i][headers_height + j] = val.nil? ? val : BigDecimal(val)
163
+ end
164
+ end
165
+ end
166
+ end
167
+ end
@@ -1,3 +1,5 @@
1
+ require File.join(File.dirname(__FILE__), "metadata")
2
+
1
3
  module GoodData
2
4
  class ReportDefinition < GoodData::MdObject
3
5
 
@@ -1,3 +1,17 @@
1
1
  module GoodData
2
- VERSION = "0.6.0.pre10"
2
+ VERSION = "0.6.0.pre11"
3
+
4
+ class << self
5
+
6
+ # Version
7
+ def version
8
+ VERSION
9
+ end
10
+
11
+ # Identifier of gem version
12
+ # @return Formatted gem version
13
+ def gem_version_string()
14
+ "gooddata-gem/#{VERSION}"
15
+ end
16
+ end
3
17
  end
@@ -0,0 +1,39 @@
1
+ require 'gooddata/bricks/brick'
2
+ require 'gooddata/bricks/bricks'
3
+ require 'gooddata/bricks/middleware/base_middleware'
4
+ require 'pry'
5
+
6
+ describe GoodData::Bricks do
7
+ it "Has GoodData::Bricks::Brick class" do
8
+ GoodData::Bricks::Brick.should_not == nil
9
+ end
10
+
11
+ it "should be possible to use block as an app in pipeline" do
12
+ p = GoodData::Bricks::Pipeline.prepare([
13
+ lambda { |params| puts "x" }
14
+ ])
15
+ p.call({})
16
+ end
17
+
18
+
19
+ # TODO: Better test pre and post so we are sure it is executed in right order
20
+ it "should be possible to use instance both as middleware and app" do
21
+
22
+ class DummyMiddleware < GoodData::Bricks::Middleware
23
+
24
+ def call(params)
25
+ puts "pre"
26
+ app.call(params)
27
+ puts "post"
28
+ end
29
+
30
+ end
31
+
32
+ p = GoodData::Bricks::Pipeline.prepare([
33
+ DummyMiddleware.new,
34
+ lambda { |params| puts "x" }
35
+ ])
36
+ p.call({})
37
+ end
38
+
39
+ end
@@ -2,7 +2,7 @@
2
2
  require 'json'
3
3
 
4
4
  # Local requires
5
- require 'gooddata/model'
5
+ require 'gooddata/models/models'
6
6
 
7
7
  module BlueprintHelper
8
8
  def blueprint_from_file(bp)
@@ -0,0 +1,12 @@
1
+ require 'gooddata/connection'
2
+
3
+ module ConnectionHelper
4
+ GD_PROJECT_TOKEN = ENV["GD_PROJECT_TOKEN"]
5
+ DEFAULT_USERNAME = "svarovsky+gem_tester@goddata.com"
6
+ DEFAULT_PASSWORD = "jindrisska"
7
+
8
+ def self.create_default_connection(username = DEFAULT_USERNAME, password = DEFAULT_PASSWORD)
9
+ GoodData::Connection.new(username, password)
10
+ end
11
+
12
+ end
@@ -3,9 +3,6 @@ require 'gooddata/commands/projects'
3
3
  require 'pry'
4
4
 
5
5
  describe GoodData::Command::Projects, :constraint => 'slow' do
6
-
7
- GD_PROJECT_TOKEN = ENV["GD_PROJECT_TOKEN"]
8
-
9
6
  before(:all) do
10
7
  @blueprint = GoodData::Model::ProjectBlueprint.from_json("./spec/data/test_project_model_spec.json")
11
8
  @module_blueprint = GoodData::Model::ProjectBlueprint.from_json("./spec/data/additional_dataset_module.json")
@@ -1,9 +1,6 @@
1
1
  require 'gooddata'
2
2
 
3
3
  describe "Spin a project", :constraint => 'slow' do
4
-
5
- GD_PROJECT_TOKEN = ENV["GD_PROJECT_TOKEN"]
6
-
7
4
  before(:all) do
8
5
  spec = JSON.parse(File.read("./spec/data/test_project_model_spec.json"), :symbolize_names => true)
9
6
  GoodData.connect("svarovsky+gem_tester@gooddata.com", "jindrisska")
@@ -0,0 +1,17 @@
1
+ require 'gooddata'
2
+ require 'pry'
3
+
4
+ describe GoodData::Connection, :constraint => 'slow' do
5
+
6
+ it "should log in and disconnect" do
7
+
8
+ GoodData.connect("svarovsky+gem_tester@gooddata.com", "jindrisska")
9
+ GoodData.get("/gdc/md")
10
+
11
+ conn = GoodData.connection
12
+ GoodData.disconnect
13
+ expect{GoodData.connection}.to raise_error
14
+ conn.connected?.should == false
15
+ end
16
+
17
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,11 @@
1
+ require 'rspec'
2
+
1
3
  # Automagically include all helpers/*_helper.rb
2
- require 'helpers/blueprint_helper'
4
+
5
+ require File.join(File.dirname(__FILE__), 'helpers/blueprint_helper')
6
+ require File.join(File.dirname(__FILE__), 'helpers/connection_helper.rb')
3
7
 
4
8
  RSpec.configure do |config|
5
9
  include BlueprintHelper
10
+ include ConnectionHelper
6
11
  end
@@ -0,0 +1,23 @@
1
+ require 'gooddata/bricks/bricks'
2
+
3
+ describe GoodData::Bricks do
4
+ it "Has GoodData::Bricks::Brick class" do
5
+ GoodData::Bricks::Brick.should_not == nil
6
+ end
7
+
8
+ it "should be possible to execute a brick" do
9
+
10
+ class DummyBrick < GoodData::Bricks::Brick
11
+
12
+ def call(params)
13
+ puts "hello"
14
+ end
15
+ end
16
+
17
+ include GoodData::Bricks
18
+
19
+ p = GoodData::Bricks::Pipeline.prepare([GoodData::Bricks::BenchMiddleware, DummyBrick])
20
+
21
+ p.call({})
22
+ end
23
+ end
@@ -0,0 +1,9 @@
1
+ require 'gooddata/bricks/brick'
2
+ require 'gooddata/bricks/bricks'
3
+ require 'gooddata/bricks/middleware/bench_middleware'
4
+
5
+ describe GoodData::Bricks::BenchMiddleware do
6
+ it "Has GoodData::Bricks::BenchMiddleware class" do
7
+ GoodData::Bricks::BenchMiddleware.should_not == nil
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require 'gooddata/bricks/brick'
2
+ require 'gooddata/bricks/bricks'
3
+ require 'gooddata/bricks/middleware/bulk_salesforce_middleware'
4
+
5
+ describe GoodData::Bricks::BulkSalesforceMiddleware do
6
+ it "Has GoodData::Bricks::BulkSalesforceMiddleware class" do
7
+ GoodData::Bricks::BulkSalesforceMiddleware.should_not == nil
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require 'gooddata/bricks/brick'
2
+ require 'gooddata/bricks/bricks'
3
+ require 'gooddata/bricks/middleware/gooddata_middleware'
4
+
5
+ describe GoodData::Bricks::GoodDataMiddleware do
6
+ it "Has GoodData::Bricks::GoodDataMiddleware class" do
7
+ GoodData::Bricks::GoodDataMiddleware.should_not == nil
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require 'gooddata/bricks/brick'
2
+ require 'gooddata/bricks/bricks'
3
+ require 'gooddata/bricks/middleware/logger_middleware'
4
+
5
+ describe GoodData::Bricks::LoggerMiddleware do
6
+ it "Has GoodData::Bricks::LoggerMiddleware class" do
7
+ GoodData::Bricks::LoggerMiddleware.should_not == nil
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require 'gooddata/bricks/brick'
2
+ require 'gooddata/bricks/bricks'
3
+ require 'gooddata/bricks/middleware/restforce_middleware'
4
+
5
+ describe GoodData::Bricks::RestForceMiddleware do
6
+ it "Has GoodData::Bricks::RestForceMiddleware class" do
7
+ GoodData::Bricks::RestForceMiddleware.should_not == nil
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require 'gooddata/bricks/brick'
2
+ require 'gooddata/bricks/bricks'
3
+ require 'gooddata/bricks/middleware/stdout_middleware'
4
+
5
+ describe GoodData::Bricks::STDOUTLoggingMiddleware do
6
+ it "Has GoodData::Bricks::STDOUTLoggingMiddleware class" do
7
+ GoodData::Bricks::STDOUTLoggingMiddleware.should_not == nil
8
+ end
9
+ end