gd_bricks 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,30 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ <<<<<<< HEAD
6
+ coverage
7
+ InstalledFiles
8
+ =======
9
+ .yardoc
10
+ Gemfile.lock
11
+ InstalledFiles
12
+ _yardoc
13
+ coverage
14
+ doc/
15
+ >>>>>>> Initial commit
16
+ lib/bundler/man
17
+ pkg
18
+ rdoc
19
+ spec/reports
20
+ test/tmp
21
+ test/version_tmp
22
+ tmp
23
+ <<<<<<< HEAD
24
+
25
+ # YARD artifacts
26
+ .yardoc
27
+ _yardoc
28
+ doc/
29
+ =======
30
+ >>>>>>> Initial commit
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
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Tomas Svarovsky
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Tomas Svarovsky
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,61 @@
1
+ bricks
2
+ ======
3
+
4
+ A short POC for bricks infrastructure
5
+ =======
6
+ # Gooddata::Bricks
7
+
8
+ Bricks is a quick POC how could reusable apps in GD infrastructure work.
9
+
10
+ ## Installation
11
+
12
+ There is no installation. This is a POC not a library. If you want to play do
13
+
14
+ git clone https://github.com/fluke777/bricks_usage.git
15
+ bricks-usage
16
+ bundle install
17
+ ruby playground.rb
18
+
19
+ ## Usage
20
+
21
+ Let's say we have Bricks. These are reusable pieces of code for example for syncing users or executing all reports. You want to pass bricks some parameters and also set its execution in certain context. You want to log in to GoodData, maybe other systems, maybe measure an execution, set up logging policies etc. We are introducing a concept of Middleware which is different from brick in the sense that it has knowledge not only about parameters but also about next brick or middleware. This enables it to manipulate the parameters and influence the execution of the brick. It also allows to wrap around the execution and perform tasks like measuring time. All this is only configuration the infrastructure itself does not change so it poses less risk for breaking it down.
22
+
23
+ let's have a look at a simple example
24
+
25
+ ```ruby
26
+ app = Pipeline.prepare([HelloWorldBrick])
27
+ app.call({:who => "tomas"})
28
+ ```
29
+
30
+ this is fine but let's say we want to introduce measuring how long execution takes
31
+ There is a middleware called BenchMiddleware which benchmarks the app and then outputs the report
32
+
33
+ ```ruby
34
+ app = Pipeline.prepare([BenchMiddleware, HelloWorldBrick])
35
+ app.call({:who => "tomas"})
36
+ ```
37
+
38
+ now imagine that you would like to create a middleware that will connect you to GD based on your gd_login and gd_password or gd_sst parameters. There is a middleware that does just this.
39
+
40
+ ```ruby
41
+ app = Pipeline.prepare([BenchMiddleware, GoodDataSSTLoginMiddleware, HelloWorldBrick])
42
+ app.call({:who => "tomas", :gd_sst => "your_sst_token_comes_here"})
43
+ ```
44
+
45
+ Currently none of the middlewares is changing params but nothing keeps them from doing it. It might be useful to peek under the covers. You can easily create your own middleware. Do this
46
+
47
+ ```ruby
48
+ class MyDebuggingMiddleware < Gooddata::Bricks::Middleware
49
+ def call(params)
50
+ binding.pry
51
+ @app.call(params)
52
+ end
53
+ end
54
+ ```
55
+
56
+ now you can use it.
57
+
58
+ ```ruby
59
+ app = Pipeline.prepare([MyDebuggingMiddleware, HelloWorldBrick])
60
+ app.call({:who => "tomas", :gd_sst => "your_sst_token_comes_here"})
61
+ ```
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,28 @@
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 = "gd_bricks"
8
+ spec.version = Gooddata::Bricks::VERSION
9
+ spec.authors = ["Tomas Svarovsky"]
10
+ spec.email = ["svarovsky.tomas@gmail.com"]
11
+ spec.description = %q{Simple example how the brick might look like.}
12
+ spec.summary = %q{This is a brief summary}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "pry"
24
+
25
+ spec.add_dependency "rest-client"
26
+ spec.add_dependency "gooddata"
27
+ spec.add_dependency "twitter"
28
+ end
@@ -0,0 +1,17 @@
1
+ require 'pp'
2
+ require 'json'
3
+ require 'pry'
4
+ require 'fileutils'
5
+ require 'restclient'
6
+ require 'benchmark'
7
+
8
+ require 'gooddata'
9
+ require 'logger'
10
+
11
+ require "gooddata/bricks/utils"
12
+ require "gooddata/bricks/brick"
13
+ require "gooddata/bricks/version"
14
+
15
+
16
+ Gem.find_files("gooddata/bricks/middleware/*.rb").each { |path| require path }
17
+ Gem.find_files("gooddata/bricks/user/*.rb").each { |path| require path }
@@ -0,0 +1,42 @@
1
+ module Gooddata
2
+ module Bricks
3
+
4
+ class Pipeline
5
+ def self.prepare(pipeline)
6
+ pipeline.reverse.reduce(nil) {|memo, app| memo.nil? ? app.new : app.new(memo)}
7
+ end
8
+ end
9
+
10
+ class Middleware
11
+ include Gooddata::Bricks::Utils
12
+
13
+ def initialize(app)
14
+ @app = app
15
+ end
16
+
17
+ end
18
+
19
+ class Brick
20
+
21
+ def log(message)
22
+ logger = @params[:gdc_logger]
23
+ logger.info(message) unless logger.nil?
24
+ end
25
+
26
+ def name
27
+ self.class
28
+ end
29
+
30
+ def version
31
+ fail "Method version should be reimplemented"
32
+ end
33
+
34
+ def call(params={})
35
+ @params = params
36
+ ""
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,12 @@
1
+ class BenchMiddleware < Gooddata::Bricks::Middleware
2
+
3
+ def call(params)
4
+ puts "Starting timer"
5
+ result = nil
6
+ report = Benchmark.measure { result = @app.call(params) }
7
+ puts "Stopping timer"
8
+ pp report
9
+ result
10
+ end
11
+
12
+ end
@@ -0,0 +1,15 @@
1
+ require 'gooddata'
2
+
3
+ class GoodDataMiddleware < Gooddata::Bricks::Middleware
4
+
5
+ def call(params)
6
+ logger = params[:gdc_logger]
7
+ token_name = :gdc_sst
8
+ fail "SST (SuperSecureToken) not present in params" if params[token_name].nil?
9
+ logger.info "Connecting to GD with SST"
10
+ GoodData.connect_with_sst(params[token_name])
11
+ GoodData.logger = logger
12
+ @app.call(params)
13
+ end
14
+
15
+ end
@@ -0,0 +1,12 @@
1
+ class LoggerMiddleware < Gooddata::Bricks::Middleware
2
+
3
+ def call(params)
4
+ logger = params[:gdc_logger] = params[:gdc_logger_file].nil? ? Logger.new(STDOUT) : Logger.new(params[:gdc_logger_file])
5
+ logger.info("Pipeline starts")
6
+
7
+ returning(@app.call(params)) do |result|
8
+ logger.info("Pipeline ending")
9
+ end
10
+ end
11
+
12
+ end
@@ -0,0 +1,12 @@
1
+ class STDOUTLoggingMiddleware < Gooddata::Bricks::Middleware
2
+
3
+ def call(params)
4
+ logger = Logger.new(STDOUT)
5
+ params[:logger] = logger
6
+ logger.info("Pipeline starting with STDOUT logger")
7
+ returning(@app.call(params)) do
8
+ logger.info("Pipeline ending")
9
+ end
10
+ end
11
+
12
+ end
@@ -0,0 +1,19 @@
1
+ require 'twitter'
2
+
3
+ class TwitterMiddleware < Gooddata::Bricks::Middleware
4
+
5
+ def call(params)
6
+
7
+ client = Twitter::REST::Client.new do |config|
8
+ config.consumer_key = params[:twitter_consumer_key]
9
+ config.consumer_secret = params[:twitter_consumer_secret]
10
+ config.access_token = params[:twitter_access_token]
11
+ config.access_token_secret = params[:twitter_access_token_secret]
12
+ end
13
+
14
+ returning(@app.call(params)) do |result|
15
+ client.update(result)
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,10 @@
1
+ module Gooddata::Bricks::Utils
2
+
3
+ def returning(value, &block)
4
+ fail "Block was not provided" if block.nil?
5
+ return_val = value
6
+ block.call(value)
7
+ return_val
8
+ end
9
+
10
+ end
@@ -0,0 +1,5 @@
1
+ module Gooddata
2
+ module Bricks
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gd_bricks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tomas Svarovsky
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-12-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: pry
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rest-client
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: gooddata
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: twitter
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: Simple example how the brick might look like.
111
+ email:
112
+ - svarovsky.tomas@gmail.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .gitignore
118
+ - Gemfile
119
+ - LICENSE
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - gooddata-bricks.gemspec
124
+ - lib/gooddata/bricks.rb
125
+ - lib/gooddata/bricks/brick.rb
126
+ - lib/gooddata/bricks/middleware/bench_middleware.rb
127
+ - lib/gooddata/bricks/middleware/gooddata_middleware.rb
128
+ - lib/gooddata/bricks/middleware/logger_middleware.rb
129
+ - lib/gooddata/bricks/middleware/stdout_middleware.rb
130
+ - lib/gooddata/bricks/middleware/twitter_middleware.rb
131
+ - lib/gooddata/bricks/utils.rb
132
+ - lib/gooddata/bricks/version.rb
133
+ homepage: ''
134
+ licenses:
135
+ - MIT
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ none: false
148
+ requirements:
149
+ - - ! '>='
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 1.8.25
155
+ signing_key:
156
+ specification_version: 3
157
+ summary: This is a brief summary
158
+ test_files: []