gooddata 0.6.7 → 0.6.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +19 -1
  3. data/README.md +10 -2
  4. data/TODO.md +32 -0
  5. data/gooddata.gemspec +5 -0
  6. data/lib/gooddata.rb +4 -0
  7. data/lib/gooddata/app/app.rb +12 -0
  8. data/lib/gooddata/bricks/middleware/gooddata_middleware.rb +4 -3
  9. data/lib/gooddata/bricks/middleware/restforce_middleware.rb +2 -1
  10. data/lib/gooddata/cli/commands/console_cmd.rb +23 -5
  11. data/lib/gooddata/cli/commands/domain_cmd.rb +9 -10
  12. data/lib/gooddata/cli/commands/process_cmd.rb +11 -9
  13. data/lib/gooddata/cli/commands/project_cmd.rb +25 -27
  14. data/lib/gooddata/cli/commands/projects_cmd.rb +2 -2
  15. data/lib/gooddata/cli/commands/run_ruby_cmd.rb +1 -1
  16. data/lib/gooddata/cli/commands/user_cmd.rb +2 -2
  17. data/lib/gooddata/cli/hooks.rb +4 -2
  18. data/lib/gooddata/cli/shared.rb +1 -1
  19. data/lib/gooddata/cli/terminal.rb +1 -1
  20. data/lib/gooddata/commands/api.rb +1 -1
  21. data/lib/gooddata/commands/auth.rb +4 -28
  22. data/lib/gooddata/commands/domain.rb +9 -4
  23. data/lib/gooddata/commands/process.rb +26 -23
  24. data/lib/gooddata/commands/project.rb +74 -50
  25. data/lib/gooddata/commands/projects.rb +3 -2
  26. data/lib/gooddata/commands/role.rb +9 -3
  27. data/lib/gooddata/commands/user.rb +6 -4
  28. data/lib/gooddata/connection.rb +11 -45
  29. data/lib/gooddata/core/logging.rb +0 -1
  30. data/lib/gooddata/core/project.rb +22 -22
  31. data/lib/gooddata/core/rest.rb +9 -8
  32. data/lib/gooddata/core/user.rb +0 -11
  33. data/lib/gooddata/exceptions/project_not_found.rb +1 -0
  34. data/lib/gooddata/extensions/enumerable.rb +10 -0
  35. data/lib/gooddata/extensions/hash.rb +25 -0
  36. data/lib/gooddata/goodzilla/goodzilla.rb +4 -4
  37. data/lib/gooddata/helper/class_helper.rb +1 -0
  38. data/lib/gooddata/helper/helpers.rb +8 -0
  39. data/lib/gooddata/helpers/auth_helpers.rb +41 -0
  40. data/lib/gooddata/mixins/author.rb +1 -1
  41. data/lib/gooddata/mixins/contributor.rb +1 -1
  42. data/lib/gooddata/mixins/data_property_reader.rb +2 -0
  43. data/lib/gooddata/mixins/data_property_writer.rb +2 -0
  44. data/lib/gooddata/mixins/inspector.rb +49 -0
  45. data/lib/gooddata/mixins/md_finders.rb +16 -8
  46. data/lib/gooddata/mixins/md_id_to_uri.rb +12 -4
  47. data/lib/gooddata/mixins/md_object_indexer.rb +15 -4
  48. data/lib/gooddata/mixins/md_object_query.rb +42 -20
  49. data/lib/gooddata/mixins/md_relations.rb +21 -12
  50. data/lib/gooddata/mixins/meta_getter.rb +2 -0
  51. data/lib/gooddata/mixins/meta_property_reader.rb +2 -0
  52. data/lib/gooddata/mixins/meta_property_writer.rb +2 -0
  53. data/lib/gooddata/mixins/rest_resource.rb +32 -10
  54. data/lib/gooddata/mixins/root_key_getter.rb +1 -1
  55. data/lib/gooddata/models/data_result.rb +3 -1
  56. data/lib/gooddata/models/domain.rb +31 -22
  57. data/lib/gooddata/models/empty_result.rb +22 -0
  58. data/lib/gooddata/models/invitation.rb +11 -9
  59. data/lib/gooddata/models/links.rb +5 -3
  60. data/lib/gooddata/models/membership.rb +23 -28
  61. data/lib/gooddata/models/metadata.rb +35 -35
  62. data/lib/gooddata/models/metadata/attribute.rb +10 -8
  63. data/lib/gooddata/models/metadata/dashboard.rb +1 -1
  64. data/lib/gooddata/models/metadata/fact.rb +3 -3
  65. data/lib/gooddata/models/metadata/label.rb +4 -4
  66. data/lib/gooddata/models/metadata/metric.rb +76 -38
  67. data/lib/gooddata/models/metadata/report.rb +52 -17
  68. data/lib/gooddata/models/metadata/report_definition.rb +178 -28
  69. data/lib/gooddata/models/model.rb +13 -6
  70. data/lib/gooddata/models/process.rb +93 -30
  71. data/lib/gooddata/models/profile.rb +18 -20
  72. data/lib/gooddata/models/project.rb +344 -127
  73. data/lib/gooddata/models/project_creator.rb +32 -22
  74. data/lib/gooddata/models/project_metadata.rb +26 -14
  75. data/lib/gooddata/models/project_role.rb +15 -17
  76. data/lib/gooddata/models/report_data_result.rb +4 -0
  77. data/lib/gooddata/models/schedule.rb +51 -20
  78. data/lib/gooddata/models/schema_blueprint.rb +9 -3
  79. data/lib/gooddata/rest/README.md +37 -0
  80. data/lib/gooddata/rest/client.rb +318 -0
  81. data/lib/gooddata/rest/connection.rb +235 -0
  82. data/lib/gooddata/rest/connections/connections.rb +8 -0
  83. data/lib/gooddata/rest/connections/dummy_connection.rb +52 -0
  84. data/lib/gooddata/rest/connections/rest_client_connection.rb +177 -0
  85. data/lib/gooddata/rest/object.rb +32 -0
  86. data/lib/gooddata/rest/object_factory.rb +67 -0
  87. data/lib/gooddata/rest/resource.rb +17 -0
  88. data/lib/gooddata/rest/rest.rb +20 -0
  89. data/lib/gooddata/version.rb +1 -1
  90. data/spec/data/cc/data/source/commits.csv +4 -0
  91. data/spec/data/cc/data/source/devs.csv +4 -0
  92. data/spec/data/cc/data/source/repos.csv +3 -0
  93. data/spec/data/cc/devel.prm +0 -0
  94. data/spec/data/cc/graph/graph.grf +11 -0
  95. data/spec/data/cc/workspace.prm +19 -0
  96. data/spec/data/hello_world_process/hello_world.rb +1 -0
  97. data/spec/data/hello_world_process/hello_world.zip +0 -0
  98. data/spec/data/users.csv +12 -12
  99. data/spec/helpers/connection_helper.rb +6 -0
  100. data/spec/helpers/process_helper.rb +12 -0
  101. data/spec/helpers/project_helper.rb +2 -2
  102. data/spec/integration/command_projects_spec.rb +11 -9
  103. data/spec/integration/create_from_template_spec.rb +6 -2
  104. data/spec/integration/full_process_schedule_spec.rb +49 -36
  105. data/spec/integration/full_project_spec.rb +221 -256
  106. data/spec/integration/partial_md_export_import_spec.rb +18 -17
  107. data/spec/logging_in_logging_out_spec.rb +17 -8
  108. data/spec/spec_helper.rb +4 -2
  109. data/spec/unit/cli/commands/cmd_api_spec.rb +1 -1
  110. data/spec/unit/cli/commands/cmd_auth_spec.rb +1 -1
  111. data/spec/unit/cli/commands/cmd_domain_spec.rb +29 -3
  112. data/spec/unit/cli/commands/cmd_process_spec.rb +1 -1
  113. data/spec/unit/cli/commands/cmd_project_spec.rb +1 -1
  114. data/spec/unit/cli/commands/cmd_role_spec.rb +13 -2
  115. data/spec/unit/cli/commands/cmd_run_ruby_spec.rb +1 -1
  116. data/spec/unit/cli/commands/cmd_scaffold_spec.rb +1 -1
  117. data/spec/unit/cli/commands/cmd_user_spec.rb +1 -1
  118. data/spec/unit/commands/command_api_spec.rb +0 -19
  119. data/spec/unit/commands/command_auth_spec.rb +20 -13
  120. data/spec/unit/commands/command_dataset_spec.rb +2 -2
  121. data/spec/unit/commands/command_process_spec.rb +24 -21
  122. data/spec/unit/commands/command_projects_spec.rb +2 -2
  123. data/spec/unit/commands/command_scaffold_spec.rb +2 -2
  124. data/spec/unit/commands/command_user_spec.rb +3 -3
  125. data/spec/unit/core/connection_spec.rb +9 -10
  126. data/spec/unit/core/project_spec.rb +8 -4
  127. data/spec/unit/core/rest_spec.rb +6 -6
  128. data/spec/unit/models/domain_spec.rb +14 -7
  129. data/spec/unit/models/invitation_spec.rb +2 -2
  130. data/spec/unit/models/membership_spec.rb +5 -5
  131. data/spec/unit/models/metric_spec.rb +92 -0
  132. data/spec/unit/models/profile_spec.rb +25 -21
  133. data/spec/unit/models/project_blueprint_spec.rb +6 -6
  134. data/spec/unit/models/project_role_spec.rb +3 -5
  135. data/spec/unit/models/project_spec.rb +43 -37
  136. data/spec/unit/models/schedule_spec.rb +58 -107
  137. data/spec/unit/rest/resource_spec.rb +6 -0
  138. metadata +87 -10
  139. data/lib/gooddata/cli/commands/role_cmd.rb +0 -28
  140. data/lib/gooddata/core/connection.rb +0 -392
  141. data/lib/gooddata/core/threaded.rb +0 -14
  142. data/lib/gooddata/models/md_object.rb +0 -25
  143. data/lib/gooddata/models/metadata/folder.rb +0 -24
  144. data/spec/unit/models/md_object_spec.rb +0 -55
  145. data/spec/unit/models/metric.rb +0 -92
@@ -12,8 +12,8 @@ GoodData::CLI.module_eval do
12
12
  c.command :list do |list|
13
13
  list.action do |global_options, options, args|
14
14
  opts = options.merge(global_options)
15
- GoodData.connect(opts)
16
- list = GoodData::Command::Projects.list
15
+ client = GoodData.connect(opts)
16
+ list = GoodData::Command::Projects.list(client: client)
17
17
  puts list.map { |p| [p.uri, p.title].join(',') }
18
18
  end
19
19
  end
@@ -9,7 +9,7 @@ require_relative '../../client'
9
9
 
10
10
  GoodData::CLI.module_eval do
11
11
 
12
- desc 'Run ruby bricks either locally or remotely deployed on our server'
12
+ desc 'Run ruby bricks either locally or remotely deployed on our server. Currently private alpha.'
13
13
  # arg_name 'show'
14
14
  command :run_ruby do |c|
15
15
 
@@ -13,8 +13,8 @@ GoodData::CLI.module_eval do
13
13
  c.command :show do |show|
14
14
  show.action do |global_options, options, args|
15
15
  opts = options.merge(global_options)
16
- GoodData.connect(opts)
17
- pp GoodData::Command::User.show
16
+ client = GoodData.connect(opts)
17
+ pp GoodData::Command::User.show(client: client)
18
18
  end
19
19
  end
20
20
  end
@@ -3,6 +3,8 @@
3
3
  require 'gli'
4
4
  require 'pp'
5
5
 
6
+ require_relative '../helpers/auth_helpers'
7
+
6
8
  GoodData::CLI.module_eval do
7
9
  pre do |global, command, options, args|
8
10
  require 'logger'
@@ -11,7 +13,7 @@ GoodData::CLI.module_eval do
11
13
  password = global[:password]
12
14
  token = global[:token]
13
15
 
14
- creds = GoodData::Command::Auth.read_credentials
16
+ creds = GoodData::Helpers::AuthHelper.read_credentials
15
17
 
16
18
  username = creds[:username] if username.nil?
17
19
  password = creds[:password] if password.nil?
@@ -39,7 +41,7 @@ GoodData::CLI.module_eval do
39
41
  # return false to skip default error handling
40
42
  # binding.pry
41
43
  # pp exception.backtrace
42
- pp exception
44
+ # pp exception
43
45
  true
44
46
  end
45
47
  end
@@ -30,7 +30,7 @@ GoodData::CLI.module_eval do
30
30
  flag [:p, :project_id]
31
31
 
32
32
  desc 'Server'
33
- default_value GoodData::Connection::DEFAULT_URL
33
+ default_value GoodData::Rest::Connection::DEFAULT_URL
34
34
  arg_name 'server'
35
35
  flag [:s, :server]
36
36
 
@@ -5,7 +5,7 @@ require 'highline'
5
5
  # Define GoodData::CLI as GLI Wrapper
6
6
  module GoodData
7
7
  module CLI
8
- DEFAULT_TERMINAL = HighLine.new
8
+ DEFAULT_TERMINAL = HighLine.new unless const_defined?(:DEFAULT_TERMINAL)
9
9
 
10
10
  class << self
11
11
  def terminal
@@ -25,7 +25,7 @@ module GoodData
25
25
  # Test of login
26
26
  def test
27
27
  if GoodData.test_login
28
- puts "Succesfully logged in as #{GoodData.profile.email}"
28
+ puts "Succesfully logged in as #{GoodData.profile.user}"
29
29
  else
30
30
  puts 'Unable to log in to GoodData server!'
31
31
  end
@@ -1,7 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  require 'highline/import'
4
- require 'multi_json'
5
4
 
6
5
  require_relative '../cli/terminal'
7
6
  require_relative '../helpers/helpers'
@@ -10,11 +9,6 @@ module GoodData
10
9
  module Command
11
10
  class Auth
12
11
  class << self
13
- # Get path of .gooddata config
14
- def credentials_file
15
- "#{GoodData::Helpers.home_directory}/.gooddata"
16
- end
17
-
18
12
  # Ask for credentials
19
13
  def ask_for_credentials
20
14
  puts 'Enter your GoodData credentials.'
@@ -25,26 +19,8 @@ module GoodData
25
19
  { :username => user, :password => password, :auth_token => auth_token }
26
20
  end
27
21
 
28
- # Read credentials
29
- def read_credentials(credentials_file_path = credentials_file)
30
- if File.exist?(credentials_file_path)
31
- config = File.read(credentials_file_path)
32
- MultiJson.load(config, :symbolize_keys => true)
33
- else
34
- {}
35
- end
36
- end
37
-
38
- # Writes credentials
39
- def write_credentials(credentials, credentials_file_path = credentials_file)
40
- File.open(credentials_file_path, 'w', 0600) do |f|
41
- f.puts MultiJson.encode(credentials, :pretty => true)
42
- end
43
- credentials
44
- end
45
-
46
22
  # Ask for credentials and store them
47
- def store(credentials_file_path = credentials_file)
23
+ def store(credentials_file_path = Helpers::AuthHelper.credentials_file)
48
24
  credentials = ask_for_credentials
49
25
 
50
26
  ovewrite = if File.exist?(credentials_file_path)
@@ -54,15 +30,15 @@ module GoodData
54
30
  end
55
31
 
56
32
  if ovewrite == 'y'
57
- write_credentials(credentials, credentials_file_path)
33
+ Helpers::AuthHelper.write_credentials(credentials, credentials_file_path)
58
34
  else
59
35
  puts 'Aborting...'
60
36
  end
61
37
  end
62
38
 
63
39
  # Delete stored credentials
64
- def unstore(credentials_file_path = credentials_file)
65
- FileUtils.rm_f(credentials_file_path)
40
+ def unstore(credentials_file_path = Helpers::AuthHelper.credentials_file)
41
+ Helpers::AuthHelper.remove_credentials_file(credentials_file_path)
66
42
  end
67
43
  end
68
44
  end
@@ -10,12 +10,17 @@ module GoodData
10
10
  attr_reader :name
11
11
 
12
12
  class << self
13
- def add_user(domain, login, password)
14
- GoodData::Domain.add_user(domain, login, password)
13
+ def add_user(domain, login, password, opts = { :client => GoodData.connection })
14
+ data = {
15
+ :domain => domain,
16
+ :login => login,
17
+ :password => password
18
+ }
19
+ GoodData::Domain.add_user(data.merge(opts))
15
20
  end
16
21
 
17
- def list_users(domain)
18
- GoodData::Domain.users(domain)
22
+ def list_users(domain, opts = { :client => GoodData.connection })
23
+ GoodData::Domain.users(domain, opts)
19
24
  end
20
25
  end
21
26
  end
@@ -8,49 +8,52 @@ module GoodData
8
8
  module Command
9
9
  class Process
10
10
  class << self
11
- def list(options = {})
12
- GoodData.with_project(options[:project_id]) do
13
- GoodData::Process[:all]
14
- end
11
+ def list(options = { :client => GoodData.connection, :project => GoodData.project })
12
+ GoodData::Process[:all, options]
15
13
  end
16
14
 
17
15
  def get(options = {})
18
- id = options[:process_id]
19
- fail 'Unspecified process id' if id.nil?
16
+ pid = options[:project_id]
17
+ fail ArgumentError, 'None or invalid project_id specified' if pid.nil? || pid.empty?
20
18
 
21
- GoodData.with_project(options[:project_id]) do
22
- GoodData::Process[id]
19
+ id = options[:process_id]
20
+ fail ArgumentError, 'None or invalid process_id' if id.nil? || id.empty?
21
+ c = options[:client]
22
+ c.with_project(pid) do |project|
23
+ project.processes(id)
23
24
  end
24
25
  end
25
26
 
26
- def delete(process_id, options = {})
27
- GoodData.with_project(options[:project_id]) do
28
- process = GoodData::Process[process_id]
29
- process.delete
27
+ def delete(process_id, options = { :client => GoodData.connection, :project => GoodData.project })
28
+ c = options[:client]
29
+ pid = options[:project_id]
30
+ process = c.with_project(pid) do |project|
31
+ project.processes(process_id)
30
32
  end
33
+ process.delete
31
34
  end
32
35
 
33
36
  # TODO: check files_to_exclude param. Does it do anything? It should check that in case of using CLI, it makes sure the files are not deployed
34
- def deploy(dir, options = {})
35
- GoodData.with_project(options[:project_id]) do
36
- params = options[:params].nil? ? [] : [options[:params]]
37
- GoodData::Process.deploy(dir, options.merge(:files_to_exclude => params))
37
+ def deploy(dir, options = { :client => GoodData.connection, :project => GoodData.project })
38
+ params = options[:params].nil? ? [] : [options[:params]]
39
+ c = options[:client]
40
+ pid = options[:project_id]
41
+ c.with_project(pid) do |project|
42
+ project.deploy_process(dir, options.merge(:files_to_exclude => params))
38
43
  end
39
44
  end
40
45
 
41
- def execute_process(process_id, executable, options = {})
42
- GoodData.with_project(options[:project_id]) do
43
- process = GoodData::Process[process_id]
44
- process.execute_process(executable, options)
45
- end
46
+ def execute_process(process_id, executable, options = { :client => GoodData.connection, :project => GoodData.project })
47
+ process = GoodData::Process[process_id, options]
48
+ process.execute_process(executable, options)
46
49
  end
47
50
 
48
- def run(dir, executable, options = {})
51
+ def run(dir, executable, options = { :client => GoodData.connection, :project => GoodData.project })
49
52
  verbose = options[:v]
50
53
  dir = Pathname(dir)
51
54
  name = options[:name] || "Temporary deploy[#{dir}][#{options[:project_name]}]"
52
55
 
53
- GoodData::Process.with_deploy(dir, options.merge(:name => name)) do |process|
56
+ GoodData::Process.with_deploy(dir, options.merge(:name => name, :project_id => ProjectHelper::PROJECT_ID)) do |process|
54
57
  puts HighLine.color('Executing', HighLine::BOLD) if verbose
55
58
  process.execute(executable, options)
56
59
  end
@@ -7,39 +7,49 @@ module GoodData
7
7
  class Project
8
8
  class << self
9
9
  # Create new project based on options supplied
10
- def create(options = {})
10
+ def create(options = { client: GoodData.connection })
11
11
  title = options[:title]
12
12
  summary = options[:summary]
13
13
  template = options[:template]
14
14
  token = options[:token]
15
-
16
- GoodData::Project.create(:title => title, :summary => summary, :template => template, :auth_token => token)
15
+ client = options[:client]
16
+ GoodData::Project.create(:title => title, :summary => summary, :template => template, :auth_token => token, :client => client)
17
17
  end
18
18
 
19
19
  # Show existing project
20
- def show(id)
21
- GoodData::Project[id]
20
+ def show(id, options = { client: GoodData.connection })
21
+ client = options[:client]
22
+ client.projects(id)
22
23
  end
23
24
 
24
- def invite(project_id, email, role, msg = GoodData::Project::DEFAULT_INVITE_MESSAGE)
25
- msg = GoodData::Project::DEFAULT_INVITE_MESSAGE if msg.nil? || msg.empty?
26
-
27
- project = GoodData::Project[project_id]
25
+ def invite(project_id, email, role, msg = GoodData::Project::DEFAULT_INVITE_MESSAGE, options = {})
26
+ client = options[:client]
27
+ project = client.projects(project_id)
28
28
  fail "Invalid project id '#{project_id}' specified" if project.nil?
29
29
 
30
30
  project.invite(email, role, msg)
31
31
  end
32
32
 
33
33
  # Clone existing project
34
- def clone(project_id, options)
35
- GoodData.with_project(project_id) do |project|
34
+ #
35
+ # @param project_id [String | GoodData::Project] Project id or project instance to delete
36
+ # @option options [String] :data Clone including all the data (default true)
37
+ # @option options [String] :users Clone including all the users (default false)
38
+ # @option options [String] :title Name of the cloned project (default "Clone of {old_project_title}")
39
+ # @option options [Boolean] :verbose (false) Switch on verbose mode for detailed logging
40
+ def clone(project_id, options = { client: GoodData.connection })
41
+ client = options[:client]
42
+ client.with_project(project_id) do |project|
36
43
  project.clone(options)
37
44
  end
38
45
  end
39
46
 
40
- # Delete existing project
41
- def delete(project_id)
42
- p = GoodData::Project[project_id]
47
+ # Deletes existing project
48
+ #
49
+ # @param project_id [String | GoodData::Project] Project id or project instance to delete
50
+ def delete(project_id, options = { client: GoodData.connection })
51
+ client = options[:client]
52
+ p = client.projects(project_id)
43
53
  p.delete
44
54
  end
45
55
 
@@ -62,47 +72,35 @@ module GoodData
62
72
  [spec, goodfile[:project_id]]
63
73
  end
64
74
 
65
- def list_users(pid)
66
- users = []
67
- finished = false
68
- offset = 0
69
- # Limit set to 1000 to be safe
70
- limit = 1000
71
- until finished
72
- result = GoodData.get('/gdc/projects/#{pid}/users?offset=#{offset}&limit=#{limit}')
73
- result['users'].map do |u|
74
- as = u['user']
75
- users.push(
76
- :login => as['content']['email'],
77
- :uri => as['links']['self'],
78
- :first_name => as['content']['firstname'],
79
- :last_name => as['content']['lastname'],
80
- :role => as['content']['userRoles'].first,
81
- :status => as['content']['status']
82
- )
83
- end
84
- if result['users'].count == limit
85
- offset += limit
86
- else
87
- finished = true
88
- end
89
- end
90
- users
91
- end
92
-
93
75
  # Update project
94
- def update(options = {})
95
- project = options[:project]
96
- GoodData::Model::ProjectCreator.migrate(:spec => options[:spec], :project => project)
76
+ def update(opts = { client: GoodData.connection })
77
+ client = opts[:client]
78
+ fail ArgumentError, 'No :client specified' if client.nil?
79
+
80
+ p = opts[:project]
81
+ fail ArgumentError, 'No :project specified' if p.nil?
82
+
83
+ project = GoodData::Project[p, opts]
84
+ fail ArgumentError, 'Wrong :project specified' if project.nil?
85
+
86
+ GoodData::Model::ProjectCreator.migrate(:spec => opts[:spec], :client => client, :project => project)
97
87
  end
98
88
 
99
89
  # Build project
100
- def build(options = {})
101
- GoodData::Model::ProjectCreator.migrate(:spec => options[:spec], :token => options[:token])
90
+ def build(opts = { client: GoodData.connection })
91
+ client = opts[:client]
92
+ fail ArgumentError, 'No :client specified' if client.nil?
93
+
94
+ GoodData::Model::ProjectCreator.migrate(:spec => opts[:spec], :token => opts[:token], :client => client)
102
95
  end
103
96
 
104
- def validate(project_id)
105
- GoodData.with_project(project_id) do |p|
97
+ # Performs project validation
98
+ #
99
+ # @param project_id [String | GoodData::Project] Project id or project instance to validate
100
+ # @return [Object] Report of found problems
101
+ def validate(project_id, options = { client: GoodData.connection })
102
+ client = options[:client]
103
+ client.with_project(project_id) do |p|
106
104
  p.validate
107
105
  end
108
106
  end
@@ -120,7 +118,11 @@ module GoodData
120
118
 
121
119
  begin
122
120
  require 'gooddata'
123
- GoodData.with_project(project_id) do |project|
121
+ client = GoodData.connect(options)
122
+
123
+ GoodData.with_project(project_id, :client => client) do |project|
124
+ fail ArgumentError, 'Wrong project specified' if project.nil?
125
+
124
126
  puts "Use 'exit' to quit the live session. Use 'q' to jump out of displaying a large output."
125
127
  binding.pry(:quiet => true,
126
128
  :prompt => [proc do |target_self, nest_level, pry|
@@ -143,6 +145,28 @@ module GoodData
143
145
  spin_session.call({}, nil)
144
146
  end
145
147
  end
148
+
149
+ # Lists roles in a project
150
+ #
151
+ # @param project_id [String | GoodData::Project] Project id or project instance to list the users in
152
+ # @return [Array <GoodData::Role>] List of project roles
153
+ def roles(project_id, options = { client: GoodData.connection })
154
+ client = options[:client]
155
+ client.with_project(project_id) do |p|
156
+ p.roles
157
+ end
158
+ end
159
+
160
+ # Lists users in a project
161
+ #
162
+ # @param project_id [String | GoodData::Project] Project id or project instance to list the users in
163
+ # @return [Array <GoodData::Membership>] List of project users
164
+ def users(project_id, options = { client: GoodData.connection })
165
+ client = options[:client]
166
+ client.with_project(project_id) do |p|
167
+ p.users
168
+ end
169
+ end
146
170
  end
147
171
  end
148
172
  end
@@ -6,8 +6,9 @@ module GoodData
6
6
  module Command
7
7
  class Projects
8
8
  class << self
9
- def list
10
- GoodData::Project.all
9
+ def list(options = { client: GoodData.connection })
10
+ client = options[:client]
11
+ client.projects
11
12
  end
12
13
  end
13
14
  end
@@ -6,12 +6,18 @@ module GoodData
6
6
  module Command
7
7
  class Role
8
8
  class << self
9
- def list(pid)
10
- roles_response = GoodData.get("/gdc/projects/#{pid}/roles")
9
+ def list(pid, opts = { :client => GoodData.connection, :project => GoodData.project })
10
+ p = opts[:project]
11
+ fail ArgumentError, 'No :project specified' if p.nil?
12
+
13
+ project = GoodData::Project[p, opts]
14
+ fail ArgumentError, 'Wrong :project specified' if project.nil?
15
+
16
+ roles_response = client.get("/gdc/projects/#{project.pid}/roles")
11
17
 
12
18
  roles = {}
13
19
  roles_response['projectRoles']['roles'].each do |role_uri|
14
- r = GoodData.get(role_uri)
20
+ r = client.get(role_uri)
15
21
  identifier = r['projectRole']['meta']['identifier']
16
22
  roles[identifier] = {
17
23
  :user_uri => r['projectRole']['links']['roleUsers'],