gooddata 0.6.0.pre5 → 0.6.0.pre6

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.
@@ -10,17 +10,36 @@ module GoodData::Bricks
10
10
  token = params[:salesforce_token]
11
11
  client_id = params[:salesforce_client_id]
12
12
  client_secret = params[:salesforce_client_secret]
13
-
14
- Restforce.log = true if params[:salesforce_client_logger]
13
+ oauth_token = params[:salesforce_oauth_token]
14
+ refresh_token = params[:salesforce_refresh_token]
15
+ host = params[:salesforce_host]
16
+
17
+ credentials = {}
15
18
 
16
- client = Restforce.new(
17
- :username => username,
18
- :password => password,
19
- :security_token => token,
19
+ credentials = if (username && password && token)
20
+ {
21
+ :username => username,
22
+ :password => password,
23
+ :security_token => token
24
+ }
25
+ elsif (oauth_token && refresh_token)
26
+ {
27
+ :oauth_token => oauth_token,
28
+ :refresh_token => refresh_token
29
+ }
30
+ else
31
+ fail "Salesforce middleware failed while trying to log in. Either salesforce_username, salesforce_password, salesforce_token or salesforce_oauth_token, salesforce_refresh_token are needed. Additionally you have to specify salesforce_client_id and salesforce_client_secret parameters in both cases"
32
+ end
20
33
 
34
+
35
+ credentials.merge!({
21
36
  :client_id => client_id,
22
- :client_secret => client_secret)
37
+ :client_secret => client_secret,
38
+ })
39
+ credentials[:host] = host unless host.nil?
23
40
 
41
+ Restforce.log = true if params[:salesforce_client_logger]
42
+ client = Restforce.new(credentials)
24
43
  @app.call(params.merge(:salesforce_client => client))
25
44
  end
26
45
 
@@ -119,7 +119,7 @@ module GoodData
119
119
  end
120
120
 
121
121
  def with_project(project, &bl)
122
- fail "You have to specify a project when using with_project" if project.nil? || project.empty?
122
+ fail "You have to specify a project when using with_project" if project.nil? || (project.is_a?(String) && project.empty?)
123
123
  old_project = GoodData.project
124
124
  begin
125
125
  GoodData.use(project)
@@ -233,8 +233,22 @@ module GoodData
233
233
  connection.delete path, options
234
234
  end
235
235
 
236
- def upload_webdav(file, options={})
237
- connection.upload(file, options[:directory], options)
236
+ def upload_to_user_webdav(file, options={})
237
+ u = URI(connection.options[:webdav_server] || GoodData.project.links["uploads"])
238
+ url = URI.join(u.to_s.chomp(u.path.to_s), "/uploads/")
239
+ connection.upload(file, options.merge({
240
+ :directory => options[:directory],
241
+ :staging_url => url
242
+ }))
243
+ end
244
+
245
+ def upload_to_project_webdav(file, options={})
246
+ u = URI(connection.options[:webdav_server] || GoodData.project.links["uploads"])
247
+ url = URI.join(u.to_s.chomp(u.path.to_s), "/project-uploads/", "#{GoodData.project.pid}/")
248
+ connection.upload(file, options.merge({
249
+ :directory => options[:directory],
250
+ :staging_url => url
251
+ }))
238
252
  end
239
253
 
240
254
  def poll(result, key, options={})
@@ -52,7 +52,7 @@ module GoodData::Command
52
52
  end
53
53
  end
54
54
 
55
- GoodData.connection.upload(temp.path)
55
+ GoodData.upload_to_user_webdav(temp.path)
56
56
  process_id = options[:process]
57
57
 
58
58
  data = {
@@ -32,10 +32,9 @@ module GoodData
32
32
  DEFAULT_URL = 'https://secure.gooddata.com'
33
33
  LOGIN_PATH = '/gdc/account/login'
34
34
  TOKEN_PATH = '/gdc/account/token'
35
- STAGE_PATH = '/uploads/'
36
35
 
37
36
  attr_reader(:auth_token, :url)
38
- attr_accessor :status
37
+ attr_accessor :status, :options
39
38
 
40
39
 
41
40
  # Options:
@@ -196,14 +195,15 @@ module GoodData
196
195
  # Uploads a file to GoodData server
197
196
  # /uploads/ resources are special in that they use a different
198
197
  # host and a basic authentication.
199
- def upload(file, dir = nil, options={})
198
+ def upload(file, options={})
200
199
  ensure_connection
201
- # We should have followed a link. If it was correct.
202
200
 
203
- stage_url = @options[:webdav_server] || @url.sub(/\./, '-di.')
201
+ dir = options[:directory] || ''
202
+ staging_uri = options[:staging_url].to_s
203
+ url = dir.empty? ? staging_uri : URI.join(staging_uri, "#{dir}/").to_s
204
+
204
205
  # Make a directory, if needed
205
- if dir then
206
- url = stage_url + STAGE_PATH + dir + '/'
206
+ unless dir.empty? then
207
207
  method = :get
208
208
  GoodData.logger.debug "#{method}: #{url}"
209
209
  begin
@@ -230,17 +230,17 @@ module GoodData
230
230
  )
231
231
  end
232
232
  end
233
- else
234
- dir = "."
235
233
  end
236
234
 
237
235
  payload = options[:stream] ? "file" : File.read(file)
238
236
  filename = options[:filename] || options[:stream] ? "randome-filename.txt" : File.basename(file)
239
237
 
240
238
  # Upload the file
239
+ puts "uploading the file #{URI.join(url, filename).to_s}"
240
+
241
241
  req = RestClient::Request.new({
242
242
  :method => :put,
243
- :url => stage_url + STAGE_PATH + dir + '/' + filename,
243
+ :url => URI.join(url, filename).to_s,
244
244
  :timeout => @options[:timeout],
245
245
  :headers => {
246
246
  :user_agent => GoodData.gem_version_string,
@@ -249,7 +249,7 @@ module GoodData
249
249
  :raw_response => true
250
250
  }.merge(cookies))
251
251
  resp = req.execute
252
- pp e.inspect
252
+ true
253
253
  end
254
254
 
255
255
  def download(what, where)
@@ -491,7 +491,7 @@ module GoodData
491
491
  end
492
492
 
493
493
  # upload it
494
- GoodData.connection.upload "#{dir}/upload.zip", File.basename(dir)
494
+ GoodData.upload_to_user_webdav("#{dir}/upload.zip", :directory => File.basename(dir))
495
495
  FileUtils.rm_rf dir
496
496
 
497
497
  # kick the load
@@ -189,6 +189,10 @@ module GoodData
189
189
  raw_data["project"]
190
190
  end
191
191
 
192
+ def links
193
+ data["links"]
194
+ end
195
+
192
196
  def to_json
193
197
  raw_data.to_json
194
198
  end
@@ -1,3 +1,3 @@
1
1
  module GoodData
2
- VERSION = "0.6.0.pre5"
2
+ VERSION = "0.6.0.pre6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gooddata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0.pre5
4
+ version: 0.6.0.pre6
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors: