gooddata 0.6.0.pre2 → 0.6.0.pre3

Sign up to get free protection for your applications and to get access to all the features.
@@ -44,6 +44,11 @@ desc 'Verbose mode'
44
44
  arg_name 'verbose'
45
45
  switch [:v,:verbose]
46
46
 
47
+ desc 'Http logger on stdout'
48
+ arg_name 'logger'
49
+ switch [:l,:logger]
50
+
51
+
47
52
  desc 'Describe list here'
48
53
  arg_name 'Describe arguments to list here'
49
54
  command :process do |c|
@@ -230,17 +235,22 @@ command :run_ruby do |c|
230
235
 
231
236
 
232
237
  c.action do |global_options, options, args|
233
-
238
+ options[:params] = if (options[:params])
239
+ JSON.parse(File.read(options[:params]), :symbolize_names => true)
240
+ else
241
+ {}
242
+ end
243
+
234
244
  opts = options.merge(global_options).merge({:project_id => options[:project], "project_id" => options[:project], :type => "RUBY"})
235
-
236
245
  if options[:remote]
246
+ fail "You have to specify name of the deploy when deploying remotely" if options[:name].nil? || options[:name].empty?
237
247
  require 'gooddata/commands/process'
238
248
  GoodData::Command::Process.run(options[:dir], opts) do
239
249
  puts "would run"
240
250
  end
241
251
  else
242
252
  require 'gooddata/commands/runners'
243
- GoodData::Command::Runners.run_ruby(options[:dir], options)
253
+ GoodData::Command::Runners.run_ruby_locally(options[:dir], opts)
244
254
  end
245
255
  end
246
256
  end
@@ -260,7 +270,7 @@ end
260
270
 
261
271
  pre do |global,command,options,args|
262
272
  require 'logger'
263
- GoodData.logger = Logger.new(STDOUT)
273
+ GoodData.logger = Logger.new(STDOUT) if global[:l]
264
274
  username = global[:username]
265
275
  password = global[:password]
266
276
 
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
13
13
  s.authors = ["Pavel Kolesnikov", "Thomas Watson Steen"]
14
14
  s.summary = %q{A convenient Ruby wrapper around the GoodData RESTful API}
15
15
  s.date = %q{2012-12-17}
16
- s.description = %q{Use the Gooddata::Client class to integrate GoodData into your own application or use the CLI to work with GoodData directly from the command line.}
16
+ s.description = %q{Use the GoodData::Client class to integrate GoodData into your own application or use the CLI to work with GoodData directly from the command line.}
17
17
  s.email = %q{pavel@gooddata.com}
18
18
  s.executables = ["gooddata"]
19
19
  s.extra_rdoc_files = [
@@ -25,12 +25,12 @@ Gem::Specification.new do |s|
25
25
  s.require_paths = ["lib"]
26
26
  s.rubygems_version = "1.3.7"
27
27
 
28
- s.add_development_dependency "bundler"
29
28
  s.add_development_dependency "thoughtbot-shoulda"
30
29
  s.add_development_dependency "pry"
31
30
  s.add_development_dependency "rake"
32
31
  s.add_development_dependency "rspec"
33
32
 
33
+ s.add_dependency "bundler"
34
34
  s.add_dependency "parseconfig"
35
35
  s.add_dependency "json_pure"
36
36
  s.add_dependency "rest-client"
@@ -40,6 +40,7 @@ Gem::Specification.new do |s|
40
40
  s.add_dependency "gli"
41
41
  s.add_dependency "pry"
42
42
  s.add_dependency "erubis"
43
+ s.add_dependency "activesupport"
43
44
 
44
45
  end
45
46
 
@@ -1,4 +1,6 @@
1
1
  module GoodData; end
2
2
 
3
+ require 'active_support/all'
3
4
  require 'gooddata/client'
4
5
  require 'gooddata/model'
6
+ require 'gooddata/bricks/brick'
@@ -0,0 +1,40 @@
1
+ require 'gooddata/bricks/utils'
2
+ require 'gooddata/bricks/middleware/middleware'
3
+ require 'gooddata/bricks/middleware/bench_middleware'
4
+ require 'gooddata/bricks/middleware/gooddata_middleware'
5
+ require 'gooddata/bricks/middleware/logger_middleware'
6
+ require 'gooddata/bricks/middleware/stdout_middleware'
7
+
8
+ module GoodData
9
+ module Bricks
10
+
11
+ class Pipeline
12
+ def self.prepare(pipeline)
13
+ pipeline.reverse.reduce(nil) {|memo, app| memo.nil? ? app.new : app.new(memo)}
14
+ end
15
+ end
16
+
17
+ class Brick
18
+
19
+ def log(message)
20
+ logger = @params[:gdc_logger]
21
+ logger.info(message) unless logger.nil?
22
+ end
23
+
24
+ def name
25
+ self.class
26
+ end
27
+
28
+ def version
29
+ fail "Method version should be reimplemented"
30
+ end
31
+
32
+ def call(params={})
33
+ @params = params
34
+ ""
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,14 @@
1
+ require 'benchmark'
2
+
3
+ class BenchMiddleware < GoodData::Bricks::Middleware
4
+
5
+ def call(params)
6
+ puts "Starting timer"
7
+ result = nil
8
+ report = Benchmark.measure { result = @app.call(params) }
9
+ puts "Stopping timer"
10
+ pp report
11
+ result
12
+ end
13
+
14
+ end
@@ -0,0 +1,22 @@
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
+ protocol_name = :GDC_PROTOCOL
9
+ server_name = :GDC_SERVER
10
+
11
+ fail "SST (SuperSecureToken) not present in params" if params[token_name].nil?
12
+ logger.info "Connecting to GD with SST"
13
+ server = if !params[protocol_name].empty? && !params[server_name].empty?
14
+ params[protocol_name] + "://" + params[server_name]
15
+ end
16
+
17
+ GoodData.connect_with_sst(params[token_name], {:server => server})
18
+ GoodData.logger = logger
19
+ @app.call(params)
20
+ end
21
+
22
+ end
@@ -0,0 +1,14 @@
1
+ require 'logger'
2
+
3
+ class LoggerMiddleware < GoodData::Bricks::Middleware
4
+
5
+ def call(params)
6
+ logger = params[:gdc_logger] = params[:GDC_LOGGER_FILE].nil? ? Logger.new(STDOUT) : Logger.new(params[:GDC_LOGGER_FILE])
7
+ logger.info("Pipeline starts")
8
+
9
+ returning(@app.call(params)) do |result|
10
+ logger.info("Pipeline ending")
11
+ end
12
+ end
13
+
14
+ end
@@ -0,0 +1,11 @@
1
+ module GoodData::Bricks
2
+
3
+ class Middleware
4
+ include GoodData::Bricks::Utils
5
+
6
+ def initialize(app)
7
+ @app = app
8
+ end
9
+
10
+ end
11
+ 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,12 @@
1
+ module GoodData::Bricks
2
+ module Utils
3
+
4
+ def returning(value, &block)
5
+ fail "Block was not provided" if block.nil?
6
+ return_val = value
7
+ block.call(value)
8
+ return_val
9
+ end
10
+
11
+ end
12
+ end
@@ -1,6 +1,5 @@
1
1
  require 'gooddata/version'
2
2
  require 'gooddata/connection'
3
- require 'active_support/core_ext/string'
4
3
 
5
4
  # fastercsv is built in Ruby 1.9
6
5
  if RUBY_VERSION < "1.9"
@@ -112,9 +111,7 @@ module GoodData
112
111
  # * +options+ - :cookies => you can specify a hash of cookies
113
112
  #
114
113
  def create_authenticated_connection(options={})
115
- url = options[:server]
116
-
117
- connect("", "", url, options)
114
+ connect(options)
118
115
  server_cookies = options[:cookies]
119
116
  connection.merge_cookies!(server_cookies)
120
117
  connection.status = :logged_in
@@ -34,7 +34,7 @@ module GoodData::Command
34
34
 
35
35
 
36
36
  type = options[:type] || fail("Type of deployment is not specified")
37
- deploy_name = "AAAAA"
37
+ deploy_name = options[:name]
38
38
  verbose = options[:verbose] || false
39
39
  project_pid = options[:project_pid]
40
40
  puts HighLine::color("Deploying #{dir}", HighLine::BOLD) if verbose
@@ -78,8 +78,8 @@ module GoodData::Command
78
78
  if type == :ruby
79
79
  result = GoodData.post(link, {
80
80
  :execution => {
81
- :graph => dir + "main.rb",
82
- :params => {}
81
+ :graph => (dir + "main.rb").to_s,
82
+ :params => options[:params]
83
83
  }
84
84
  })
85
85
  begin
@@ -117,17 +117,17 @@ module GoodData::Command
117
117
  def self.run(dir, options={})
118
118
  email = options[:email]
119
119
  verbose = options[:v]
120
-
121
120
  dir = Pathname(dir)
121
+ name = options[:name] || "Temporary deploy[#{dir}][#{options[:project_name]}]"
122
122
 
123
- with_deploy(dir, options.merge(:name => "Temporary deploy[#{dir}][#{options[:project_name]}]")) do |deploy_response|
123
+ with_deploy(dir, options.merge(:name => name)) do |deploy_response|
124
124
  puts HighLine::color("Executing", HighLine::BOLD) if verbose
125
125
  # if email.nil?
126
126
  # result = execute_process(deploy_response["process"]["links"]["executions"], dir, options)
127
127
  # else
128
128
  # create_email_channel(options) do |channel_response|
129
129
  # subscribe_on_finish(:success, channel_response, deploy_response, options)
130
- result = execute_process(deploy_response["process"]["links"]["executions"], dir)
130
+ result = execute_process(deploy_response["process"]["links"]["executions"], dir, options)
131
131
  # end
132
132
  # end
133
133
  end
@@ -1,33 +1,38 @@
1
+ require 'bundler'
2
+
1
3
  module GoodData::Command
2
4
  class Runners
3
5
 
4
- def self.run_ruby(brick_dir, options={})
6
+ def self.run_ruby_locally(brick_dir, options={})
5
7
  pid = options[:project]
6
8
  fail "You have to specify a project ID" if pid.nil?
7
- fail "You have to specify directory of the brick ran" if brick_dir.nil?
9
+ fail "You have to specify directory of the brick run" if brick_dir.nil?
10
+ fail "You specified file as a birck run directory. You have to specify directory." if File.exist?(brick_dir) && !File.directory?(brick_dir)
8
11
 
9
- params = if options[:params]
10
- JSON.parse(File.read(options[:params]), :symbolize_names => true)
11
- else
12
- {}
13
- end
12
+ params = options[:params] || {}
14
13
 
15
14
  GoodData.connection.connect!
16
15
  sst = GoodData.connection.cookies[:cookies]["GDCAuthSST"]
17
-
16
+ pwd = Pathname.new(Dir.pwd)
18
17
  logger_stream = STDOUT
18
+
19
+ server_uri = URI(options[:server]) unless options[:server].nil?
20
+ scheme = server_uri.nil? ? "" : server_uri.scheme
21
+ hostname = server_uri.nil? ? "" : server_uri.host
22
+
19
23
  script_body = <<-script_body
20
24
  require 'fileutils'
21
- FileUtils::cd(\"#{brick_dir}\") do\
25
+ FileUtils::cd(\"#{pwd+brick_dir}\") do\
22
26
  require 'bundler/setup'
23
27
  eval(File.read(\"main.rb\")).call({
24
- :gdc_sst => \"#{sst}\",
25
- :gdc_project => \"#{pid}\"
28
+ :GDC_SST => \"#{sst}\",
29
+ :GDC_PROJECT_ID => \"#{pid}\",
30
+ :GDC_PROTOCOL => \"#{scheme}\",
31
+ :GDC_SERVER => \"#{hostname}\"
26
32
  }.merge(#{params}))
27
33
  end
28
34
  script_body
29
35
 
30
-
31
36
  Bundler.with_clean_env do
32
37
  system("ruby", "-e", script_body)
33
38
  end
@@ -52,7 +52,6 @@ module GoodData
52
52
  end
53
53
 
54
54
  def create(options={})
55
- binding.pry
56
55
  stuff = {
57
56
  "projectDashboard" => {
58
57
  "content" => {
@@ -67,7 +67,6 @@ module GoodData
67
67
  end
68
68
  end
69
69
  puts HighLine::color("Deploy DONE #{dir}", HighLine::BOLD) if verbose
70
- binding.pry
71
70
  res
72
71
  end
73
72
  end
@@ -1,3 +1,3 @@
1
1
  module GoodData
2
- VERSION = "0.6.0.pre2"
2
+ VERSION = "0.6.0.pre3"
3
3
  end
@@ -1,4 +1,4 @@
1
- class MyBrick < Gooddata::Bricks::Brick
1
+ class MyBrick < GoodData::Bricks::Brick
2
2
 
3
3
  def call(params)
4
4
  # do something here
@@ -1,4 +1,4 @@
1
1
  require 'gooddata/bricks'
2
2
  require './mybrick'
3
3
 
4
- Gooddata::Bricks::Pipeline.prepare([LoggerMiddleware, BenchMiddleware, GoodDataMiddleware, MyBrick])
4
+ GoodData::Bricks::Pipeline.prepare([LoggerMiddleware, BenchMiddleware, GoodDataMiddleware, MyBrick])
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.pre2
4
+ version: 0.6.0.pre3
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ cert_chain: []
13
13
  date: 2012-12-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: bundler
16
+ name: thoughtbot-shoulda
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
@@ -29,7 +29,7 @@ dependencies:
29
29
  - !ruby/object:Gem::Version
30
30
  version: '0'
31
31
  - !ruby/object:Gem::Dependency
32
- name: thoughtbot-shoulda
32
+ name: pry
33
33
  requirement: !ruby/object:Gem::Requirement
34
34
  none: false
35
35
  requirements:
@@ -45,7 +45,7 @@ dependencies:
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
47
  - !ruby/object:Gem::Dependency
48
- name: pry
48
+ name: rake
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
@@ -61,7 +61,7 @@ dependencies:
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  - !ruby/object:Gem::Dependency
64
- name: rake
64
+ name: rspec
65
65
  requirement: !ruby/object:Gem::Requirement
66
66
  none: false
67
67
  requirements:
@@ -77,14 +77,14 @@ dependencies:
77
77
  - !ruby/object:Gem::Version
78
78
  version: '0'
79
79
  - !ruby/object:Gem::Dependency
80
- name: rspec
80
+ name: bundler
81
81
  requirement: !ruby/object:Gem::Requirement
82
82
  none: false
83
83
  requirements:
84
84
  - - ! '>='
85
85
  - !ruby/object:Gem::Version
86
86
  version: '0'
87
- type: :development
87
+ type: :runtime
88
88
  prerelease: false
89
89
  version_requirements: !ruby/object:Gem::Requirement
90
90
  none: false
@@ -236,7 +236,23 @@ dependencies:
236
236
  - - ! '>='
237
237
  - !ruby/object:Gem::Version
238
238
  version: '0'
239
- description: Use the Gooddata::Client class to integrate GoodData into your own application
239
+ - !ruby/object:Gem::Dependency
240
+ name: activesupport
241
+ requirement: !ruby/object:Gem::Requirement
242
+ none: false
243
+ requirements:
244
+ - - ! '>='
245
+ - !ruby/object:Gem::Version
246
+ version: '0'
247
+ type: :runtime
248
+ prerelease: false
249
+ version_requirements: !ruby/object:Gem::Requirement
250
+ none: false
251
+ requirements:
252
+ - - ! '>='
253
+ - !ruby/object:Gem::Version
254
+ version: '0'
255
+ description: Use the GoodData::Client class to integrate GoodData into your own application
240
256
  or use the CLI to work with GoodData directly from the command line.
241
257
  email: pavel@gooddata.com
242
258
  executables:
@@ -258,6 +274,14 @@ files:
258
274
  - examples.rb
259
275
  - gooddata.gemspec
260
276
  - lib/gooddata.rb
277
+ - lib/gooddata/bricks/brick.rb
278
+ - lib/gooddata/bricks/middleware/bench_middleware.rb
279
+ - lib/gooddata/bricks/middleware/gooddata_middleware.rb
280
+ - lib/gooddata/bricks/middleware/logger_middleware.rb
281
+ - lib/gooddata/bricks/middleware/middleware.rb
282
+ - lib/gooddata/bricks/middleware/stdout_middleware.rb
283
+ - lib/gooddata/bricks/middleware/twitter_middleware.rb
284
+ - lib/gooddata/bricks/utils.rb
261
285
  - lib/gooddata/client.rb
262
286
  - lib/gooddata/commands/api.rb
263
287
  - lib/gooddata/commands/auth.rb