bushido 0.0.35 → 0.0.36
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/.rspec +4 -0
- data/Gemfile +6 -13
- data/README.md +3 -0
- data/Rakefile +31 -7
- data/app/controllers/bushido/data_controller.rb +2 -1
- data/app/controllers/bushido/envs_controller.rb +7 -5
- data/app/controllers/bushido/mail_controller.rb +37 -0
- data/lib/bushido.rb +27 -5
- data/lib/bushido/action_mailer.rb +35 -0
- data/lib/bushido/app.rb +7 -0
- data/lib/bushido/bar.rb +19 -0
- data/lib/bushido/base.rb +23 -0
- data/lib/bushido/command.rb +17 -15
- data/lib/bushido/config.rb +12 -0
- data/lib/bushido/data.rb +41 -23
- data/lib/bushido/data_helper.rb +1 -0
- data/lib/bushido/engine.rb +21 -0
- data/lib/bushido/envs_helper.rb +1 -0
- data/lib/bushido/event.rb +25 -2
- data/lib/bushido/event_observer.rb +20 -0
- data/lib/bushido/mail_helper.rb +1 -0
- data/lib/bushido/mail_route.rb +186 -0
- data/lib/bushido/middleware.rb +9 -16
- data/lib/bushido/platform.rb +27 -3
- data/lib/bushido/smtp.rb +24 -0
- data/lib/bushido/user.rb +39 -9
- data/lib/bushido/user_helper.rb +7 -0
- data/lib/bushido/utils.rb +44 -0
- data/lib/bushido/version.rb +1 -1
- data/lib/generators/bushido/auth_migration_generator.rb +46 -0
- data/lib/generators/bushido/hooks_generator.rb +43 -0
- data/lib/generators/bushido/mail_routes_generator.rb +45 -0
- data/lib/generators/bushido/routes_generator.rb +22 -0
- data/lib/{bushido/hooks.rb → hooks.rb} +0 -0
- data/lib/rails/routes.rb +36 -8
- data/lib/tasks/bushido.rake +6 -0
- data/{test_app/spec → spec/app_spec}/controllers/envs_controller_spec.rb +0 -0
- data/spec/app_spec/controllers/mail_controller_spec.rb +28 -0
- data/{test_app/spec → spec/app_spec}/integration/app_claim_spec.rb +4 -6
- data/spec/gem_spec/base_spec.rb +24 -0
- data/spec/gem_spec/command_spec.rb +181 -0
- data/spec/gem_spec/config_spec.rb +9 -0
- data/spec/gem_spec/data_spec.rb +13 -0
- data/spec/gem_spec/hooks_spec.rb +5 -0
- data/spec/gem_spec/mail_route_spec.rb +168 -0
- data/spec/gem_spec/platform_spec.rb +9 -0
- data/spec/gem_spec/user_spec.rb +45 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/test_apps/rails-2.3/.gitignore +13 -0
- data/spec/test_apps/rails-2.3/Gemfile +13 -0
- data/spec/test_apps/rails-2.3/README +243 -0
- data/spec/test_apps/rails-2.3/Rakefile +10 -0
- data/spec/test_apps/rails-2.3/app/controllers/application_controller.rb +10 -0
- data/spec/test_apps/rails-2.3/app/helpers/application_helper.rb +3 -0
- data/spec/test_apps/rails-2.3/config/boot.rb +114 -0
- data/spec/test_apps/rails-2.3/config/environment.rb +41 -0
- data/spec/test_apps/rails-2.3/config/environments/development.rb +17 -0
- data/spec/test_apps/rails-2.3/config/environments/production.rb +28 -0
- data/spec/test_apps/rails-2.3/config/environments/test.rb +30 -0
- data/spec/test_apps/rails-2.3/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/test_apps/rails-2.3/config/initializers/cookie_verification_secret.rb +7 -0
- data/spec/test_apps/rails-2.3/config/initializers/inflections.rb +10 -0
- data/{test_app → spec/test_apps/rails-2.3}/config/initializers/mime_types.rb +0 -0
- data/spec/test_apps/rails-2.3/config/initializers/new_rails_defaults.rb +21 -0
- data/spec/test_apps/rails-2.3/config/initializers/session_store.rb +15 -0
- data/spec/test_apps/rails-2.3/config/locales/en.yml +5 -0
- data/spec/test_apps/rails-2.3/config/routes.rb +43 -0
- data/spec/test_apps/rails-2.3/db/seeds.rb +7 -0
- data/{test_app → spec/test_apps/rails-2.3}/doc/README_FOR_APP +0 -0
- data/spec/test_apps/rails-2.3/lib/tasks/rspec.rake +144 -0
- data/spec/test_apps/rails-2.3/public/404.html +30 -0
- data/spec/test_apps/rails-2.3/public/422.html +30 -0
- data/spec/test_apps/rails-2.3/public/500.html +30 -0
- data/{test_app → spec/test_apps/rails-2.3}/public/favicon.ico +0 -0
- data/{test_app → spec/test_apps/rails-2.3}/public/images/rails.png +0 -0
- data/{test_app → spec/test_apps/rails-2.3}/public/javascripts/application.js +0 -0
- data/spec/test_apps/rails-2.3/public/javascripts/controls.js +963 -0
- data/spec/test_apps/rails-2.3/public/javascripts/dragdrop.js +973 -0
- data/spec/test_apps/rails-2.3/public/javascripts/effects.js +1128 -0
- data/spec/test_apps/rails-2.3/public/javascripts/prototype.js +4320 -0
- data/{test_app → spec/test_apps/rails-2.3}/public/robots.txt +0 -0
- data/spec/test_apps/rails-2.3/script/about +4 -0
- data/spec/test_apps/rails-2.3/script/autospec +6 -0
- data/spec/test_apps/rails-2.3/script/console +3 -0
- data/spec/test_apps/rails-2.3/script/dbconsole +3 -0
- data/spec/test_apps/rails-2.3/script/destroy +3 -0
- data/spec/test_apps/rails-2.3/script/generate +3 -0
- data/spec/test_apps/rails-2.3/script/performance/benchmarker +3 -0
- data/spec/test_apps/rails-2.3/script/performance/profiler +3 -0
- data/spec/test_apps/rails-2.3/script/plugin +3 -0
- data/spec/test_apps/rails-2.3/script/runner +3 -0
- data/spec/test_apps/rails-2.3/script/server +3 -0
- data/spec/test_apps/rails-2.3/script/spec +10 -0
- data/spec/test_apps/rails-2.3/spec/all_spec.rb +5 -0
- data/spec/test_apps/rails-2.3/spec/rcov.opts +2 -0
- data/spec/test_apps/rails-2.3/spec/spec.opts +4 -0
- data/spec/test_apps/rails-2.3/spec/spec_helper.rb +83 -0
- data/spec/test_apps/rails-2.3/test/performance/browsing_test.rb +9 -0
- data/spec/test_apps/rails-2.3/test/test_helper.rb +38 -0
- data/{test_app → spec/test_apps/rails-3.0}/.gitignore +0 -0
- data/spec/test_apps/rails-3.0/.rspec +2 -0
- data/spec/test_apps/rails-3.0/Gemfile +10 -0
- data/{test_app → spec/test_apps/rails-3.0}/README +0 -0
- data/{test_app → spec/test_apps/rails-3.0}/Rakefile +0 -0
- data/{test_app → spec/test_apps/rails-3.0}/app/controllers/application_controller.rb +0 -0
- data/{test_app → spec/test_apps/rails-3.0}/app/controllers/static_controller.rb +0 -0
- data/{test_app → spec/test_apps/rails-3.0}/app/helpers/application_helper.rb +0 -0
- data/{test_app → spec/test_apps/rails-3.0}/app/helpers/static_helper.rb +0 -0
- data/{test_app → spec/test_apps/rails-3.0}/app/views/layouts/application.html.erb +0 -0
- data/{test_app → spec/test_apps/rails-3.0}/app/views/static/home.html.erb +0 -0
- data/{test_app → spec/test_apps/rails-3.0}/config.ru +0 -0
- data/{test_app → spec/test_apps/rails-3.0}/config/application.rb +2 -0
- data/{test_app → spec/test_apps/rails-3.0}/config/boot.rb +0 -0
- data/{test_app → spec/test_apps/rails-3.0}/config/environment.rb +0 -0
- data/{test_app → spec/test_apps/rails-3.0}/config/environments/development.rb +0 -0
- data/{test_app → spec/test_apps/rails-3.0}/config/environments/production.rb +0 -0
- data/{test_app → spec/test_apps/rails-3.0}/config/environments/test.rb +0 -0
- data/{test_app → spec/test_apps/rails-3.0}/config/initializers/backtrace_silencers.rb +0 -0
- data/{test_app → spec/test_apps/rails-3.0}/config/initializers/inflections.rb +0 -0
- data/spec/test_apps/rails-3.0/config/initializers/mime_types.rb +5 -0
- data/{test_app → spec/test_apps/rails-3.0}/config/initializers/secret_token.rb +0 -0
- data/{test_app → spec/test_apps/rails-3.0}/config/initializers/session_store.rb +0 -0
- data/{test_app → spec/test_apps/rails-3.0}/config/locales/en.yml +0 -0
- data/{test_app → spec/test_apps/rails-3.0}/config/routes.rb +0 -0
- data/{test_app → spec/test_apps/rails-3.0}/db/schema.rb +0 -0
- data/{test_app → spec/test_apps/rails-3.0}/db/seeds.rb +0 -0
- data/spec/test_apps/rails-3.0/doc/README_FOR_APP +2 -0
- data/{test_app → spec/test_apps/rails-3.0}/lib/tasks/.gitkeep +0 -0
- data/{test_app → spec/test_apps/rails-3.0}/public/404.html +0 -0
- data/{test_app → spec/test_apps/rails-3.0}/public/422.html +0 -0
- data/{test_app → spec/test_apps/rails-3.0}/public/500.html +0 -0
- data/{test_app/public/stylesheets/.gitkeep → spec/test_apps/rails-3.0/public/favicon.ico} +0 -0
- data/spec/test_apps/rails-3.0/public/images/rails.png +0 -0
- data/{test_app → spec/test_apps/rails-3.0}/public/index.html +0 -0
- data/spec/test_apps/rails-3.0/public/javascripts/application.js +2 -0
- data/{test_app → spec/test_apps/rails-3.0}/public/javascripts/controls.js +0 -0
- data/{test_app → spec/test_apps/rails-3.0}/public/javascripts/dragdrop.js +0 -0
- data/{test_app → spec/test_apps/rails-3.0}/public/javascripts/effects.js +0 -0
- data/{test_app → spec/test_apps/rails-3.0}/public/javascripts/prototype.js +0 -0
- data/{test_app → spec/test_apps/rails-3.0}/public/javascripts/rails.js +0 -0
- data/spec/test_apps/rails-3.0/public/robots.txt +5 -0
- data/{test_app/vendor/plugins → spec/test_apps/rails-3.0/public/stylesheets}/.gitkeep +0 -0
- data/{test_app → spec/test_apps/rails-3.0}/script/rails +0 -0
- data/spec/test_apps/rails-3.0/spec/all_spec.rb +5 -0
- data/{test_app → spec/test_apps/rails-3.0}/spec/spec_helper.rb +13 -1
- data/{test_app → spec/test_apps/rails-3.0}/test/performance/browsing_test.rb +0 -0
- data/{test_app → spec/test_apps/rails-3.0}/test/test_helper.rb +0 -0
- data/spec/test_apps/rails-3.0/vendor/plugins/.gitkeep +0 -0
- data/tasks/cover_me.rake +11 -0
- metadata +249 -117
- data/lib/engine.rb +0 -16
- data/test/executable_test.rb +0 -10
- data/test/routes_test.rb +0 -12
- data/test/test_helper.rb +0 -8
- data/test_app/.rspec +0 -1
- data/test_app/Gemfile +0 -7
- data/test_app/config/database.yml +0 -22
- data/test_app/spec/helpers/static_helper_spec.rb +0 -14
- data/test_app/spec/support/integration_example_group.rb +0 -35
data/.gitignore
CHANGED
data/.rspec
ADDED
data/Gemfile
CHANGED
@@ -4,21 +4,14 @@ source "http://rubygems.org"
|
|
4
4
|
# Specify your gem's dependencies in bushido.gemspec
|
5
5
|
gemspec
|
6
6
|
|
7
|
-
gem "rails", "~> 3.0.7"
|
8
7
|
gem "sqlite3-ruby"
|
8
|
+
gem "rails", "~> 3.0.7"
|
9
9
|
|
10
|
-
group :test do
|
10
|
+
group :development, :test do
|
11
11
|
# gem "webrat", "0.7.2", :require => false
|
12
12
|
# gem "mocha", :require => false
|
13
|
-
gem
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
# gem "sqlite3-ruby"
|
18
|
-
|
19
|
-
# group :mongoid do
|
20
|
-
# gem "mongo", "~> 1.3.0"
|
21
|
-
# gem "mongoid", "2.0.1"
|
22
|
-
# gem "bson_ext", "~> 1.3.0"
|
23
|
-
# end
|
13
|
+
gem "rspec-rails", "~> 2.7.0"
|
14
|
+
gem "configatron", "> 2.8.3"
|
15
|
+
gem "cover_me"
|
16
|
+
gem "ci_reporter"
|
24
17
|
end
|
data/README.md
ADDED
data/Rakefile
CHANGED
@@ -1,12 +1,36 @@
|
|
1
1
|
require 'rake/testtask'
|
2
|
+
require 'rspec/core/rake_task'
|
2
3
|
require 'bundler'
|
4
|
+
require 'ci/reporter/rake/rspec'
|
3
5
|
Bundler::GemHelper.install_tasks
|
4
6
|
|
5
|
-
|
7
|
+
Dir['tasks/**/*.rake'].each { |rake| load rake }
|
6
8
|
|
7
|
-
desc "
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
desc "Default: run all specs"
|
10
|
+
task :default => :all_specs
|
11
|
+
|
12
|
+
desc "Run all specs"
|
13
|
+
task :all_specs do
|
14
|
+
Rake::Task["spec"].execute
|
15
|
+
Rake::Task["dummy_specs"].execute
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "run unit tests in dummy apps"
|
19
|
+
task :dummy_specs do
|
20
|
+
Dir['spec/test_apps/**/Rakefile'].each do |rakefile|
|
21
|
+
directory_name = File.dirname(rakefile)
|
22
|
+
sh <<-CMD
|
23
|
+
cd #{directory_name} && bundle exec rake
|
24
|
+
CMD
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
desc "run unit tests for gem only"
|
29
|
+
RSpec::Core::RakeTask.new('spec') do |t|
|
30
|
+
t.pattern = '**/gem_spec/*_spec.rb'
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
if ENV["RAILS_ENV"] != "production"
|
35
|
+
require 'ci/reporter/rake/rspec'
|
36
|
+
end
|
@@ -22,8 +22,9 @@ module Bushido
|
|
22
22
|
hook_data["data"] = params["data"]
|
23
23
|
|
24
24
|
puts "Firing with: #{hook_data.inspect}"
|
25
|
+
event = "#{params['category']}.#{params['event']}".gsub('.', '_').to_sym
|
25
26
|
|
26
|
-
Bushido::Data.fire(hook_data,
|
27
|
+
Bushido::Data.fire(hook_data, event)
|
27
28
|
|
28
29
|
respond_to do |format|
|
29
30
|
format.json {render :json => {'acknowledged' => true}, :status => 200}
|
@@ -10,17 +10,19 @@ module Bushido
|
|
10
10
|
|
11
11
|
else
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
var = params[:id].upcase
|
14
|
+
|
15
|
+
ENV[var] = params[:value]
|
16
|
+
@value = ENV[var]
|
15
17
|
|
16
18
|
respond_to do |format|
|
17
|
-
if @value != ENV[
|
19
|
+
if @value != ENV[var]
|
18
20
|
format.html{render :layout => false, :text => true, :status => :unprocessable_entity}
|
19
21
|
format.json{render :status => :unprocessable_entity}
|
20
22
|
else
|
21
|
-
Bushido::Data.fire(
|
23
|
+
Bushido::Data.fire(var, {var => ENV[var]})
|
22
24
|
format.html{render :text => true}
|
23
|
-
format.json{render :json => {
|
25
|
+
format.json{render :json => {var => ENV[var]}}
|
24
26
|
end
|
25
27
|
end
|
26
28
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module Bushido
|
3
|
+
class MailController < ApplicationController
|
4
|
+
|
5
|
+
# POST /bushido/mail
|
6
|
+
def index
|
7
|
+
puts "Handling email!"
|
8
|
+
mail = {}
|
9
|
+
attachments = []
|
10
|
+
|
11
|
+
# Strip the attachments first
|
12
|
+
params.keys.each do |key|
|
13
|
+
attachments << params.delete(key) if key =~ /attachment-\d+/
|
14
|
+
end
|
15
|
+
|
16
|
+
# Copy the params to the hook data
|
17
|
+
(params.keys - ["controller", "action"]).each do |param|
|
18
|
+
mail[param.downcase] = params[param]
|
19
|
+
end
|
20
|
+
|
21
|
+
mail["attachments"] = attachments
|
22
|
+
|
23
|
+
puts "params: #{params.inspect}"
|
24
|
+
puts "mail: #{mail.inspect}"
|
25
|
+
|
26
|
+
# Output for debugging remotely
|
27
|
+
Bushido::Mailroute.pretty_print_routes
|
28
|
+
puts "Finished routing"
|
29
|
+
|
30
|
+
# Mailroute is in charge of figuring out which callback to trigger
|
31
|
+
Bushido::Mailroute.routes.process(mail)
|
32
|
+
|
33
|
+
result = {:success => true, :message => nil, :data => {}}
|
34
|
+
render :text => result.to_json, :status => 200
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/bushido.rb
CHANGED
@@ -4,12 +4,17 @@ module Bushido #:nodoc:
|
|
4
4
|
require 'json'
|
5
5
|
require 'highline/import'
|
6
6
|
require 'orm_adapter'
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
require 'bushido/engine'
|
8
|
+
if defined?(Rails) && Rails::VERSION::MAJOR == 3
|
9
|
+
require "action_dispatch"
|
10
|
+
end
|
11
11
|
require "rails/routes"
|
12
|
-
require "bushido/
|
12
|
+
require "bushido/base"
|
13
|
+
require "bushido/bar"
|
14
|
+
require "bushido/config"
|
15
|
+
require "bushido/smtp"
|
16
|
+
|
17
|
+
require "hooks"
|
13
18
|
require "bushido/platform"
|
14
19
|
require "bushido/utils"
|
15
20
|
require "bushido/command"
|
@@ -22,6 +27,23 @@ module Bushido #:nodoc:
|
|
22
27
|
require "bushido/middleware"
|
23
28
|
require "bushido/models"
|
24
29
|
require "bushido/schema"
|
30
|
+
require "bushido/event_observer"
|
31
|
+
require "bushido/mail_route"
|
32
|
+
require "bushido/user_helper"
|
33
|
+
|
34
|
+
# Manually require the controllers for rails 2
|
35
|
+
if defined?(Rails) && Rails::VERSION::MAJOR == 2
|
36
|
+
base_dir = "#{File.dirname(__FILE__)}/.."
|
37
|
+
|
38
|
+
require "#{base_dir}/app/controllers/bushido/data_controller"
|
39
|
+
require "#{base_dir}/app/controllers/bushido/mail_controller"
|
40
|
+
require "#{base_dir}/app/controllers/bushido/envs_controller"
|
41
|
+
require "bushido/action_mailer"
|
42
|
+
end
|
43
|
+
|
44
|
+
if defined?(Rails) && Rails::VERSION::MAJOR == 3
|
45
|
+
Bushido::SMTP.setup_action_mailer_smtp!
|
46
|
+
end
|
25
47
|
|
26
48
|
# Default way to setup Bushido. Run rails generate bushido_install to create
|
27
49
|
# a fresh initializer with all configuration values.
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module ActionMailer
|
2
|
+
class Base
|
3
|
+
private
|
4
|
+
def perform_delivery_bushido(mail)
|
5
|
+
if mail.to.nil?
|
6
|
+
unless logger.nil?
|
7
|
+
logger.error "This mail isn't addressed to anyone! Dropping"
|
8
|
+
end
|
9
|
+
|
10
|
+
return false
|
11
|
+
end
|
12
|
+
|
13
|
+
#result = Bushido::App.mail_allowed?
|
14
|
+
result = {"success" => true}
|
15
|
+
|
16
|
+
if result
|
17
|
+
logger.info result.inspect unless logger.nil?
|
18
|
+
if result["success"] == true
|
19
|
+
Bushido::SMTP.setup_action_mailer_smtp!
|
20
|
+
|
21
|
+
unless logger.nil?
|
22
|
+
logger.info "App allowed to send email, sending via SMTP"
|
23
|
+
logger.info "Sending:"
|
24
|
+
logger.info mail.inspect
|
25
|
+
__send__("perform_delivery_smtp", mail) if perform_deliveries
|
26
|
+
end
|
27
|
+
else
|
28
|
+
logger.info "Unable to send email: #{result['message']}" unless logger.nil?
|
29
|
+
end
|
30
|
+
else
|
31
|
+
logger.info "Unable to contact Bushido to verify email credentials" unless logger.nil?
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/bushido/app.rb
CHANGED
@@ -187,6 +187,13 @@ module Bushido
|
|
187
187
|
end
|
188
188
|
|
189
189
|
|
190
|
+
# Check if the app is allowed to send emails
|
191
|
+
# Apps are rate-limited according to their tier
|
192
|
+
def mail_allowed?
|
193
|
+
Bushido::Command.get_command(Bushido::Base.allowed_email_url)
|
194
|
+
end
|
195
|
+
|
196
|
+
|
190
197
|
def ssh_key #:nodoc:
|
191
198
|
get({:gift => "ssh_key"})["ssh_key"]
|
192
199
|
end
|
data/lib/bushido/bar.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Bushido
|
2
|
+
# Bushido::Bar
|
3
|
+
class Bar
|
4
|
+
# Default to showing the bar on all paths
|
5
|
+
@@bar_paths = [/.*/]
|
6
|
+
|
7
|
+
def self.set_bar_display_paths(*paths)
|
8
|
+
@@bar_paths = paths
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.in_bar_display_path?(env)
|
12
|
+
@@bar_paths.each do |path_regex|
|
13
|
+
return true if env['PATH_INFO'] =~ path_regex
|
14
|
+
end
|
15
|
+
|
16
|
+
return false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/bushido/base.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Bushido
|
2
|
+
class Base
|
3
|
+
class << self
|
4
|
+
url_pairs = {
|
5
|
+
:unity=>[:valid, :exists, :invite, :pending_invites, :remove, :notify],
|
6
|
+
:email=>[:send, :allowed]
|
7
|
+
}
|
8
|
+
|
9
|
+
def notify_user_url
|
10
|
+
"#{Bushido::Platform.host}/notifications.json"
|
11
|
+
end
|
12
|
+
|
13
|
+
# NOTE Cannot use define_singleton_method since ruby 1.8 compatibility is a must
|
14
|
+
url_pairs.each_pair do |prefix, method_names|
|
15
|
+
method_names.each do |method_name|
|
16
|
+
define_method "#{method_name}_#{prefix}_url".to_sym do
|
17
|
+
"#{Bushido::Platform.host}/#{prefix}/#{Bushido::Config.api_version}/#{method_name}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/bushido/command.rb
CHANGED
@@ -15,21 +15,25 @@ module Bushido
|
|
15
15
|
|
16
16
|
begin
|
17
17
|
raw = RestClient.get(url, {:params => params, :accept => :json})
|
18
|
-
rescue => e
|
19
|
-
puts e.inspect
|
18
|
+
rescue # => e
|
19
|
+
# puts e.inspect
|
20
20
|
@@last_request_successful = false
|
21
21
|
return nil
|
22
22
|
end
|
23
23
|
|
24
24
|
@@last_request_successful = true
|
25
|
-
@@last_request = JSON
|
25
|
+
@@last_request = JSON(raw)
|
26
26
|
end
|
27
27
|
|
28
28
|
def post_command(url, params)
|
29
29
|
@@request_count += 1
|
30
|
-
|
30
|
+
|
31
|
+
unless Bushido::Platform.key.nil?
|
32
|
+
params["auth_token"] ||= Bushido::Platform.key
|
33
|
+
end
|
31
34
|
|
32
35
|
begin
|
36
|
+
puts "RestClient.post(#{url}, #{params.to_json}, :content_type => :json, :accept => :json)"
|
33
37
|
raw = RestClient.post(url, params.to_json, :content_type => :json, :accept => :json)
|
34
38
|
rescue => e
|
35
39
|
puts e.inspect
|
@@ -38,39 +42,37 @@ module Bushido
|
|
38
42
|
end
|
39
43
|
|
40
44
|
@@last_request_successful = true
|
41
|
-
@@last_request = JSON
|
45
|
+
@@last_request = JSON(raw)
|
42
46
|
end
|
43
47
|
|
44
48
|
def put_command(url, params, meta={})
|
45
49
|
@@request_count += 1
|
50
|
+
|
46
51
|
if meta[:force]
|
47
52
|
params.merge!({:auth_token => Bushido::Platform.key}) if params[:auth_token].nil? unless Bushido::Platform.key.nil?
|
48
53
|
|
49
54
|
begin
|
50
55
|
raw = RestClient.put(url, params.to_json, :content_type => :json)
|
51
|
-
rescue => e
|
52
|
-
puts e.inspect
|
56
|
+
rescue # => e
|
57
|
+
# puts e.inspect
|
53
58
|
@@last_request_successful = false
|
54
59
|
return nil
|
55
60
|
end
|
56
61
|
|
57
|
-
@@last_request_successful = true
|
58
|
-
@@last_request = JSON.parse raw
|
59
|
-
|
60
62
|
else
|
61
63
|
params.merge!({:auth_token => Bushido::Platform.key}) if params[:auth_token].nil? unless Bushido::Platform.key.nil?
|
62
64
|
|
63
65
|
begin
|
64
66
|
raw = RestClient.put(url, params.to_json, :content_type => :json)
|
65
|
-
rescue => e
|
66
|
-
puts e.inspect
|
67
|
+
rescue # => e
|
68
|
+
#puts e.inspect
|
67
69
|
@@last_request_successful = false
|
68
70
|
return nil
|
69
71
|
end
|
70
|
-
|
71
|
-
@@last_request_successful = true
|
72
|
-
@@last_request = JSON.parse raw
|
73
72
|
end
|
73
|
+
|
74
|
+
@@last_request_successful = true
|
75
|
+
@@last_request = JSON.parse raw
|
74
76
|
end
|
75
77
|
|
76
78
|
def show_response(response)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Bushido
|
2
|
+
class Config
|
3
|
+
|
4
|
+
# API version defaults to v1
|
5
|
+
# Passing prefix "v" to ensure that developers assume it's a string. For future advantage when using API versions like 1.6.23
|
6
|
+
@api_version = "v1"
|
7
|
+
|
8
|
+
class << self
|
9
|
+
attr_accessor :api_version
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/bushido/data.rb
CHANGED
@@ -1,34 +1,52 @@
|
|
1
1
|
module Bushido
|
2
2
|
class Data #:nodoc:
|
3
|
+
@@observers = []
|
4
|
+
|
5
|
+
def self.add_observer(observer)
|
6
|
+
puts "Subscribing #{observer} to Bushido data calls"
|
7
|
+
@@observers << observer
|
8
|
+
end
|
3
9
|
|
4
|
-
|
10
|
+
def self.fire(data, event)
|
11
|
+
puts "Bushido Hooks Firing #{event} with => #{data.inspect}"
|
5
12
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
#
|
10
|
-
|
13
|
+
processed = false
|
14
|
+
|
15
|
+
@@observers.each do |observer|
|
16
|
+
puts "#{observer}.respond_to?(#{event}) => #{observer.respond_to?(event)}"
|
17
|
+
|
18
|
+
if observer.respond_to?(event)
|
19
|
+
processed = true
|
20
|
+
|
21
|
+
# Make a copy of the data so it's not mutated as the events
|
22
|
+
# pass through the observers
|
23
|
+
observer.instance_variable_set("@params", data.dup)
|
11
24
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
data["data"]["ido_model"] = model
|
20
|
-
#puts "Publishing Ido model"
|
21
|
-
#puts data.to_json
|
22
|
-
#puts Bushido::Platform.publish_url
|
23
|
-
|
24
|
-
# TODO: Catch non-200 response code
|
25
|
-
response = JSON.parse(RestClient.post(Bushido::Platform.publish_url, data.to_json, :content_type => :json, :accept => :json))
|
26
|
-
if response['ido_id'].nil? or response['ido_version'].nil?
|
27
|
-
return false
|
25
|
+
result = observer.send(event)
|
26
|
+
|
27
|
+
# Allow an observer to halt event propagation
|
28
|
+
if result == :halt
|
29
|
+
puts "Observer #{observer} halted event propagation"
|
30
|
+
break
|
31
|
+
end
|
28
32
|
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# We've checked all the observers to see if they respond to the
|
36
|
+
# named events, so if the event is still unprocessed then let's
|
37
|
+
# fall back on the first catch_all event we find
|
38
|
+
if !processed
|
39
|
+
@@observers.each do |observer|
|
40
|
+
if observer.respond_to?(:catch_all)
|
41
|
+
observer.instance_variable_set("@params", data.dup)
|
29
42
|
|
30
|
-
|
43
|
+
observer.send(:catch_all)
|
44
|
+
break
|
45
|
+
end
|
46
|
+
end
|
31
47
|
end
|
32
48
|
end
|
33
49
|
end
|
34
50
|
end
|
51
|
+
|
52
|
+
|