gooddata-bricks 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 19b98bdc50b16bdb85db7a9698794eba74f660ce
4
- data.tar.gz: 826ca8b4ca96c71eca424f6dbfa17cc167a21843
3
+ metadata.gz: c449efac4ebc29bbe1894ddacd889d6c5bc408e0
4
+ data.tar.gz: 1ddd5f72330bbcbd4837b3790f4c620d1a87e254
5
5
  SHA512:
6
- metadata.gz: 3173fbe9fca5a422161d3d1a3e4e8d681bbad10c51d27845a4a242030237a7237b0de74273d2bdcc7a79146578b2025e86289bd5a9cb496ee07ecb95da72147b
7
- data.tar.gz: 5d18283393e0548b0845cb6bb5e0b708d02ce54f40841fd106afd185be6b8396cf1c328a48691b0da67d74a88e27a7a6f7022ab4456b4500e2f6cc8112783961
6
+ metadata.gz: 0f46c3b8817ec7f367e4e45b629d3765541acbb875f3f059daa7634302ea9980e1032b818e94cb2d6575e256da5656dba4accff1cbf51ded0328b2f0f10fcc35
7
+ data.tar.gz: 1c9c0c4fa49f22ee8771ed314e534aef03a13de6005a2524026772c2f9b50d509ca76ee9971f49e5c8d9ed1a4086a4e5b5521adaa552c41e7c08dd991a8818cd
@@ -34,5 +34,6 @@ Gem::Specification.new do |spec|
34
34
  spec.add_dependency 'restforce', '~> 2.1', '>= 2.1.1'
35
35
  spec.add_dependency 'salesforce_bulk_query', '~> 0.2', '>= 0.2.0'
36
36
  spec.add_dependency 'gooddata'
37
+ spec.add_dependency 'gooddata_datawarehouse'
37
38
  spec.add_dependency 'multi_json'
38
39
  end
@@ -6,3 +6,4 @@
6
6
 
7
7
  require 'gooddata/bricks/version'
8
8
  require_relative 'bricks/brick'
9
+ require_relative 'helpers/data_helper'
@@ -0,0 +1,27 @@
1
+ # encoding: UTF-8
2
+ #
3
+ # Copyright (c) 2010-2015 GoodData Corporation. All rights reserved.
4
+ # This source code is licensed under the BSD-style license found in the
5
+ # LICENSE file in the root directory of this source tree.
6
+
7
+ require_relative 'base_middleware'
8
+ require 'gooddata_datawarehouse'
9
+
10
+ module GoodData
11
+ module Bricks
12
+ class WarehouseMiddleware < Bricks::Middleware
13
+ def call(params)
14
+ if params.key?('ads_client')
15
+ puts "Setting up ADS connection to #{params['ads_client']['ads_id']}"
16
+ fail "ADS middleware needs username either as part of ads_client spec or as a global 'GDC_USERNAME' parameter" unless params['ads_client']['username'] || params['GDC_USERNAME']
17
+ fail "ADS middleware needs password either as part of ads_client spec or as a global 'GDC_PASSWORD' parameter" unless params['ads_client']['password'] || params['GDC_PASSWORD']
18
+
19
+ ads = GoodData::Datawarehouse.new(params['ads_client']['username'] || params['GDC_USERNAME'], params['ads_client']['password'] || params['GDC_PASSWORD'], params['ads_client']['ads_id'])
20
+ @app.call(params.merge('ads_client' => ads, :ads_client => ads))
21
+ else
22
+ @app.call(params)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -6,6 +6,6 @@
6
6
 
7
7
  module GoodData
8
8
  module Bricks
9
- VERSION = '0.1.0'.freeze
9
+ VERSION = '0.2.0'.freeze
10
10
  end
11
11
  end
@@ -0,0 +1,116 @@
1
+ # encoding: UTF-8
2
+ #
3
+ # Copyright (c) 2010-2015 GoodData Corporation. All rights reserved.
4
+ # This source code is licensed under the BSD-style license found in the
5
+ # LICENSE file in the root directory of this source tree.
6
+
7
+ require 'csv'
8
+ require 'digest'
9
+ require 'open-uri'
10
+
11
+ module GoodData
12
+ module Helpers
13
+ class DataSource
14
+ attr_reader :realized
15
+
16
+ def initialize(opts = {})
17
+ opts = opts.is_a?(String) ? { type: :staging, path: opts } : opts
18
+ opts = GoodData::Helpers.symbolize_keys(opts)
19
+ @source = opts[:type]
20
+ @options = opts
21
+ @realized = false
22
+ end
23
+
24
+ def realize(params = {})
25
+ @realized = true
26
+ source = @source && @source.to_s
27
+ case source
28
+ when 'ads'
29
+ realize_query(params)
30
+ when 'staging'
31
+ realize_staging(params)
32
+ when 'web'
33
+ realize_link
34
+ when 's3'
35
+ realize_s3(params)
36
+ else
37
+ fail "DataSource does not support type \"#{source}\""
38
+ end
39
+ end
40
+
41
+ def realized?
42
+ @realized == true
43
+ end
44
+
45
+ private
46
+
47
+ def realize_query(params)
48
+ query = @options[:query]
49
+ dwh = params['ads_client']
50
+ fail "Data Source needs a client to ads to be able to query the storage but 'ads_client' is empty." unless dwh
51
+ filename = Digest::SHA256.new.hexdigest(query)
52
+ measure = Benchmark.measure do
53
+ CSV.open(filename, 'w') do |csv|
54
+ header_written = false
55
+ header = nil
56
+
57
+ dwh.execute_select(query) do |row|
58
+ unless header_written
59
+ header_written = true
60
+ header = row.keys
61
+ csv << header
62
+ end
63
+ csv << row.values_at(*header)
64
+ end
65
+ end
66
+ end
67
+ puts "Realizing SQL query \"#{query}\" took #{measure.real}"
68
+ filename
69
+ end
70
+
71
+ def realize_staging(params)
72
+ path = @options[:path]
73
+ url = URI.parse(path)
74
+ filename = Digest::SHA256.new.hexdigest(path)
75
+ if url.relative?
76
+ params['gdc_project'].download_file(path, filename)
77
+ else
78
+ params['GDC_GD_CLIENT'].download_file(path, filename)
79
+ end
80
+ filename
81
+ end
82
+
83
+ def realize_link
84
+ link = @options[:url]
85
+ filename = Digest::SHA256.new.hexdigest(link)
86
+ measure = Benchmark.measure do
87
+ File.open(filename, 'w') do |f|
88
+ open(link) { |rf| f.write(rf.read) }
89
+ end
90
+ end
91
+ puts "Realizing web download from \"#{link}\" took #{measure.real}"
92
+ filename
93
+ end
94
+
95
+ def realize_s3(params)
96
+ s3_client = params['aws_client'] && params['aws_client']['s3_client']
97
+ fail 'AWS client not present. Perhaps S3Middleware is missing in the brick definition?' if !s3_client || !s3_client.respond_to?(:buckets)
98
+ bucket_name = @options[:bucket]
99
+ key = @options[:key]
100
+ fail "Key \"bucket\" is missing in S3 datasource" if bucket_name.blank?
101
+ fail "Key \"key\" is missing in S3 datasource" if key.blank?
102
+ puts "Realizing download from S3. Bucket #{bucket_name}, object with key #{key}."
103
+ filename = Digest::SHA256.new.hexdigest(@options.to_json)
104
+ bucket = s3_client.buckets[bucket_name]
105
+ obj = bucket.objects[key]
106
+ File.open(filename, 'wb') do |file|
107
+ obj.read do |chunk|
108
+ file.write(chunk)
109
+ end
110
+ end
111
+ puts 'Done downloading file.'
112
+ filename
113
+ end
114
+ end
115
+ end
116
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gooddata-bricks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Svarovsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-27 00:00:00.000000000 Z
11
+ date: 2016-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -140,6 +140,20 @@ dependencies:
140
140
  - - ">="
141
141
  - !ruby/object:Gem::Version
142
142
  version: '0'
143
+ - !ruby/object:Gem::Dependency
144
+ name: gooddata_datawarehouse
145
+ requirement: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :runtime
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
143
157
  - !ruby/object:Gem::Dependency
144
158
  name: multi_json
145
159
  requirement: !ruby/object:Gem::Requirement
@@ -176,6 +190,7 @@ files:
176
190
  - lib/gooddata/bricks/middleware/bench_middleware.rb
177
191
  - lib/gooddata/bricks/middleware/bulk_salesforce_middleware.rb
178
192
  - lib/gooddata/bricks/middleware/decode_params_middleware.rb
193
+ - lib/gooddata/bricks/middleware/dwh_middleware.rb
179
194
  - lib/gooddata/bricks/middleware/fs_download_middleware.rb
180
195
  - lib/gooddata/bricks/middleware/fs_upload_middleware.rb
181
196
  - lib/gooddata/bricks/middleware/gooddata_middleware.rb
@@ -188,6 +203,7 @@ files:
188
203
  - lib/gooddata/bricks/pipeline.rb
189
204
  - lib/gooddata/bricks/utils.rb
190
205
  - lib/gooddata/bricks/version.rb
206
+ - lib/gooddata/helpers/data_helper.rb
191
207
  homepage: https://github.com/gooddata/gooddata-bricks
192
208
  licenses:
193
209
  - BSD