gooddata-bricks 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 19b98bdc50b16bdb85db7a9698794eba74f660ce
4
+ data.tar.gz: 826ca8b4ca96c71eca424f6dbfa17cc167a21843
5
+ SHA512:
6
+ metadata.gz: 3173fbe9fca5a422161d3d1a3e4e8d681bbad10c51d27845a4a242030237a7237b0de74273d2bdcc7a79146578b2025e86289bd5a9cb496ee07ecb95da72147b
7
+ data.tar.gz: 5d18283393e0548b0845cb6bb5e0b708d02ce54f40841fd106afd185be6b8396cf1c328a48691b0da67d74a88e27a7a6f7022ab4456b4500e2f6cc8112783961
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,11 @@
1
+ AbcSize:
2
+ Enabled: false
3
+
4
+ Documentation:
5
+ Enabled: false
6
+
7
+ LineLength:
8
+ Max: 323
9
+
10
+ MethodLength:
11
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gooddata-bricks.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ (BSD License)
2
+
3
+ Copyright (c) 2010-2016 GoodData Corporation. All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided
6
+ that the following conditions are met:
7
+
8
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and
9
+ the following disclaimer.
10
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
11
+ and the following disclaimer in the documentation and/or other materials provided with the distribution.
12
+ * Neither the name of the GoodData Corporation nor the names of its contributors may be used to endorse
13
+ or promote products derived from this software without specific prior written permission.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
16
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
18
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,35 @@
1
+ # gooddata-bricks
2
+ Base functionality for so called app store bricks. We want to extract existing functionality from gooddata-ruby and put it here.
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ ```ruby
9
+ gem 'gooddata-bricks'
10
+ ```
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install gooddata-bricks
19
+
20
+
21
+ ## Development
22
+
23
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
24
+
25
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
26
+
27
+ ## Contributing
28
+
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gooddata-bricks. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
30
+
31
+
32
+ ## License
33
+
34
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
35
+
@@ -0,0 +1,14 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require 'rubocop/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ desc 'Run RuboCop'
8
+ RuboCop::RakeTask.new(:cop) do |task|
9
+ task.patterns = ['lib/**/*.rb']
10
+ end
11
+
12
+
13
+ task :default => :spec
14
+
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gooddata/bricks/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gooddata-bricks"
8
+ spec.version = GoodData::Bricks::VERSION
9
+ spec.authors = ["Tomas Svarovsky"]
10
+ spec.email = ["svarovsky@gooddata.com"]
11
+
12
+ spec.summary = "Simple library that simplifies development of GoodData Bricks"
13
+ spec.description = "Provides some utils, simple framework and wraps some commond functionality."
14
+ spec.homepage = "https://github.com/gooddata/gooddata-bricks"
15
+ spec.license = "BSD"
16
+
17
+ # # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # # delete this section to allow pushing this gem to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.10"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rspec"
31
+ spec.add_development_dependency 'rubocop', '~> 0.34', '>= 0.34.0'
32
+
33
+ spec.add_dependency 'aws-sdk', '~> 1.45'
34
+ spec.add_dependency 'restforce', '~> 2.1', '>= 2.1.1'
35
+ spec.add_dependency 'salesforce_bulk_query', '~> 0.2', '>= 0.2.0'
36
+ spec.add_dependency 'gooddata'
37
+ spec.add_dependency 'multi_json'
38
+ end
@@ -0,0 +1,8 @@
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 'gooddata/bricks/version'
8
+ require_relative 'bricks/brick'
@@ -0,0 +1,37 @@
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 'utils'
8
+ require_relative 'middleware/middleware'
9
+ require_relative 'pipeline'
10
+
11
+ module GoodData
12
+ module Bricks
13
+ # Brick base class
14
+ class Brick
15
+ def log(message)
16
+ logger = @params[:gdc_logger]
17
+ logger.info(message) unless logger.nil?
18
+ end
19
+
20
+ # Name of the brick
21
+ def name
22
+ self.class
23
+ end
24
+
25
+ # Version of brick, this should be implemented in subclasses
26
+ def version
27
+ raise NotImplementedError, 'Method version should be reimplemented'
28
+ end
29
+
30
+ # Bricks implementation which can be 'called'
31
+ def call(params = {})
32
+ @params = params
33
+ ''
34
+ end
35
+ end
36
+ end
37
+ end
@@ -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 'aws-sdk'
8
+ require_relative 'base_middleware'
9
+
10
+ module GoodData
11
+ module Bricks
12
+ class AWSMiddleware < Bricks::Middleware
13
+ def call(params)
14
+ params = params.to_hash
15
+ if params.key?('aws_client')
16
+ puts 'Setting up AWS-S3 connection'
17
+ raise 'Unable to connect to AWS. Parameter "aws_client" seems to be empty' unless params['aws_client']
18
+ raise 'Unable to connect to AWS. Parameter "access_key_id" is missing' if params['aws_client']['access_key_id'].blank?
19
+ raise 'Unable to connect to AWS. Parameter "secret_access_key" is missing' if params['aws_client']['secret_access_key'].blank?
20
+ s3 = AWS::S3.new(params['aws_client'])
21
+ params['aws_client']['s3_client'] = s3
22
+ end
23
+ @app.call(params)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,57 @@
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 'hashie'
8
+ require 'multi_json'
9
+
10
+ module GoodData
11
+ module Bricks
12
+ class Middleware
13
+ attr_accessor :app
14
+
15
+ include Bricks::Utils
16
+
17
+ # Loads defaults to params from a json file in @config.
18
+ #
19
+ # The idea is to have a set of parameter defaults
20
+ # for a middleware. The defaults are loaded from a json file.
21
+ # If a brick user wants to override a default, they can
22
+ # do that in runtime params which come to the method in 'params'.
23
+ #
24
+ # A deep merge is done on the params. Arrays and other
25
+ # non-hash types are overwritten (params win).
26
+ #
27
+ # ### Examples
28
+ #
29
+ # A brick developer develops a SalesforceDownloaderMiddleware
30
+ # with default preset 'gse' having a configuration preset
31
+ # {"entities": ["Acount", "Event", "OpportunityLineItem", "Opportunity", "User"]}
32
+ #
33
+ # The brick user only wants to use Opportunity, so he passes
34
+ # runtime parameter {"entities": ["Opportunity"]} which overrides
35
+ # the default.
36
+ # See spec/bricks/bricks_spec.rb for usage.
37
+ def load_defaults(params)
38
+ # if default params given, fill what's not given in runtime params
39
+ if @config
40
+ # load it from file and merge it
41
+ defaults = { 'config' => MultiJson.load(File.read(@config)) }
42
+ default_params = GoodData::Helpers::DeepMergeableHash[defaults]
43
+ params = default_params.deep_merge(params)
44
+ end
45
+ params
46
+ end
47
+
48
+ def call(params)
49
+ load_defaults(params)
50
+ end
51
+
52
+ def initialize(options = {})
53
+ @app = options[:app]
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,24 @@
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 'benchmark'
8
+ require_relative 'base_middleware'
9
+
10
+ module GoodData
11
+ module Bricks
12
+ class BenchMiddleware < Bricks::Middleware
13
+ def call(params)
14
+ params = params.to_hash
15
+ puts 'Starting timer'
16
+ result = nil
17
+ report = Benchmark.measure { result = @app.call(params) }
18
+ puts 'Stopping timer'
19
+ pp report
20
+ result
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,37 @@
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 'salesforce_bulk_query'
8
+
9
+ require_relative 'base_middleware'
10
+
11
+ module GoodData
12
+ module Bricks
13
+ class BulkSalesforceMiddleware < Bricks::Middleware
14
+ DEFAULT_VERSION = '29.0'.freeze
15
+
16
+ def self.create_client(params)
17
+ salesforce = nil
18
+ if params['salesforce_client']
19
+
20
+ client = params['salesforce_client']
21
+ client.authenticate!
22
+
23
+ salesforce = SalesforceBulkQuery::Api.new(client, logger: params['GDC_LOGGER'])
24
+ # SalesforceBulkQuery adds its own Restforce logging so turn it off
25
+ Restforce.log = false if params['GDC_LOGGER']
26
+ end
27
+ params.merge('salesforce_bulk_client' => salesforce)
28
+ end
29
+
30
+ def call(params)
31
+ params = params.to_hash
32
+ params = self.class.create_client(params)
33
+ @app.call(params)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,20 @@
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
+
9
+ module GoodData
10
+ module Bricks
11
+ # Converts params from encoded hash to decoded hash
12
+ class DecodeParamsMiddleware < Bricks::Middleware
13
+ def call(params)
14
+ params = params.to_hash
15
+
16
+ @app.call(GoodData::Helpers.decode_params(params))
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,48 @@
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
+
9
+ module GoodData
10
+ module Bricks
11
+ class FsProjectDownloadMiddleware < Bricks::Middleware
12
+ def call(params)
13
+ params = params.to_hash
14
+ (params['gdc_files_to_download'] || []).each do |source|
15
+ case source[:type].to_s
16
+ when 'ads'
17
+ CSV.open(source[:to], 'w') do |csv|
18
+ header_written = false
19
+ header = nil
20
+ dwh = params['ads_client']
21
+ dwh.execute_select(source[:query]) do |row|
22
+ unless header_written
23
+ header_written = true
24
+ header = row.keys
25
+ csv << header
26
+ end
27
+ csv << row.values_at(*header)
28
+ end
29
+ end
30
+ when 'staging'
31
+ webdav_uri = GoodData.project_webdav_path
32
+ dav = Net::DAV.new(webdav_uri, curl: false)
33
+ dav.verify_server = false
34
+ dav.credentials(params['GDC_USERNAME'], params['GDC_PASSWORD'])
35
+ dav.find(path, recursive: true, suppress_errors: true) do |item|
36
+ puts 'Checking: ' + item.url.to_s
37
+ name = (item.uri - webdav_uri).to_s
38
+ File.open(name, 'w') do |f|
39
+ f << item.content
40
+ end
41
+ end
42
+ end
43
+ end
44
+ @app.call(params)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,36 @@
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
+
9
+ module GoodData
10
+ module Bricks
11
+ class FsProjectUploadMiddleware < Bricks::Middleware
12
+ def initialize(options = {})
13
+ super
14
+ @destination = options[:destination]
15
+ end
16
+
17
+ def call(params)
18
+ params = params.to_hash
19
+ returning(@app.call(params)) do |_|
20
+ destination = @destination
21
+ (params['gdc_files_to_upload'] || []).each do |f|
22
+ path = f[:path]
23
+ case destination.to_sym
24
+ when :staging
25
+ GoodData.client.get '/gdc/account/token', dont_reauth: true
26
+ url = GoodData.project_webdav_path
27
+ GoodData.upload_to_project_webdav(path)
28
+ puts "Uploaded local file \"#{path}\" to url \"#{url + path}\""
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ FsUploadMiddleware = FsProjectUploadMiddleware
35
+ end
36
+ end
@@ -0,0 +1,39 @@
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
+
9
+ module GoodData
10
+ module Bricks
11
+ class GoodDataMiddleware < Bricks::Middleware
12
+ def call(params)
13
+ params = params.to_hash
14
+ logger = params['GDC_LOGGER']
15
+ token_name = 'GDC_SST'
16
+ protocol_name = 'CLIENT_GDC_PROTOCOL'
17
+ server_name = 'CLIENT_GDC_HOSTNAME'
18
+ project_id = params['GDC_PROJECT_ID']
19
+
20
+ server = if params[protocol_name] && params[server_name]
21
+ "#{params[protocol_name]}://#{params[server_name]}"
22
+ end
23
+
24
+ client = if params['GDC_USERNAME'].nil? || params['GDC_PASSWORD'].nil?
25
+ puts "Connecting with SST to server #{server}"
26
+ raise 'SST (SuperSecureToken) not present in params' if params[token_name].nil?
27
+ GoodData.connect(sst_token: params[token_name], server: server)
28
+ else
29
+ puts "Connecting as #{params['GDC_USERNAME']} to server #{server}"
30
+ GoodData.connect(params['GDC_USERNAME'], params['GDC_PASSWORD'], server: server)
31
+ end
32
+ project = client.projects(project_id)
33
+ GoodData.project = project
34
+ GoodData.logger = logger
35
+ @app.call(params.merge('GDC_GD_CLIENT' => client, 'gdc_project' => project))
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,29 @@
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 'logger'
8
+
9
+ require_relative 'base_middleware'
10
+
11
+ module GoodData
12
+ module Bricks
13
+ class LoggerMiddleware < Bricks::Middleware
14
+ def call(params)
15
+ params = params.to_hash
16
+ logger = nil
17
+ if params['GDC_LOGGING_OFF']
18
+ logger = NilLogger.new
19
+ else
20
+ logger = params['GDC_LOGGER'] = params[:GDC_LOGGER_FILE].nil? ? Logger.new(STDOUT) : Logger.new(params[:GDC_LOGGER_FILE])
21
+ logger.info('Pipeline starts')
22
+ end
23
+ returning(@app.call(params)) do |_result|
24
+ logger.info('Pipeline ending')
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,12 @@
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 'pathname'
8
+
9
+ base = Pathname(__FILE__).dirname.expand_path
10
+ Dir.glob("#{base}/*_middleware.rb").each do |file|
11
+ require file
12
+ end
@@ -0,0 +1,61 @@
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
+ # TODO: Remove this
8
+ # require 'gooddata'
9
+
10
+ require_relative 'base_middleware'
11
+
12
+ module GoodData
13
+ module Bricks
14
+ class RestForceMiddleware < Bricks::Middleware
15
+ DEFAULT_VERSION = '29.0'.freeze
16
+
17
+ def self.prepare_credentials(downloader_config)
18
+ username = downloader_config['username']
19
+ password = downloader_config['password']
20
+ token = downloader_config['token']
21
+ oauth_refresh_token = downloader_config['oauth_refresh_token']
22
+
23
+ if username && password && token
24
+ {
25
+ username: username,
26
+ password: password,
27
+ security_token: token
28
+ }
29
+ elsif oauth_refresh_token && !oauth_refresh_token.empty?
30
+ {
31
+ refresh_token: oauth_refresh_token
32
+ }
33
+ end
34
+ end
35
+
36
+ def self.create_client(params)
37
+ downloader_config = params['config']['downloader']['salesforce']
38
+ credentials = prepare_credentials(params)
39
+
40
+ client = if credentials
41
+ credentials[:client_id] = downloader_config['client_id']
42
+ credentials[:client_secret] = downloader_config['client_secret']
43
+
44
+ host = downloader_config['host']
45
+ credentials[:host] = host if host
46
+ credentials[:api_version] = downloader_config['api_version'] || DEFAULT_VERSION
47
+
48
+ Restforce.log = true if params['GDC_LOGGER']
49
+
50
+ Restforce.new(credentials)
51
+ end
52
+ params.merge('salesforce_client' => client)
53
+ end
54
+
55
+ def call(params)
56
+ params = self.class.create_client(params)
57
+ @app.call(params)
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,23 @@
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
+
9
+ module GoodData
10
+ module Bricks
11
+ class STDOUTLoggingMiddleware < Bricks::Middleware
12
+ def call(params)
13
+ params = params.to_hash
14
+ logger = Logger.new(STDOUT)
15
+ params[:logger] = logger
16
+ logger.info('Pipeline starting with STDOUT logger')
17
+ returning(@app.call(params)) do
18
+ logger.info('Pipeline ending')
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,29 @@
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 'twitter'
8
+
9
+ require_relative 'base_middleware'
10
+
11
+ module GoodData
12
+ module Bricks
13
+ class TwitterMiddleware < Bricks::Middleware
14
+ def call(params)
15
+ params = params.to_hash
16
+ client = Twitter::REST::Client.new do |config|
17
+ config.consumer_key = params[:twitter_consumer_key]
18
+ config.consumer_secret = params[:twitter_consumer_secret]
19
+ config.access_token = params[:twitter_access_token]
20
+ config.access_token_secret = params[:twitter_access_token_secret]
21
+ end
22
+
23
+ returning(@app.call(params)) do |result|
24
+ client.update(result)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,37 @@
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
+
9
+ module GoodData
10
+ module Bricks
11
+ # Converts params from double underscore notation to nested hash under 'config'
12
+ # Parameters starting GDC_ are considered system params and aren't converted.
13
+ #
14
+ # This is useful because the executor platform can currently
15
+ # do just key-value parameters. Also it makes it easier for
16
+ # a user, as there aren't as much curly braces.
17
+ #
18
+ #
19
+ # ### Examples
20
+ # If you pass params in form:
21
+ # {"my__namespace__param": "value"}
22
+ #
23
+ # you'll get:
24
+ # {"my": {"namespace": {"param": value}}}
25
+ class UndotParamsMiddleware < Bricks::Middleware
26
+ def call(params)
27
+ params = params.to_hash
28
+ unless params['config']
29
+ # split the params to those starting with GDC and those that don't, put other params under config
30
+ gdc_params, other_params = params.partition { |k, _| k =~ /GDC_.*/ }.map { |h| Hash[h] }
31
+ params = gdc_params.merge('config' => other_params.undot)
32
+ end
33
+ @app.call(params)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,25 @@
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
+ module GoodData
8
+ module Bricks
9
+ class Pipeline
10
+ # Pipeline preparation code
11
+ def self.prepare(pipeline)
12
+ pipeline.reverse.reduce(nil) do |memo, app|
13
+ if memo.nil?
14
+ app.respond_to?(:new) ? app.new : app
15
+ elsif app.respond_to?(:new)
16
+ app.new(app: memo)
17
+ else
18
+ app.app = memo
19
+ app
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,18 @@
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
+ module GoodData
8
+ module Bricks
9
+ module Utils
10
+ def returning(value, &block)
11
+ raise 'Block was not provided' if block.nil?
12
+ return_val = value
13
+ yield value
14
+ return_val
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,11 @@
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
+ module GoodData
8
+ module Bricks
9
+ VERSION = '0.1.0'.freeze
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,215 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gooddata-bricks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tomas Svarovsky
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.34'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 0.34.0
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '0.34'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 0.34.0
75
+ - !ruby/object:Gem::Dependency
76
+ name: aws-sdk
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '1.45'
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '1.45'
89
+ - !ruby/object:Gem::Dependency
90
+ name: restforce
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '2.1'
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: 2.1.1
99
+ type: :runtime
100
+ prerelease: false
101
+ version_requirements: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - "~>"
104
+ - !ruby/object:Gem::Version
105
+ version: '2.1'
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: 2.1.1
109
+ - !ruby/object:Gem::Dependency
110
+ name: salesforce_bulk_query
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: '0.2'
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: 0.2.0
119
+ type: :runtime
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '0.2'
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: 0.2.0
129
+ - !ruby/object:Gem::Dependency
130
+ name: gooddata
131
+ requirement: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ type: :runtime
137
+ prerelease: false
138
+ version_requirements: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ - !ruby/object:Gem::Dependency
144
+ name: multi_json
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'
157
+ description: Provides some utils, simple framework and wraps some commond functionality.
158
+ email:
159
+ - svarovsky@gooddata.com
160
+ executables: []
161
+ extensions: []
162
+ extra_rdoc_files: []
163
+ files:
164
+ - ".gitignore"
165
+ - ".rspec"
166
+ - ".rubocop.yml"
167
+ - Gemfile
168
+ - LICENSE.txt
169
+ - README.md
170
+ - Rakefile
171
+ - gooddata-bricks.gemspec
172
+ - lib/gooddata/bricks.rb
173
+ - lib/gooddata/bricks/brick.rb
174
+ - lib/gooddata/bricks/middleware/aws_middleware.rb
175
+ - lib/gooddata/bricks/middleware/base_middleware.rb
176
+ - lib/gooddata/bricks/middleware/bench_middleware.rb
177
+ - lib/gooddata/bricks/middleware/bulk_salesforce_middleware.rb
178
+ - lib/gooddata/bricks/middleware/decode_params_middleware.rb
179
+ - lib/gooddata/bricks/middleware/fs_download_middleware.rb
180
+ - lib/gooddata/bricks/middleware/fs_upload_middleware.rb
181
+ - lib/gooddata/bricks/middleware/gooddata_middleware.rb
182
+ - lib/gooddata/bricks/middleware/logger_middleware.rb
183
+ - lib/gooddata/bricks/middleware/middleware.rb
184
+ - lib/gooddata/bricks/middleware/restforce_middleware.rb
185
+ - lib/gooddata/bricks/middleware/stdout_middleware.rb
186
+ - lib/gooddata/bricks/middleware/twitter_middleware.rb
187
+ - lib/gooddata/bricks/middleware/undot_params_middleware.rb
188
+ - lib/gooddata/bricks/pipeline.rb
189
+ - lib/gooddata/bricks/utils.rb
190
+ - lib/gooddata/bricks/version.rb
191
+ homepage: https://github.com/gooddata/gooddata-bricks
192
+ licenses:
193
+ - BSD
194
+ metadata: {}
195
+ post_install_message:
196
+ rdoc_options: []
197
+ require_paths:
198
+ - lib
199
+ required_ruby_version: !ruby/object:Gem::Requirement
200
+ requirements:
201
+ - - ">="
202
+ - !ruby/object:Gem::Version
203
+ version: '0'
204
+ required_rubygems_version: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ requirements: []
210
+ rubyforge_project:
211
+ rubygems_version: 2.4.6
212
+ signing_key:
213
+ specification_version: 4
214
+ summary: Simple library that simplifies development of GoodData Bricks
215
+ test_files: []