Method: GoodData::Project.create

Defined in:
lib/gooddata/models/project.rb

.create(opts = { client: GoodData.connection }, &block) ⇒ Object

Create a project from a given attributes Expected keys:

  • :title (mandatory)
  • :summary
  • :template (default /projects/blank)
[View source]

137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/gooddata/models/project.rb', line 137

def create(opts = { client: GoodData.connection }, &block)
  GoodData.logger.info "Creating project #{opts[:title]}"

  auth_token = opts[:auth_token] || opts[:token]
  if auth_token.nil? || auth_token.empty?
    opts = { auth_token: Helpers::AuthHelper.read_token }.merge(opts)
    auth_token = opts[:auth_token]
  end
  fail ArgumentError, 'You have to provide your token for creating projects as :auth_token or :token parameter' if auth_token.nil? || auth_token.empty?

  project = create_object(opts)
  project.save
  # until it is enabled or deleted, recur. This should still end if there
  # is a exception thrown out from RESTClient. This sometimes happens from
  # WebApp when request is too long
  while project.state.to_s != 'enabled'
    if project.deleted?
      # if project is switched to deleted state, fail. This is usually problem of creating a template which is invalid.
      fail 'Project was marked as deleted during creation. This usually means you were trying to create from template and it failed.'
    end
    sleep(3)
    project.reload!
  end

  if block
    GoodData.with_project(project) do |p|
      block.call(p)
    end
  end
  sleep 3
  project
end