gooddata 0.6.0 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (208) hide show
  1. checksums.yaml +13 -5
  2. data/.rubocop.yml +23 -0
  3. data/.travis.yml +9 -4
  4. data/CLI.md +439 -0
  5. data/Gemfile +0 -1
  6. data/README.md +2 -2
  7. data/Rakefile +60 -8
  8. data/doc/templates/default/module/setup.rb +1 -1
  9. data/examples.rb +2 -0
  10. data/gooddata +2 -0
  11. data/gooddata.gemspec +12 -8
  12. data/lib/gooddata.rb +0 -2
  13. data/lib/gooddata/bricks/base_downloader.rb +52 -47
  14. data/lib/gooddata/bricks/brick.rb +20 -31
  15. data/lib/gooddata/bricks/bricks.rb +1 -1
  16. data/lib/gooddata/bricks/middleware/base_middleware.rb +9 -7
  17. data/lib/gooddata/bricks/middleware/bench_middleware.rb +12 -10
  18. data/lib/gooddata/bricks/middleware/bulk_salesforce_middleware.rb +28 -28
  19. data/lib/gooddata/bricks/middleware/fs_upload_middleware.rb +20 -16
  20. data/lib/gooddata/bricks/middleware/gooddata_middleware.rb +21 -19
  21. data/lib/gooddata/bricks/middleware/logger_middleware.rb +10 -8
  22. data/lib/gooddata/bricks/middleware/restforce_middleware.rb +36 -34
  23. data/lib/gooddata/bricks/middleware/stdout_middleware.rb +11 -9
  24. data/lib/gooddata/bricks/middleware/twitter_middleware.rb +14 -12
  25. data/lib/gooddata/bricks/pipeline.rb +28 -0
  26. data/lib/gooddata/bricks/utils.rb +10 -8
  27. data/lib/gooddata/cli/cli.rb +1 -6
  28. data/lib/gooddata/cli/commands/auth_cmd.rb +1 -1
  29. data/lib/gooddata/cli/commands/console_cmd.rb +7 -5
  30. data/lib/gooddata/cli/commands/domain_cmd.rb +45 -0
  31. data/lib/gooddata/cli/commands/process_cmd.rb +42 -5
  32. data/lib/gooddata/cli/commands/project_cmd.rb +96 -36
  33. data/lib/gooddata/cli/commands/projects_cmd.rb +21 -0
  34. data/lib/gooddata/cli/commands/role_cmd.rb +28 -0
  35. data/lib/gooddata/cli/commands/run_ruby_cmd.rb +5 -5
  36. data/lib/gooddata/cli/commands/scaffold_cmd.rb +1 -1
  37. data/lib/gooddata/cli/commands/{profile_cmd.rb → user_cmd.rb} +7 -9
  38. data/lib/gooddata/cli/shared.rb +3 -2
  39. data/lib/gooddata/client.rb +16 -304
  40. data/lib/gooddata/commands/api.rb +13 -5
  41. data/lib/gooddata/commands/auth.rb +47 -40
  42. data/lib/gooddata/commands/base.rb +4 -2
  43. data/lib/gooddata/commands/commands.rb +1 -1
  44. data/lib/gooddata/commands/datasets.rb +20 -7
  45. data/lib/gooddata/commands/domain.rb +23 -0
  46. data/lib/gooddata/commands/process.rb +23 -117
  47. data/lib/gooddata/commands/project.rb +147 -0
  48. data/lib/gooddata/commands/projects.rb +8 -102
  49. data/lib/gooddata/commands/role.rb +26 -0
  50. data/lib/gooddata/commands/runners.rb +41 -38
  51. data/lib/gooddata/commands/scaffold.rb +46 -43
  52. data/lib/gooddata/commands/user.rb +33 -0
  53. data/lib/gooddata/connection.rb +43 -353
  54. data/lib/gooddata/core/connection.rb +389 -0
  55. data/lib/gooddata/core/core.rb +5 -4
  56. data/lib/gooddata/core/logging.rb +48 -0
  57. data/lib/gooddata/core/nil_logger.rb +13 -0
  58. data/lib/gooddata/core/project.rb +70 -0
  59. data/lib/gooddata/core/rest.rb +120 -0
  60. data/lib/gooddata/core/threaded.rb +14 -0
  61. data/lib/gooddata/core/user.rb +19 -0
  62. data/lib/gooddata/data/data.rb +2 -1
  63. data/lib/gooddata/data/guesser.rb +16 -12
  64. data/lib/gooddata/exceptions/command_failed.rb +1 -1
  65. data/lib/gooddata/exceptions/exceptions.rb +2 -1
  66. data/lib/gooddata/exceptions/no_project_error.rb +11 -0
  67. data/lib/gooddata/exceptions/project_not_found.rb +1 -1
  68. data/lib/gooddata/extensions/big_decimal.rb +6 -2
  69. data/lib/gooddata/extract.rb +10 -8
  70. data/lib/gooddata/goodzilla/goodzilla.rb +61 -59
  71. data/lib/gooddata/helpers.rb +15 -9
  72. data/lib/gooddata/models/account_settings.rb +124 -0
  73. data/lib/gooddata/models/attributes/anchor.rb +37 -0
  74. data/lib/gooddata/models/attributes/attributes.rb +8 -0
  75. data/lib/gooddata/models/attributes/date_attribute.rb +25 -0
  76. data/lib/gooddata/models/attributes/time_attribute.rb +24 -0
  77. data/lib/gooddata/models/columns/attribute.rb +71 -0
  78. data/lib/gooddata/models/columns/columns.rb +8 -0
  79. data/lib/gooddata/models/columns/date_column.rb +63 -0
  80. data/lib/gooddata/models/columns/fact_model.rb +54 -0
  81. data/lib/gooddata/models/columns/label.rb +55 -0
  82. data/lib/gooddata/models/columns/reference.rb +57 -0
  83. data/lib/gooddata/models/dashboard_builder.rb +26 -0
  84. data/lib/gooddata/models/data_result.rb +10 -9
  85. data/lib/gooddata/models/domain.rb +131 -0
  86. data/lib/gooddata/models/empty_result.rb +5 -8
  87. data/lib/gooddata/models/facts/facts.rb +8 -0
  88. data/lib/gooddata/models/facts/time_fact.rb +20 -0
  89. data/lib/gooddata/models/folders/attribute_folder.rb +20 -0
  90. data/lib/gooddata/models/folders/fact_folder.rb +20 -0
  91. data/lib/gooddata/models/folders/folders.rb +8 -0
  92. data/lib/gooddata/models/invitation.rb +78 -0
  93. data/lib/gooddata/models/links.rb +6 -6
  94. data/lib/gooddata/models/md_object.rb +25 -0
  95. data/lib/gooddata/models/metadata.rb +160 -62
  96. data/lib/gooddata/models/metadata/attribute.rb +81 -0
  97. data/lib/gooddata/models/metadata/column.rb +61 -0
  98. data/lib/gooddata/models/{dashboard.rb → metadata/dashboard.rb} +12 -7
  99. data/lib/gooddata/models/{data_set.rb → metadata/data_set.rb} +5 -4
  100. data/lib/gooddata/models/metadata/date_dimension.rb +26 -0
  101. data/lib/gooddata/models/metadata/display_form.rb +61 -0
  102. data/lib/gooddata/models/metadata/fact.rb +36 -0
  103. data/lib/gooddata/models/metadata/folder.rb +24 -0
  104. data/lib/gooddata/models/metadata/metadata.rb +8 -0
  105. data/lib/gooddata/models/metadata/metric.rb +197 -0
  106. data/lib/gooddata/models/metadata/report.rb +115 -0
  107. data/lib/gooddata/models/{report_definition.rb → metadata/report_definition.rb} +16 -10
  108. data/lib/gooddata/models/metadata/schema.rb +227 -0
  109. data/lib/gooddata/models/model.rb +38 -1339
  110. data/lib/gooddata/models/models.rb +5 -2
  111. data/lib/gooddata/models/module_constants.rb +29 -0
  112. data/lib/gooddata/models/process.rb +142 -13
  113. data/lib/gooddata/models/profile.rb +4 -6
  114. data/lib/gooddata/models/project.rb +406 -136
  115. data/lib/gooddata/models/project_blueprint.rb +221 -0
  116. data/lib/gooddata/models/project_builder.rb +136 -0
  117. data/lib/gooddata/models/project_creator.rb +138 -0
  118. data/lib/gooddata/models/project_metadata.rb +11 -10
  119. data/lib/gooddata/models/project_role.rb +92 -0
  120. data/lib/gooddata/models/references/date_reference.rb +44 -0
  121. data/lib/gooddata/models/references/references.rb +8 -0
  122. data/lib/gooddata/models/references/time_reference.rb +13 -0
  123. data/lib/gooddata/models/report_data_result.rb +11 -11
  124. data/lib/gooddata/models/schedule.rb +284 -0
  125. data/lib/gooddata/models/schema_blueprint.rb +158 -0
  126. data/lib/gooddata/models/schema_builder.rb +81 -0
  127. data/lib/gooddata/models/tab_builder.rb +23 -0
  128. data/lib/gooddata/models/user.rb +165 -0
  129. data/lib/gooddata/version.rb +1 -1
  130. data/lib/templates/project/data/devs.csv +1 -1
  131. data/lib/templates/project/data/repos.csv +1 -1
  132. data/lib/templates/project/model/model.rb.erb +7 -11
  133. data/spec/bricks/bricks_spec.rb +2 -0
  134. data/spec/data/test-ci-data.csv +2 -0
  135. data/spec/data/test_project_model_spec.json +7 -27
  136. data/spec/helpers/blueprint_helper.rb +2 -0
  137. data/spec/helpers/cli_helper.rb +2 -0
  138. data/spec/helpers/connection_helper.rb +14 -1
  139. data/spec/helpers/project_helper.rb +16 -0
  140. data/spec/helpers/schema_helper.rb +16 -0
  141. data/spec/integration/command_projects_spec.rb +7 -7
  142. data/spec/integration/create_from_template_spec.rb +2 -2
  143. data/spec/integration/full_project_spec.rb +160 -7
  144. data/spec/integration/partial_md_export_import_spec.rb +3 -3
  145. data/spec/logging_in_logging_out_spec.rb +2 -1
  146. data/spec/spec_helper.rb +26 -4
  147. data/spec/unit/bricks/bricks_spec.rb +15 -7
  148. data/spec/unit/bricks/middleware/bench_middleware_spec.rb +2 -0
  149. data/spec/unit/bricks/middleware/bulk_salesforce_middleware_spec.rb +2 -0
  150. data/spec/unit/bricks/middleware/gooddata_middleware_spec.rb +2 -0
  151. data/spec/unit/bricks/middleware/logger_middleware_spec.rb +2 -0
  152. data/spec/unit/bricks/middleware/restforce_middleware_spec.rb +2 -0
  153. data/spec/unit/bricks/middleware/stdout_middleware_spec.rb +2 -0
  154. data/spec/unit/bricks/middleware/twitter_middleware_spec.rb +2 -0
  155. data/spec/unit/cli/cli_spec.rb +2 -0
  156. data/spec/unit/cli/commands/cmd_api_spec.rb +23 -15
  157. data/spec/unit/cli/commands/cmd_auth_spec.rb +8 -4
  158. data/spec/unit/cli/commands/cmd_domain_spec.rb +82 -0
  159. data/spec/unit/cli/commands/cmd_process_spec.rb +29 -13
  160. data/spec/unit/cli/commands/cmd_project_spec.rb +51 -30
  161. data/spec/unit/cli/commands/cmd_role_spec.rb +44 -0
  162. data/spec/unit/cli/commands/cmd_run_ruby_spec.rb +8 -4
  163. data/spec/unit/cli/commands/cmd_scaffold_spec.rb +48 -11
  164. data/spec/unit/cli/commands/cmd_user_spec.rb +29 -0
  165. data/spec/unit/commands/command_api_spec.rb +1 -1
  166. data/spec/unit/commands/command_auth_spec.rb +100 -18
  167. data/spec/unit/commands/command_dataset_spec.rb +4 -0
  168. data/spec/unit/commands/command_process_spec.rb +9 -4
  169. data/spec/unit/commands/command_projects_spec.rb +10 -6
  170. data/spec/unit/commands/command_scaffold_spec.rb +5 -1
  171. data/spec/unit/commands/command_user_spec.rb +22 -0
  172. data/spec/unit/core/connection_spec.rb +35 -6
  173. data/spec/unit/core/logging_spec.rb +65 -0
  174. data/spec/unit/core/nil_logger_spec.rb +9 -0
  175. data/spec/unit/core/project_spec.rb +51 -0
  176. data/spec/unit/core/rest_spec.rb +33 -0
  177. data/spec/unit/data/guesser_spec.rb +5 -0
  178. data/spec/unit/godzilla/goodzilla_spec.rb +2 -0
  179. data/spec/unit/models/account_settings_spec.rb +28 -0
  180. data/spec/unit/models/anchor_spec.rb +32 -0
  181. data/spec/unit/models/attribute_column_spec.rb +7 -0
  182. data/spec/unit/models/domain_spec.rb +45 -0
  183. data/spec/unit/models/invitation_spec.rb +13 -0
  184. data/spec/unit/models/md_object_spec.rb +47 -0
  185. data/spec/unit/models/metric.rb +92 -0
  186. data/spec/unit/{model → models}/model_spec.rb +9 -7
  187. data/spec/unit/models/project_blueprint_spec.rb +202 -0
  188. data/spec/unit/models/project_creator.rb +73 -0
  189. data/spec/unit/models/project_role_spec.rb +90 -0
  190. data/spec/unit/models/project_spec.rb +143 -0
  191. data/spec/unit/models/schedule_spec.rb +491 -0
  192. data/spec/unit/{model → models}/schema_builder_spec.rb +2 -0
  193. data/spec/unit/{model → models}/tools_spec.rb +13 -7
  194. data/spec/unit/models/user_spec.rb +16 -0
  195. data/test/test_upload.rb +2 -0
  196. metadata +189 -86
  197. data/lib/gooddata/commands/profile.rb +0 -11
  198. data/lib/gooddata/models/attribute.rb +0 -29
  199. data/lib/gooddata/models/display_form.rb +0 -9
  200. data/lib/gooddata/models/fact.rb +0 -19
  201. data/lib/gooddata/models/metric.rb +0 -99
  202. data/lib/gooddata/models/report.rb +0 -89
  203. data/spec/data/blueprint_valid.json +0 -37
  204. data/spec/unit/cli/commands/cmd_profile_spec.rb +0 -16
  205. data/spec/unit/commands/command_profile_spec.rb +0 -18
  206. data/spec/unit/core/core_spec.rb +0 -7
  207. data/spec/unit/model/blueprint_spec.rb +0 -132
  208. data/spec/unit/model/project_blueprint_spec.rb +0 -44
@@ -1,32 +1,22 @@
1
1
  # encoding: UTF-8
2
2
 
3
+ require 'pathname'
3
4
  require 'pp'
4
5
 
5
6
  require_relative '../shared'
6
- require_relative '../../commands/projects'
7
+ require_relative '../../commands/project'
7
8
 
8
9
  GoodData::CLI.module_eval do
9
10
 
10
- desc 'Manage your projects'
11
+ desc 'Manage your project'
11
12
  arg_name 'project_command'
12
13
  command :project do |c|
13
-
14
- c.desc "Lists user's projects"
15
- c.command :list do |list|
16
- list.action do |global_options, options, args|
17
- opts = options.merge(global_options)
18
- GoodData.connect(opts)
19
- list = GoodData::Command::Projects.list()
20
- puts list.map { |p| [p.uri, p.title].join(',') }
21
- end
22
- end
23
-
24
14
  c.desc 'If you are in a gooddata project blueprint or if you provide a project id it will start an interactive session inside that project'
25
15
  c.command :jack_in do |jack|
26
16
  jack.action do |global_options, options, args|
27
17
  goodfile_path = GoodData::Helpers.find_goodfile(Pathname('.'))
28
18
 
29
- spin_session = Proc.new do |goodfile, blueprint|
19
+ spin_session = proc do |goodfile, blueprint|
30
20
  project_id = global_options[:project_id] || goodfile[:project_id]
31
21
  fail "You have to provide 'project_id'. You can either provide it through -p flag or even better way is to fill it in in your Goodfile under key \"project_id\". If you just started a project you have to create it first. One way might be through \"gooddata project build\"" if project_id.nil? || project_id.empty?
32
22
 
@@ -37,11 +27,11 @@ GoodData::CLI.module_eval do
37
27
  GoodData.with_project(project_id) do |project|
38
28
  puts "Use 'exit' to quit the live session. Use 'q' to jump out of displaying a large output."
39
29
  binding.pry(:quiet => true,
40
- :prompt => [proc { |target_self, nest_level, pry|
30
+ :prompt => [proc do |target_self, nest_level, pry|
41
31
  'project_live_sesion: '
42
- }])
32
+ end])
43
33
  end
44
- rescue GoodData::ProjectNotFound => e
34
+ rescue GoodData::ProjectNotFound
45
35
  puts "Project with id \"#{project_id}\" could not be found. Make sure that the id you provided is correct."
46
36
  end
47
37
  end
@@ -50,7 +40,7 @@ GoodData::CLI.module_eval do
50
40
  goodfile = MultiJson.load(File.read(goodfile_path), :symbolize_keys => true)
51
41
  model_key = goodfile[:model]
52
42
  blueprint = GoodData::Model::ProjectBlueprint.new(eval(File.read(model_key)).to_hash) if File.exist?(model_key) && !File.directory?(model_key)
53
- FileUtils::cd(goodfile_path.dirname) do
43
+ FileUtils.cd(goodfile_path.dirname) do
54
44
  spin_session.call(goodfile, blueprint)
55
45
  end
56
46
  else
@@ -59,6 +49,7 @@ GoodData::CLI.module_eval do
59
49
  end
60
50
  end
61
51
 
52
+ # TODO: Move away the ask methods. Provide params
62
53
  c.desc 'Create a gooddata project'
63
54
  c.command :create do |create|
64
55
  create.action do |global_options, options, args|
@@ -69,12 +60,12 @@ GoodData::CLI.module_eval do
69
60
 
70
61
  opts = options.merge(global_options)
71
62
  GoodData.connect(opts)
72
- project = GoodData::Command::Projects.create({
73
- :title => title,
74
- :summary => summary,
75
- :template => template,
76
- :token => token
77
- })
63
+ project = GoodData::Command::Project.create(
64
+ :title => title,
65
+ :summary => summary,
66
+ :template => template,
67
+ :token => token
68
+ )
78
69
  puts "Project '#{project.title}' with id #{project.uri} created successfully!"
79
70
  end
80
71
  end
@@ -85,24 +76,69 @@ GoodData::CLI.module_eval do
85
76
  id = global_options[:project_id]
86
77
  opts = options.merge(global_options)
87
78
  GoodData.connect(opts)
88
- GoodData::Command::Projects.delete(id)
79
+ GoodData::Command::Project.delete(id)
89
80
  end
90
81
  end
91
82
 
92
83
  c.desc 'Clones a project. Useful for testing'
93
84
  c.command :clone do |clone|
94
85
  clone.desc 'Name of the new project'
86
+
95
87
  clone.default_value nil
96
88
  clone.arg_name 'cloned_project_name'
97
- clone.flag [:n, :name]
89
+ clone.flag [:t, :title]
90
+
91
+ clone.default_value false
92
+ clone.switch [:u, :users]
93
+
94
+ clone.default_value true
95
+ clone.switch [:d, :data]
98
96
 
99
97
  clone.action do |global_options, options, args|
98
+ opts = options.merge(global_options)
100
99
  id = global_options[:project_id]
101
- name = options[:name]
102
- token = options[:token]
100
+ token = opts[:token]
101
+
102
+ fail 'You have to provide a token for creating a project. Please use parameter --token' if token.nil? || token.empty?
103
+
104
+ GoodData.connect(opts)
105
+ GoodData::Command::Project.clone(id, opts)
106
+ end
107
+ end
108
+
109
+ c.desc 'Invites user to project'
110
+ c.command :invite do |store|
111
+ store.action do |global_options, options, args|
112
+ project_id = global_options[:project_id]
113
+ fail 'Project ID has to be provided' if project_id.nil? || project_id.empty?
114
+
115
+ email = args.first
116
+ fail 'Email of user to be invited has to be provided' if email.nil? || email.empty?
117
+
118
+ role = args[1]
119
+ fail 'Role name has to be provided' if role.nil? || role.empty?
120
+
121
+ msg = args[2]
122
+ msg = GoodData::Command::Project::DEFAULT_INVITE_MESSAGE if msg.nil? || msg.empty?
123
+
124
+ opts = options.merge(global_options)
125
+ GoodData.connect(opts)
126
+
127
+ GoodData::Command::Project.invite(project_id, email, role, msg)
128
+ end
129
+ end
130
+
131
+ c.desc 'List users'
132
+ c.command :users do |list|
133
+ list.action do |global_options, options, args|
103
134
  opts = options.merge(global_options)
104
135
  GoodData.connect(opts)
105
- GoodData::Command::Projects.clone(id, :name => name, :token => token)
136
+
137
+ pid = global_options[:project_id]
138
+ fail 'Project ID has to be provided' if pid.nil? || pid.empty?
139
+
140
+ user_list = GoodData::Command::Project.users(pid)
141
+ puts user_list.map { |u| [u[:last_name], u[:first_name], u[:login], u[:uri]].join(',') }
106
142
  end
107
143
  end
108
144
 
@@ -112,7 +148,7 @@ GoodData::CLI.module_eval do
112
148
  id = global_options[:project_id]
113
149
  opts = options.merge(global_options)
114
150
  GoodData.connect(opts)
115
- p = GoodData::Command::Projects.show(id)
151
+ p = GoodData::Command::Project.show(id)
116
152
  pp p.data
117
153
  end
118
154
  end
@@ -122,8 +158,8 @@ GoodData::CLI.module_eval do
122
158
  show.action do |global_options, options, args|
123
159
  opts = options.merge(global_options)
124
160
  GoodData.connect(opts)
125
- spec, project_id = GoodData::Command::Projects.get_spec_and_project_id('.')
126
- new_project = GoodData::Command::Projects.build(opts.merge(:spec => spec))
161
+ spec, _ = GoodData::Command::Project.get_spec_and_project_id('.')
162
+ new_project = GoodData::Command::Project.build(opts.merge(:spec => spec))
127
163
  puts "Project was created. New project PID is #{new_project.pid}, URI is #{new_project.uri}."
128
164
  end
129
165
  end
@@ -134,12 +170,36 @@ GoodData::CLI.module_eval do
134
170
 
135
171
  opts = options.merge(global_options)
136
172
  GoodData.connect(opts)
137
- spec, project_id = GoodData::Command::Projects.get_spec_and_project_id('.')
138
- project = GoodData::Command::Projects.update(opts.merge(:spec => spec, :project_id => global_options[:project_id] || project_id))
173
+ spec, project_id = GoodData::Command::Project.get_spec_and_project_id('.')
174
+ project_id = global_options[:project_id] || project_id
175
+ fail 'You have to provide "project_id". You can either provide it through -p flag or even better way is to fill it in in your Goodfile under key "project_id". If you just started a project you have to create it first. One way might be through "gooddata project build"' if project_id.nil? || project_id.empty?
176
+ project = GoodData::Command::Project.update(opts.merge(:spec => spec, :project_id => project_id))
139
177
  puts "Migration was done. Project PID is #{project.pid}, URI is #{project.uri}."
178
+ end
179
+ end
180
+
181
+ c.desc 'Roles'
182
+ c.command :roles do |roles|
183
+ roles.action do |global_options, options, args|
184
+ project_id = global_options[:project_id]
185
+ fail 'Project ID has to be provided' if project_id.nil? || project_id.empty?
140
186
 
187
+ opts = options.merge(global_options)
188
+ GoodData.connect(opts)
189
+
190
+ roles = GoodData::Command::Project.roles(project_id)
191
+
192
+ puts roles.map { |r| [r['url'], r['role']['projectRole']['meta']['title']].join(',') }
141
193
  end
142
194
  end
143
- end
144
195
 
145
- end
196
+ c.desc 'You can run project validation which will check RI integrity and other problems.'
197
+ c.command :validate do |show|
198
+ show.action do |global_options, options, args|
199
+ opts = options.merge(global_options)
200
+ GoodData.connect(opts)
201
+ pp GoodData::Command::Project.validate(global_options[:project_id])
202
+ end
203
+ end
204
+ end
205
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: UTF-8
2
+
3
+ require_relative '../shared'
4
+ require_relative '../../commands/projects'
5
+
6
+ GoodData::CLI.module_eval do
7
+
8
+ desc 'Manage your projects'
9
+ command :projects do |c|
10
+
11
+ c.desc "Lists user's projects"
12
+ c.command :list do |list|
13
+ list.action do |global_options, options, args|
14
+ opts = options.merge(global_options)
15
+ GoodData.connect(opts)
16
+ list = GoodData::Command::Projects.list
17
+ puts list.map { |p| [p.uri, p.title].join(',') }
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,28 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'pp'
4
+
5
+ require_relative '../shared'
6
+ require_relative '../../commands/role'
7
+
8
+ GoodData::CLI.module_eval do
9
+ desc 'Basic Role Management'
10
+ arg_name 'list'
11
+ command :role do |c|
12
+ c.desc 'List roles'
13
+ c.command :list do |list|
14
+ list.action do |global_options, options, args|
15
+ opts = options.merge(global_options)
16
+ GoodData.connect(opts)
17
+
18
+ pid = global_options[:project_id]
19
+ fail 'Project ID has to be provided' if pid.nil? || pid.empty?
20
+
21
+ role_list = GoodData::Command::Role.list(pid)
22
+ role_list.each do |k, v|
23
+ puts [k, v[:uri]].join(',')
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -34,24 +34,24 @@ GoodData::CLI.module_eval do
34
34
 
35
35
  c.action do |global_options, options, args|
36
36
  verbose = global_options[:verbose]
37
- options[:expanded_params] = if (options[:params])
37
+ options[:expanded_params] = if options[:params]
38
38
  MultiJson.load(File.read(options[:params]))
39
39
  else
40
40
  {}
41
41
  end
42
42
 
43
- opts = options.merge(global_options).merge({:type => 'RUBY'})
43
+ opts = options.merge(global_options).merge(:type => 'RUBY')
44
44
  GoodData.connect(opts)
45
45
  if options[:remote]
46
46
  fail 'You have to specify name of the deploy when deploying remotely' if options[:name].nil? || options[:name].empty?
47
47
  require_relative '../../commands/process'
48
- GoodData::Command::Process.run(options[:dir], opts)
48
+ GoodData::Command::Process.run(options[:dir], './main.rb', opts)
49
49
  else
50
50
  require_relative '../../commands/runners'
51
51
  GoodData::Command::Runners.run_ruby_locally(options[:dir], opts)
52
52
  end
53
- puts HighLine::color('Running ruby brick - DONE', HighLine::GREEN) if verbose
53
+ puts HighLine.color('Running ruby brick - DONE', HighLine::GREEN) if verbose
54
54
  end
55
55
  end
56
56
 
57
- end
57
+ end
@@ -31,4 +31,4 @@ GoodData::CLI.module_eval do
31
31
  end
32
32
  end
33
33
 
34
- end
34
+ end
@@ -1,24 +1,22 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require 'pp'
4
-
5
3
  require_relative '../shared'
6
- require_relative '../../commands/profile'
4
+ require_relative '../../commands/project'
5
+ require_relative '../../commands/role'
6
+ require_relative '../../commands/user'
7
7
 
8
8
  GoodData::CLI.module_eval do
9
9
 
10
- desc 'Describe add here'
11
- arg_name 'show'
12
- command :profile do |c|
13
-
10
+ desc 'User management'
11
+ command :user do |c|
14
12
  c.desc 'Show your profile'
15
13
  c.command :show do |show|
16
14
  show.action do |global_options, options, args|
17
15
  opts = options.merge(global_options)
18
16
  GoodData.connect(opts)
19
- pp GoodData::Command::Profile.show()
17
+ pp GoodData::Command::User.show
20
18
  end
21
19
  end
22
20
  end
23
21
 
24
- end
22
+ end
@@ -3,6 +3,7 @@
3
3
  require 'gli'
4
4
 
5
5
  require_relative '../version'
6
+ require_relative '../core/core'
6
7
 
7
8
  include GLI::App
8
9
 
@@ -28,7 +29,7 @@ GoodData::CLI.module_eval do
28
29
  flag [:p, :project_id]
29
30
 
30
31
  desc 'Server'
31
- default_value nil
32
+ default_value GoodData::Connection::DEFAULT_URL
32
33
  arg_name 'server'
33
34
  flag [:s, :server]
34
35
 
@@ -50,4 +51,4 @@ GoodData::CLI.module_eval do
50
51
  arg_name 'logger'
51
52
  switch [:l, :logger]
52
53
 
53
- end
54
+ end
@@ -1,30 +1,12 @@
1
1
  # encoding: UTF-8
2
2
 
3
+ require 'csv'
4
+
3
5
  require_relative 'version'
4
6
  require_relative 'connection'
5
7
  require_relative 'helpers'
6
8
 
7
- # fastercsv is built in Ruby 1.9
8
- if RUBY_VERSION < '1.9'
9
- require 'fastercsv'
10
- else
11
- require 'csv'
12
- FasterCSV = CSV
13
- end
14
-
15
- # Initializes required dynamically loaded classes
16
- def init_gd_module()
17
- # Metadata packages, such as report.rb, require this to be loaded first
18
- require_relative 'models/metadata.rb'
19
-
20
- # Load models from models folder
21
- Dir[File.dirname(__FILE__) + '/models/*.rb'].each { |file| require file }
22
-
23
- # Load collections
24
- Dir[File.dirname(__FILE__) + '/collections/*.rb'].each { |file| require file }
25
- end
26
-
27
- init_gd_module()
9
+ FasterCSV = CSV
28
10
 
29
11
  # # GoodData API wrapper
30
12
  #
@@ -53,301 +35,31 @@ init_gd_module()
53
35
  #
54
36
  # For details about the logger options and methods, see the
55
37
  # (Logger module documentation)[http://www.ruby-doc.org/stdlib/libdoc/logger/rdoc].
56
- #
57
- module GoodData
58
- module Threaded
59
- # Used internally for thread safety
60
- def threaded
61
- Thread.current[:goooddata] ||= {}
62
- end
63
- end
64
-
65
- # Dummy implementation of logger
66
- class NilLogger
67
- def debug(*args)
68
- ;
69
- end
70
-
71
- alias :info :debug
72
- alias :warn :debug
73
- alias :error :debug
74
- end
75
-
76
- # Assigns global/default GoodData project
77
- def project=(project)
78
- GoodData.project = project
79
- GoodData.project
80
- end
81
38
 
82
- alias :use :project=
39
+ require_relative 'core/core'
83
40
 
41
+ module GoodData
84
42
  class << self
85
- include Threaded
86
-
87
43
  RELEASE_INFO_PATH = '/gdc/releaseInfo'
88
44
 
89
- # Connect to the GoodData API
90
- #
91
- # @param options
92
- # @param second_options
93
- # @param third_options
94
- #
95
- def connect(options=nil, second_options=nil, third_options={})
96
- if options.is_a? Hash
97
- fail 'You have to provide login and password' if ((options[:login].nil? || options[:login].empty?) && (options[:password].nil? || options[:password].empty?))
98
- threaded[:connection] = Connection.new(options[:login], options[:password], options)
99
- GoodData.project = options[:project] if options[:project]
100
- elsif options.is_a?(String) && second_options.is_a?(String)
101
- fail 'You have to provide login and password' if ((options.nil? || options.empty?) && (second_options.nil? || second_options.empty?))
102
- threaded[:connection] = Connection.new(options, second_options, third_options)
103
- end
45
+ # Initializes required dynamically loaded classes
46
+ def init_module
47
+ # Metadata packages, such as report.rb, require this to be loaded first
48
+ require_relative 'models/metadata.rb'
104
49
 
105
- return threaded[:connection]
106
- end
107
-
108
- # Disconnect (logout) if logged in
109
- def disconnect
110
- if threaded[:connection]
111
- threaded[:connection].disconnect
112
- threaded[:connection] = nil
113
- end
114
- end
50
+ # Load models from models folder
51
+ Dir[File.dirname(__FILE__) + '/models/*.rb'].each { |file| require file }
115
52
 
116
- # Turn logging on
117
- def logging_on
118
- if logger.is_a? NilLogger
119
- GoodData::logger = Logger.new(STDOUT)
120
- end
121
- end
122
-
123
- # Turn logging off
124
- def logging_off
125
- GoodData::logger = NilLogger.new
126
- end
127
-
128
-
129
- # Hepler for starting with SST easier
130
- #
131
- # @param token SST token
132
- # @param options Options get routed to connect eventually so everything that you can use there should be possible to use here.
133
- #
134
- def connect_with_sst(token, options={})
135
- create_authenticated_connection(options.merge({:cookies => {'GDCAuthSST' => token}}))
136
- end
137
-
138
- # This method is aimed at creating an authenticated connection in case you do not hae pass/login but you have SST
139
- #
140
- # @param options :server => optional GD server uri, If nil it secure will be used. :cookies => you can specify a hash of cookies
141
- #
142
- def create_authenticated_connection(options={})
143
- connect(options)
144
- server_cookies = options[:cookies]
145
- connection.merge_cookies!(server_cookies)
146
- connection.status = :logged_in
147
- connection
148
- end
149
-
150
- # Perform block in context of another project than currently set
151
- #
152
- # @param project Project to use
153
- # @param bl Block to be performed
154
- def with_project(project, &bl)
155
- fail 'You have to specify a project when using with_project' if project.nil? || (project.is_a?(String) && project.empty?)
156
- old_project = GoodData.project
157
- begin
158
- GoodData.use(project)
159
- bl.call(GoodData.project)
160
- rescue RestClient::ResourceNotFound => e
161
- fail GoodData::ProjectNotFound.new(e)
162
- ensure
163
- GoodData.project = old_project
164
- end
165
- end
166
-
167
- # Returns the active GoodData connection earlier initialized via GoodData.connect call
168
- #
169
- # @see GoodData.connect
170
- def connection
171
- threaded[:connection] || raise('Please authenticate with GoodData.connect first')
172
- end
173
-
174
- # Sets the active project
175
- #
176
- # @param project A project identifier
177
- #
178
- # ### Examples
179
- #
180
- # The following calls are equivalent
181
- #
182
- # # Assign project ID
183
- # GoodData.project = 'afawtv356b6usdfsdf34vt'
184
- #
185
- # # Use project ID
186
- # GoodData.use 'afawtv356b6usdfsdf34vt'
187
- #
188
- # # Use project URL
189
- # GoodData.use '/gdc/projects/afawtv356b6usdfsdf34vt'
190
- #
191
- # # Select project using indexer on GoodData::Project class
192
- # GoodData.project = Project['afawtv356b6usdfsdf34vt']
193
- #
194
- def project=(project)
195
- if project.is_a? Project
196
- threaded[:project] = project
197
- elsif project.nil?
198
- threaded[:project] = nil
199
- else
200
- threaded[:project] = Project[project]
201
- end
202
- end
203
-
204
- alias :use :project=
205
-
206
- # Returns the active project
207
- #
208
- def project
209
- threaded[:project]
210
- end
211
-
212
- # Performs a HTTP GET request.
213
- #
214
- # Retuns the JSON response formatted as a Hash object.
215
- #
216
- # @param path The HTTP path on the GoodData server (must be prefixed with a forward slash)
217
- #
218
- # ### Examples
219
- #
220
- # GoodData.get '/gdc/projects'
221
- #
222
- def get(path, options = {})
223
- connection.get(path, options)
224
- end
225
-
226
- # Performs a HTTP POST request.
227
- #
228
- # Retuns the JSON response formatted as a Hash object.
229
- #
230
- # @param path The HTTP path on the GoodData server (must be prefixed with a forward slash)
231
- # @param data The payload data in the format of a Hash object
232
- #
233
- # ### Examples
234
- #
235
- # GoodData.post '/gdc/projects', { ... }
236
- #
237
- def post(path, data, options = {})
238
- connection.post path, data, options
239
- end
240
-
241
- # Performs a HTTP PUT request.
242
- #
243
- # Retuns the JSON response formatted as a Hash object.
244
- #
245
- # ### Parameters
246
- #
247
- # @param path The HTTP path on the GoodData server (must be prefixed with a forward slash)
248
- # @param data The payload data in the format of a Hash object
249
- #
250
- # ### Examples
251
- #
252
- # GoodData.put '/gdc/projects', { ... }
253
- #
254
- def put(path, data, options = {})
255
- connection.put path, data, options
256
- end
257
-
258
- # Performs a HTTP DELETE request.
259
- #
260
- # Retuns the JSON response formatted as a Hash object.
261
- #
262
- # @param path The HTTP path on the GoodData server (must be prefixed with a forward slash)
263
- #
264
- # ### Examples
265
- #
266
- # GoodData.delete '/gdc/project/1'
267
- #
268
- def delete(path, options = {})
269
- connection.delete path, options
270
- end
271
-
272
- def upload_to_user_webdav(file, options={})
273
- u = URI(connection.options[:webdav_server] || GoodData.project.links['uploads'])
274
- url = URI.join(u.to_s.chomp(u.path.to_s), '/uploads/')
275
- connection.upload(file, options.merge({
276
- :directory => options[:directory],
277
- :staging_url => url
278
- }))
279
- end
280
-
281
- def get_project_webdav_path(file, options={})
282
- u = URI(connection.options[:webdav_server] || GoodData.project.links["uploads"])
283
- url = URI.join(u.to_s.chomp(u.path.to_s), "/project-uploads/", "#{GoodData.project.pid}/")
284
- end
285
-
286
- def upload_to_project_webdav(file, options={})
287
- url = get_project_webdav_path(file, options)
288
- connection.upload(file, options.merge({
289
- :directory => options[:directory],
290
- :staging_url => url
291
- }))
292
- end
293
-
294
- def get_user_webdav_path(file, options={})
295
- u = URI(connection.options[:webdav_server] || GoodData.project.links["uploads"])
296
- url = URI.join(u.to_s.chomp(u.path.to_s), "/uploads/")
297
- end
298
-
299
- def download_from_user_webdav(file, where, options={})
300
- url = get_user_webdav_path(file, options)
301
- connection.download(file, where, options.merge({
302
- :staging_url => url
303
- }))
304
- end
305
-
306
- def poll(result, key, options={})
307
- sleep_interval = options[:sleep_interval] || 10
308
- link = result[key]['links']['poll']
309
- response = GoodData.get(link, :process => false)
310
- while response.code != 204
311
- sleep sleep_interval
312
- GoodData.connection.retryable(:tries => 3, :on => RestClient::InternalServerError) do
313
- sleep sleep_interval
314
- response = GoodData.get(link, :process => false)
315
- end
316
- end
317
- end
318
-
319
- def test_login
320
- connection.connect!
321
- connection.logged_in?
322
- end
323
-
324
- # Returns the currently logged in user Profile.
325
- def profile
326
- threaded[:profile] ||= Profile.load
53
+ # Load collections
54
+ Dir[File.dirname(__FILE__) + '/collections/*.rb'].each { |file| require file }
327
55
  end
328
56
 
329
57
  # Returns information about the GoodData API as a Hash (e.g. version, release time etc.)
330
58
  def release_info
331
59
  @release_info ||= @connection.get(RELEASE_INFO_PATH)['release']
332
60
  end
333
-
334
- # Returns the logger instance. The default implementation
335
- # does not log anything
336
- # For some serious logging, set the logger instance using
337
- # the logger= method
338
- #
339
- # ### Example
340
- #
341
- # require 'logger'
342
- # GoodData.logger = Logger.new(STDOUT)
343
- #
344
- def logger
345
- @logger ||= NilLogger.new
346
- end
347
-
348
- # Sets the logger instance
349
- def logger=(logger)
350
- @logger = logger
351
- end
352
61
  end
353
62
  end
63
+
64
+ # Init requires
65
+ GoodData.init_module