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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 143aa38816bd648dc9f03a63e2453432ccf2581f
4
+ data.tar.gz: 3e5d3940d94a67474d14400def5addfc0e91e92a
5
+ SHA512:
6
+ metadata.gz: 793043d0ffccb3d565b6c5458b2a7a6358acd77995e4a3fb9302dea6c85ea2c6193f69487f0b63392caaafb501149203b754a4bf62a82c5db7231a092a97ee20
7
+ data.tar.gz: e2814af4b8916f9a1b25fe34938ac3955b43418385a8495fff639ccd436006a3a66042d668a1f51fb7b819d2c86eb28048cd9e0fc3feb9fdc290102e35284354
data/.autotest ADDED
@@ -0,0 +1,2 @@
1
+ # Customize autotest behavior here
2
+
data/.gitignore CHANGED
@@ -24,3 +24,6 @@ pkg
24
24
 
25
25
  ## PROJECT::SPECIFIC
26
26
  Gemfile.lock
27
+
28
+ # YARD
29
+ .yardoc/
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.1.0
5
+ - ruby-head
6
+
7
+ script: rake test:unit
data/.yardopts CHANGED
@@ -1,3 +1,5 @@
1
+ --template-path doc/templates
2
+ --plugin rspec
1
3
  --protected
2
4
  --no-private
3
5
  --verbose
@@ -10,10 +12,9 @@
10
12
  --hide-void-return
11
13
  --exclude LICENSE
12
14
  --output-dir doc/html
13
- --template-path doc/templates
14
15
  lib/**/*.rb
15
16
  ext/**/*{.m,.c}
16
- spec/**/*.rb
17
+ spec/**/*_spec.rb
17
18
  -
18
19
  README.md
19
20
  doc/pages/**/*.md
data/README.md CHANGED
@@ -1,10 +1,11 @@
1
- # GoodData Ruby wrapper and CLI
1
+ # GoodData API Ruby wrapper and CLI
2
2
 
3
3
  A convenient Ruby wrapper around the GoodData RESTful API. The gem comes in two flavors.
4
4
  It has a CLI client and it is a library which you can integrate into your application.
5
5
 
6
6
  The best documentation for the GoodData API can be found using these resources:
7
7
 
8
+ * sdk.gooddata.com/gooddata-ruby/
8
9
  * http://docs.gooddata.apiary.io/
9
10
  * http://developer.gooddata.com/api
10
11
  * https://secure.gooddata.com/gdc
@@ -14,16 +15,17 @@ The best documentation for the GoodData API can be found using these resources:
14
15
  [![Gem Version](https://badge.fury.io/rb/gooddata.png)](http://badge.fury.io/rb/gooddata)
15
16
  [![Dependency Status](https://gemnasium.com/gooddata/gooddata-ruby.png)](https://gemnasium.com/gooddata/gooddata-ruby)
16
17
  [![Code Climate](https://codeclimate.com/github/gooddata/gooddata-ruby.png)](https://codeclimate.com/github/gooddata/gooddata-ruby)
18
+ [![Build Status](https://travis-ci.org/korczis/gooddata-ruby.png?branch=refactor)](https://travis-ci.org/korczis/gooddata-ruby)
17
19
 
18
20
  ## Install
19
21
 
20
- If you are using bundler. Add
22
+ If you are using bundler. Add
21
23
 
22
24
  gem "gooddata"
23
25
 
24
- into Gemfile
26
+ into Gemfile
25
27
 
26
- and run
28
+ and run
27
29
 
28
30
  bundle install
29
31
 
@@ -31,145 +33,6 @@ If you are using gems just
31
33
 
32
34
  gem install gooddata
33
35
 
34
-
35
- ### Library usage
36
-
37
-
38
- In its most simple form GoodData gem just cares about the logging in and juggling the tokens that are needed for you to retrive information. It provides you the usual HTTP methods that you are used to. Couple of examples.
39
-
40
- #### Authentiacation
41
-
42
- GoodData.connect("login", "pass")
43
-
44
- # Different server than the usual secure.gooddata.com
45
- GoodData.connect("login", "pass", "https://different.server.gooddata.com")
46
-
47
- # the last argument is passed to underlying RestClient so you can specify other useful stuff there
48
- GoodData.connect("login", "pass", "https://different.server.gooddata.com", :timeout => 0)
49
-
50
-
51
- #### Basic requests
52
-
53
- GoodData.get("/gdc/md")
54
-
55
- # This post will not actually work it is just for the illustration
56
- GoodData.post("/gdc/md/#{project_id}", {:my_object => "some_date"})
57
-
58
- # The same goes for put delete.
59
- # By default the response is decoded for you as json but sometimes you do not want that png or other stuff.
60
- # You will get the response object and you can query it further.
61
- response = GoodData.get("/gdc/md", :process => false)
62
- response.code == 400
63
- pp response.body
64
-
65
- #### Loading of data
66
-
67
- This library is able to load data but it is not used that much if at all. Since there is some data processing needed on the client side we rely on faster implementations in Java usually. Let us know if you would be interested. As the APIs improve we could bring it back.
68
-
69
- #### Other stuff
70
-
71
- The API is currently a little fragmented and we never had the guts to actually deal with all the ugliness and present nice object oriented API. Usually it is just better to deal with the ugly json as hashes. But there are couple of exceptions where we needed something better and we thought providing an abstraction is worth the hassle.
72
-
73
- #### Working with obj
74
-
75
- obj is a resource that is probably the oldest in all GoodData. Obj are all the objects that have something to do with the analytical engine (metrics, attributes, reports etc). You can find the docs here (Add link to apiary). There are coule of convenience methods to work with these
76
-
77
- GoodData.connect("svarovsky@gooddata.com", "just_testing")
78
- GoodData.project="fill_in_your_project_pid"
79
-
80
- # Access raw obj
81
- obj = GoodData::MdObject[obj_number]
82
-
83
- # bunch of useful methods are defined on these
84
- obj.title
85
- obj.get_used_by
86
- obj.get_using
87
- obj.delete
88
-
89
-
90
- #### Working with reports
91
-
92
- Sometimes it is useful to compute reports outside of UI so there are couple of convenience methods for that.
93
-
94
- require 'pp'
95
-
96
- GoodData.connect("svarovsky@gooddata.com", "just_testing")
97
- GoodData.project="fill_in_your_project_pid"
98
-
99
- report = GoodData::Report[1231]
100
- result = report.execute
101
- pp result
102
-
103
- File.open('png.png', 'w') do |f|
104
- f.write(report.export(:png))
105
- end
106
-
107
- You can export even whole dashboards. Currently afaik reports can be exported either as xls and png and dashboards as pdf. Hopefully it will support more in the future.
108
-
109
- dash = GoodData::Dashboard[33807]
110
- File.open('dash.pdf', 'w') do |f|
111
- f.write(dash.export(:pdf))
112
- end
113
-
114
- You can specify which tab to export. By default it is the first
115
-
116
- dash = GoodData::Dashboard[33807]
117
- File.open('dash.pdf', 'w') do |f|
118
- f.write(dash.export(:pdf, :tab => dash.tabs_ids.last))
119
- end
120
-
121
- ### CLI Usage
122
-
123
- After installing the gooddata gem, GoodData is available from your command line using
124
- the `gooddata` command. To get a complete overview of possible options type:
125
-
126
- gooddata help
127
-
128
- The examples and descriptions below does not cover all the options available via the CLI.
129
- So remember to refer back to the `help` command.
130
-
131
- Before you do anything else, a good idea is to see if your account is set up correctly and
132
- that you can log in. To do this, use the `api:test` command:
133
-
134
- gooddata api:test
135
-
136
- #### Authentication
137
-
138
- As you saw if you ran the above test command <tt>gooddata</tt> will prompt you
139
- for your GoodData username and password. If you don't wish to write your
140
- credentials each time you connect to GoodData using <tt>gooddata</tt>, you can
141
- create a simple gooddata credentials file called <tt>.gooddata</tt> in the root
142
- of your home directory. To make it easy you can just run the credentials file
143
- generator command which will create the file for you:
144
-
145
- gooddata auth:store
146
-
147
- #### List available projects
148
-
149
- To get a list of projects available to your GoodData user account, run:
150
-
151
- gooddata projects
152
-
153
- The output from the above command will look similar to this:
154
-
155
- ```
156
- 521 Some project
157
- 3521 Some other project
158
- 3642 Some third project
159
- ```
160
-
161
- The first column contains the project-key. You need this if you wan't to either
162
- see more details about the project using the `projects:show` comamnd or
163
- if you wish to delete the project using the `projects:delete` command.
164
-
165
- #### Create a new project
166
-
167
- To create a new project under on the GoodData servers, run:
168
-
169
- gooddata projects:create
170
-
171
- You will then be asked about the desired project name and summary before it's created.
172
-
173
36
  ## Note on Patches/Pull Requests
174
37
 
175
38
  * Fork the project.
@@ -182,10 +45,10 @@ You will then be asked about the desired project name and summary before it's cr
182
45
 
183
46
  ## Credits
184
47
 
185
- This project is developed and maintained by Pavel Kolesnikov [ <mailto:pavel@gooddata.com> / [@koles](http://twitter.com/koles) ] and Tomas Svarovsky <mailto:svarovsky.tomas@gmail.com>
48
+ This project is developed and maintained by Pavel Kolesnikov [ <mailto:pavel@gooddata.com> / [@koles](http://twitter.com/koles) ] and Tomas Svarovsky [<mailto:svarovsky.tomas@gmail.com> / [@fluke777](http://twitter.com/fluke777)]
186
49
 
187
50
  Special thanks to Thomas Watson Steen [ <mailto:w@tson.dk> / [@wa7son](http://twitter.com/wa7son) ]
188
51
 
189
52
  ## Copyright
190
53
 
191
- Copyright (c) 2010 - 2014 GoodData Corporation and Thomas Watson Steen. See LICENSE for details.
54
+ Copyright (c) 2010 - 2014 GoodData Corporation and Thomas Watson Steen. See LICENSE for details.
data/Rakefile CHANGED
@@ -8,18 +8,35 @@ require 'rspec/core/rake_task'
8
8
 
9
9
  require 'yard'
10
10
 
11
- RSpec::Core::RakeTask.new(:spec)
12
-
13
11
  task :usage do
14
12
  puts "No rake task specified, use rake -T to list them"
15
13
  end
16
14
 
17
- Rake::TestTask.new(:test) do |test|
18
- test.libs << 'lib' << 'test'
19
- test.pattern = 'test/**/test_*.rb'
20
- test.verbose = true
15
+ RSpec::Core::RakeTask.new(:test)
16
+
17
+ namespace :test do
18
+ desc "Run unit tests"
19
+ RSpec::Core::RakeTask.new(:unit) do |t|
20
+ t.pattern = 'spec/unit/**/*.rb'
21
+ end
22
+
23
+ desc "Run integration tests"
24
+ RSpec::Core::RakeTask.new(:integration) do |t|
25
+ t.pattern = 'spec/integration/**/*.rb'
26
+ end
27
+
28
+ # Rake::TestTask.new(:legacy) do |test|
29
+ # test.libs << 'lib' << 'test'
30
+ # test.pattern = 'test/**/test_*.rb'
31
+ # test.verbose = true
32
+ # end
33
+
34
+ task :all => [:unit, :integration]
21
35
  end
22
36
 
37
+ desc "Run all tests"
38
+ task :test => 'test:all'
39
+
23
40
  YARD::Rake::YardocTask.new
24
41
 
25
42
  task :default => [:usage]
data/bin/gooddata CHANGED
@@ -1,404 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'gli'
4
- require 'gooddata'
5
- require 'highline/import'
6
- require 'gooddata/commands/projects'
7
- require 'gooddata/commands/auth'
8
- require 'gooddata/commands/scaffold'
9
- require 'gooddata/commands/process'
10
- require 'gooddata/commands/api'
11
- require 'gooddata/commands/profile'
12
- require 'pp'
3
+ require "gooddata/cli/cli"
13
4
 
14
- include GLI::App
5
+ res = GoodData::CLI.main(ARGV)
15
6
 
16
- program_desc 'GoodData Ruby gem - a wrapper over GoodData API and several useful abstractions to make your everyday usage of GoodData easier.'
17
-
18
- version GoodData::VERSION
19
-
20
- desc 'GoodData user name'
21
- default_value nil
22
- arg_name 'gooddata-login'
23
- flag [:U, :username, :login]
24
-
25
- desc 'GoodData password'
26
- default_value nil
27
- arg_name 'gooddata-password'
28
- flag [:P, :password]
29
-
30
- desc 'Project pid'
31
- default_value nil
32
- arg_name 'project-id'
33
- flag [:p, :project_id]
34
-
35
- desc 'Server'
36
- default_value nil
37
- arg_name 'server'
38
- flag [:s, :server]
39
-
40
- desc 'WEBDAV Server. Used for uploads of files'
41
- default_value nil
42
- arg_name 'web dav server'
43
- flag [:w, :webdav_server]
44
-
45
- desc 'Token for project creation'
46
- default_value nil
47
- arg_name 'token'
48
- flag [:t, :token]
49
-
50
- desc 'Verbose mode'
51
- arg_name 'verbose'
52
- switch [:v, :verbose]
53
-
54
- desc 'Http logger on stdout'
55
- arg_name 'logger'
56
- switch [:l, :logger]
57
-
58
-
59
- desc 'Work with deployed processes'
60
- arg_name 'Describe arguments to list here'
61
- command :process do |c|
62
-
63
- c.desc 'Use when you need to redeploy a specific process'
64
- c.default_value nil
65
- c.flag :process_id
66
-
67
- c.desc 'Specify directory for deployment'
68
- c.default_value nil
69
- c.flag :dir
70
-
71
- c.desc 'Specify type of deployment'
72
- c.default_value nil
73
- c.flag :type
74
-
75
- c.desc 'Specify name of deployed process'
76
- c.default_value nil
77
- c.flag :name
78
-
79
- c.desc "Lists all user's processes deployed on the plaform"
80
- c.command :list do |list|
81
- list.action do |global_options, options, args|
82
- opts = options.merge(global_options)
83
- GoodData.connect(opts)
84
- pp GoodData::Command::Process.list(options.merge(global_options))
85
- end
86
- end
87
-
88
- c.desc "Gives you some basic info about the process"
89
- c.command :get do |get|
90
- get.action do |global_options, options, args|
91
- opts = options.merge(global_options)
92
- GoodData.connect(opts)
93
- pp GoodData::Command::Process.get(options.merge(global_options))
94
- end
95
- end
96
-
97
- c.desc "Deploys provided directory to the server"
98
- c.command :deploy do |deploy|
99
- deploy.action do |global_options, options, args|
100
- opts = options.merge(global_options)
101
- GoodData.connect(opts)
102
- pp GoodData::Command::Process.deploy(options[:dir], options.merge(global_options))
103
- end
104
- end
105
-
106
- end
107
-
108
- desc 'Some basic API stuff directly from CLI'
109
- arg_name 'info|test|get|delete'
110
- command :api do |c|
111
-
112
- c.desc "Info about the API version etc"
113
- c.command :info do |info|
114
- info.action do |global_options, options, args|
115
- opts = options.merge(global_options)
116
- GoodData.connect(opts)
117
- pp GoodData::Command::Api.info
118
- end
119
- end
120
-
121
- c.desc "GET request on our API"
122
- c.command :get do |get|
123
- get.action do |global_options, options, args|
124
- opts = options.merge(global_options)
125
- GoodData.connect(opts)
126
- pp GoodData::Command::Api.get(args[0])
127
- end
128
- end
129
-
130
- end
131
-
132
-
133
- desc 'Describe add here'
134
- arg_name 'show'
135
- command :profile do |c|
136
-
137
- c.desc "Show your profile"
138
- c.command :show do |show|
139
- show.action do |global_options, options, args|
140
- opts = options.merge(global_options)
141
- GoodData.connect(opts)
142
- pp GoodData::Command::Profile.show()
143
- end
144
- end
145
-
146
- end
147
-
148
- desc 'Scaffold things'
149
- arg_name 'show'
150
- command :scaffold do |c|
151
-
152
- c.desc "Scaffold a gooddata project blueprint"
153
- c.command :project do |project|
154
- project.action do |global_options, options, args|
155
- name = args.first
156
- fail "Name of the project has to be provided" if name.nil? || name.empty?
157
- GoodData::Command::Scaffold.project(name)
158
- end
159
- end
160
-
161
- c.desc "Scaffold a gooddata ruby brick. This is a piece of code that you can run on our platform"
162
- c.command :brick do |brick|
163
- # brick.arg_name 'name'
164
- brick.action do |global_options, options, args|
165
- name = args.first
166
- fail "Name of the brick has to be provided" if name.nil? || name.empty?
167
- GoodData::Command::Scaffold.brick(name)
168
- end
169
- end
170
- end
171
-
172
- desc 'Manage your projects'
173
- arg_name 'project_command'
174
- command :project do |c|
175
-
176
- c.desc "Lists user's projects"
177
- c.command :list do |list|
178
- list.action do |global_options, options, args|
179
- opts = options.merge(global_options)
180
- GoodData.connect(opts)
181
- list = GoodData::Command::Projects.list()
182
- puts list.map { |p| [p.uri, p.title].join(",") }
183
- end
184
- end
185
-
186
- 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"
187
- c.command :jack_in do |jack|
188
- jack.action do |global_options, options, args|
189
- goodfile_path = GoodData::Helpers.find_goodfile(Pathname('.'))
190
-
191
- spin_session = Proc.new do |goodfile, blueprint|
192
- project_id = global_options[:project_id] || goodfile[:project_id]
193
- 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?
194
-
195
- opts = options.merge(global_options)
196
- GoodData.connect(opts)
197
-
198
- begin
199
- GoodData.with_project(project_id) do |project|
200
- puts "Use 'exit' to quit the live session. Use 'q' to jump out of displaying a large output."
201
- binding.pry(:quiet => true,
202
- :prompt => [proc { |target_self, nest_level, pry|
203
- "project_live_sesion: "
204
- }])
205
- end
206
- rescue GoodData::ProjectNotFound => e
207
- puts "Project with id \"#{project_id}\" could not be found. Make sure that the id you provided is correct."
208
- end
209
- end
210
-
211
- if goodfile_path
212
- goodfile = JSON.parse(File.read(goodfile_path), :symbolize_names => true)
213
- model_key = goodfile[:model]
214
- blueprint = GoodData::Model::ProjectBlueprint.new(eval(File.read(model_key)).to_hash) if File.exist?(model_key) && !File.directory?(model_key)
215
- FileUtils::cd(goodfile_path.dirname) do
216
- spin_session.call(goodfile, blueprint)
217
- end
218
- else
219
- spin_session.call({}, nil)
220
- end
221
- end
222
- end
223
-
224
- c.desc "Create a gooddata project"
225
- c.command :create do |create|
226
- create.action do |global_options, options, args|
227
- title = ask "Project name"
228
- summary = ask("Project summary") { |q| q.default = "" }
229
- template = ask("Project template")
230
- token = ask("token")
231
-
232
- opts = options.merge(global_options)
233
- GoodData.connect(opts)
234
- project = GoodData::Command::Projects.create({
235
- :title => title,
236
- :summary => summary,
237
- :template => template,
238
- :token => token
239
- })
240
- puts "Project '#{project.title}' with id #{project.uri} created successfully!"
241
- end
242
- end
243
-
244
- c.desc "Delete a project. Be careful this is impossible to revert"
245
- c.command :delete do |delete|
246
- delete.action do |global_options, options, args|
247
- id = global_options[:project_id]
248
- opts = options.merge(global_options)
249
- GoodData.connect(opts)
250
- GoodData::Command::Projects.delete(id)
251
- end
252
- end
253
-
254
- c.desc "Clones a project. Useful for testing"
255
- c.command :clone do |clone|
256
- clone.desc 'Name of the new project'
257
- clone.default_value nil
258
- clone.arg_name 'cloned_project_name'
259
- clone.flag [:n, :name]
260
-
261
- clone.action do |global_options, options, args|
262
- id = global_options[:project_id]
263
- name = options[:name]
264
- token = options[:token]
265
- opts = options.merge(global_options)
266
- GoodData.connect(opts)
267
- GoodData::Command::Projects.clone(id, :name => name, :token => token)
268
- end
269
- end
270
-
271
- c.desc "Shows basic info about a project"
272
- c.command :show do |show|
273
- show.action do |global_options, options, args|
274
- id = global_options[:project_id]
275
- opts = options.merge(global_options)
276
- GoodData.connect(opts)
277
- p = GoodData::Command::Projects.show(id)
278
- pp p.data
279
- end
280
- end
281
-
282
- c.desc "If you are in a gooddata project blueprint it will apply the changes. If you do not provide a project id it will build it from scratch and create a project for you."
283
- c.command :build do |show|
284
- show.action do |global_options, options, args|
285
- opts = options.merge(global_options)
286
- GoodData.connect(opts)
287
- spec, project_id = GoodData::Command::Projects.get_spec_and_project_id(".")
288
- new_project = GoodData::Command::Projects.build(opts.merge(:spec => spec))
289
- puts "Project was created. New project PID is #{new_project.pid}, URI is #{new_project.uri}."
290
- end
291
- end
292
-
293
- c.desc "If you are in a gooddata project blueprint it will apply the changes. If you do not provide a project id it will build it from scratch and create a project for you."
294
- c.command :update do |show|
295
- show.action do |global_options, options, args|
296
-
297
- opts = options.merge(global_options)
298
- GoodData.connect(opts)
299
- spec, project_id = GoodData::Command::Projects.get_spec_and_project_id(".")
300
- project = GoodData::Command::Projects.update(opts.merge(:spec => spec, :project_id => global_options[:project_id] || project_id))
301
- puts "Migration was done. Project PID is #{project.pid}, URI is #{project.uri}."
302
-
303
- end
304
- end
305
-
306
- end
307
-
308
- desc 'Work with your locally stored credentials'
309
- command :auth do |c|
310
-
311
- c.desc "Store your credentials to ~/.gooddata so client does not have to ask you every single time"
312
- c.command :store do |store|
313
- store.action do |global_options, options, args|
314
- GoodData::Command::Auth.store
315
- end
316
- end
317
-
318
- end
319
-
320
- desc 'Run ruby bricks either locally or remotely deployed on our server'
321
- # arg_name 'show'
322
- command :run_ruby do |c|
323
-
324
- c.desc 'Directory of the ruby brick'
325
- c.default_value nil
326
- c.flag [:d, :dir]
327
-
328
- c.desc 'Log file. If empty STDOUT will be used instead'
329
- c.default_value nil
330
- c.flag [:l, :logger]
331
-
332
- c.desc 'Params file path. Inside should be hash of key values'
333
- c.default_value nil
334
- c.flag [:params]
335
-
336
- c.desc 'Run on remote machine'
337
- c.switch [:r, :remote]
338
-
339
- c.desc 'Name of the deployed process'
340
- c.default_value nil
341
- c.flag [:n, :name]
342
-
343
- c.action do |global_options, options, args|
344
- verbose = global_options[:verbose]
345
- options[:expanded_params] = if (options[:params])
346
- JSON.parse(File.read(options[:params]), :symbolize_names => true)
347
- else
348
- {}
349
- end
350
-
351
- opts = options.merge(global_options).merge({:type => "RUBY"})
352
- GoodData.connect(opts)
353
- if options[:remote]
354
- fail "You have to specify name of the deploy when deploying remotely" if options[:name].nil? || options[:name].empty?
355
- require 'gooddata/commands/process'
356
- GoodData::Command::Process.run(options[:dir], opts)
357
- else
358
- require 'gooddata/commands/runners'
359
- GoodData::Command::Runners.run_ruby_locally(options[:dir], opts)
360
- end
361
- puts HighLine::color("Running ruby brick - DONE", HighLine::GREEN) if verbose
362
- end
363
- end
364
-
365
- pre do |global, command, options, args|
366
- require 'logger'
367
- GoodData.logger = Logger.new(STDOUT) if global[:l]
368
- username = global[:username]
369
- password = global[:password]
370
- token = global[:token]
371
-
372
- creds = GoodData::Command::Auth.read_credentials
373
-
374
- username = creds[:username] if username.nil?
375
- password = creds[:password] if password.nil?
376
- token = creds[:auth_token] if token.nil?
377
-
378
- global[:token] = token if global[:token].nil?
379
- global[:login] = username if global[:login].nil?
380
- global[:password] = password if global[:password].nil?
381
- # Pre logic here
382
- # Return true to proceed; false to abort and not call the
383
- # chosen command
384
- # Use skips_pre before a command to skip this block
385
- # on that command only
386
- true
387
- end
388
-
389
- post do |global, command, options, args|
390
- # Post logic here
391
- # Use skips_post before a command to skip this
392
- # block on that command only
393
- end
394
-
395
- on_error do |exception|
396
- # Error logic here
397
- # return false to skip default error handling
398
- # binding.pry
399
- pp exception.backtrace
400
- pp exception
401
- true
402
- end
403
-
404
- exit run(ARGV)
7
+ exit(res)