bushido 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/bin/bushido CHANGED
@@ -3,10 +3,11 @@ require 'bushido'
3
3
 
4
4
  options = {}
5
5
 
6
- commands = [:reauth, :claim, :list, :create, :show, :start, :stop, :restart, :update, :open]
6
+ commands = [:reauth, :remove_account, :claim, :list, :create, :show, :start, :stop, :restart, :update, :open]
7
7
 
8
8
  help_docs = {
9
9
  :reauth => "bushido reauth - Reauthorize this machine to work under your Bushido account",
10
+ :remove_account => "bushido remove_account - Removes all Bushido information from this machine",
10
11
  :claim => "bushido claim [NAME] - Claim a running Bushido app as your own",
11
12
  :list => "bushido list - List all of your deployed Bushido apps",
12
13
  :create => "bushido create [URL] - Deploy a Bushido app from a git repository in URL",
@@ -47,16 +48,17 @@ command = ARGV.first
47
48
 
48
49
  if command
49
50
  case command.downcase.to_sym
50
- when :reauth then Bushido::User.reauth
51
- when :claim then Bushido::App.claim(ARGV[1])
52
- when :list then Bushido::App.list()
53
- when :create then Bushido::App.create(ARGV[1])
54
- when :show then Bushido::App.show(ARGV[1])
55
- when :start then Bushido::App.start(ARGV[1])
56
- when :stop then Bushido::App.stop(ARGV[1])
57
- when :restart then Bushido::App.restart(ARGV[1])
58
- when :update then Bushido::App.update(ARGV[1])
59
- when :open then Bushido::App.open(ARGV[1])
51
+ when :reauth then Bushido::User.reauth
52
+ when :remove_account then Bushido::User.clear_config
53
+ when :claim then Bushido::App.claim(ARGV[1])
54
+ when :list then Bushido::App.list()
55
+ when :create then Bushido::App.create(ARGV[1])
56
+ when :show then Bushido::App.show(ARGV[1])
57
+ when :start then Bushido::App.start(ARGV[1])
58
+ when :stop then Bushido::App.stop(ARGV[1])
59
+ when :restart then Bushido::App.restart(ARGV[1])
60
+ when :update then Bushido::App.update(ARGV[1])
61
+ when :open then Bushido::App.open(ARGV[1])
60
62
  end
61
63
  else
62
64
  puts "usage: bushido <command>\n\nSee bushido -h for more detailed instructions"
data/bushido.gemspec CHANGED
@@ -10,7 +10,9 @@ Gem::Specification.new do |s|
10
10
  s.email = ["s@bushi.do"]
11
11
  s.homepage = "http://trapm.com"
12
12
  s.summary = %q{Command-lin interface for bushi.do}
13
- s.description = %q{A command line tool to do everything with bushido, from signing up and deploying apps, to claiming, restarting, and updating existing apps}
13
+ s.description = %q{A command line tool to do everything with bushido, from signing up and deploying new apps, to claiming, restarting, and updating existing apps}
14
+
15
+ s.add_dependency "rest-client"
14
16
 
15
17
  s.rubyforge_project = "bushido"
16
18
 
data/lib/bushido/app.rb CHANGED
@@ -2,7 +2,9 @@ module Bushido
2
2
  class App
3
3
  class << self
4
4
  def create(url)
5
- puts "Creating account for #{Bushido::User.email}..."
5
+ Bushido::User.load_account
6
+
7
+ puts "Creating from #{url} for #{Bushido::User.email}..."
6
8
 
7
9
  post({:app => {:url => url}})
8
10
  end
@@ -30,35 +32,12 @@ module Bushido
30
32
  url = "#{Temple}/apps/#{app}.json"
31
33
  params = {:command => command}
32
34
 
33
- show_response Bushido::Command.put_command(url, params)
35
+ Bushido::Command.show_response Bushido::Command.put_command(url, params)
34
36
  end
35
37
 
36
38
  def post(params)
37
39
  url = "#{Temple}/apps"
38
- show_response Bushido::Command.post_command(url, params)
39
- end
40
-
41
- def show_response(response)
42
- show_messages response
43
- show_errors response
44
- end
45
-
46
- def show_messages(response)
47
- if response["messages"]
48
- puts "Messages:"
49
- response["messages"].each_with_index do |error, counter|
50
- puts "\t#{counter + 1}. #{error}"
51
- end
52
- end
53
- end
54
-
55
- def show_errors(response)
56
- if response["errors"]
57
- puts "Errors:"
58
- response["errors"].each_with_index do |error, counter|
59
- puts "\t#{counter + 1}. #{error}"
60
- end
61
- end
40
+ Bushido::Command.show_response Bushido::Command.post_command(url, params)
62
41
  end
63
42
 
64
43
  def show(name)
@@ -15,12 +15,43 @@ module Bushido
15
15
  response = JSON.parse raw
16
16
  end
17
17
 
18
- def put_command(url, params)
19
- Bushido::Utils.while_authorized do
18
+ def put_command(url, params, meta={})
19
+ if meta[:force]
20
20
  params.merge!({:auth_token => Bushido::User.authentication_token}) if params[:auth_token].nil? unless Bushido::User.authentication_token.nil?
21
21
 
22
22
  raw = RestClient.put(url, params.to_json, :content_type => :json)
23
23
  response = JSON.parse raw
24
+
25
+ else
26
+ Bushido::Utils.while_authorized do
27
+ params.merge!({:auth_token => Bushido::User.authentication_token}) if params[:auth_token].nil? unless Bushido::User.authentication_token.nil?
28
+
29
+ raw = RestClient.put(url, params.to_json, :content_type => :json)
30
+ response = JSON.parse raw
31
+ end
32
+ end
33
+ end
34
+
35
+ def show_response(response)
36
+ show_messages response
37
+ show_errors response
38
+ end
39
+
40
+ def show_messages(response)
41
+ if response["messages"]
42
+ puts "Messages:"
43
+ response["messages"].each_with_index do |error, counter|
44
+ puts "\t#{counter + 1}. #{error}"
45
+ end
46
+ end
47
+ end
48
+
49
+ def show_errors(response)
50
+ if response["errors"]
51
+ puts "Errors:"
52
+ response["errors"].each_with_index do |error, counter|
53
+ puts "\t#{counter + 1}. #{error}"
54
+ end
24
55
  end
25
56
  end
26
57
  end
data/lib/bushido/user.rb CHANGED
@@ -5,42 +5,43 @@ module Bushido
5
5
  load_config || {}
6
6
  end
7
7
 
8
+ def clear_config
9
+ print "Clearing out all local bushido configuration..."
10
+ FileUtils.rm_rf "#{Bushido::Utils.home_directory}/.bushido/"
11
+ puts "done"
12
+ end
13
+
8
14
  def load_config
9
15
  begin
10
- return JSON.parse(File.open(File.expand_path("~/.bushido/config.json"), 'r') { |l| l.read })
16
+ return JSON.parse(File.open(File.expand_path("#{Bushido::Utils.home_directory}/.bushido/config.json"), 'r') { |l| l.read })
11
17
  rescue Errno::ENOENT
12
18
  end
13
19
  end
14
20
 
15
21
  def load_account
16
22
  begin
17
- @account = JSON.parse(File.open(File.expand_path("~/.bushido/config.json"), 'r') { |l| l.read })
23
+ @account = JSON.parse(File.open(File.expand_path("#{Bushido::Utils.home_directory}/.bushido/config.json"), 'r') { |l| l.read })
18
24
  rescue Errno::ENOENT
19
- @account = retrieve_account
25
+ @account = retrieve_account("Couldn't find your Bushido config on this machine.")
20
26
  end
21
27
  end
22
28
 
23
29
  def reauth
24
- retrieve_account
30
+ retrieve_account("Re-authenticating your account.")
25
31
  end
26
32
 
27
33
  def update_account(account)
28
34
  print "Storing account information..."
29
- File.open(File.expand_path("~/.bushido/config.json"), 'w') { |f| f.write(account.to_json) }
35
+ Dir.mkdir "#{Bushido::Utils.home_directory}/.bushido" unless Dir.exists? "#{Bushido::Utils.home_directory}/.bushido"
36
+ File.open(File.expand_path("#{Bushido::Utils.home_directory}/.bushido/config.json"), 'w') { |f| f.write(account.to_json) }
30
37
  puts " Done!"
31
38
  end
32
39
 
33
- def retrieve_account
40
+ def retrieve_account(msg)
41
+ puts "#{msg} Enter your username and password, and we'll either retrieve if from your existing account on our servers, or create a new account for you."
34
42
  credentials = self.prompt_for_credentials
35
43
 
36
- raw = RestClient.get "#{Bushido::Temple}/users/verify.json", {:params => {:email => credentials[:email], :password => credentials[:password]}, :accept => :json}
37
-
38
- begin
39
- result = JSON.parse(raw)
40
- rescue
41
- puts "Our servers didn't respond properly while trying to retrieve the account, this seems to be an issue on our end. Please email us at support@bushi.do to clear this up."
42
- exit 1
43
- end
44
+ result = Bushido::Command.put_command "#{Bushido::Temple}/users/verify", {:email => credentials[:email], :password => credentials[:password]}, {:force => true}
44
45
 
45
46
  if result["authentication_token"] and result["error"].nil?
46
47
  update_account({:email => credentials[:email], :authentication_token => result["authentication_token"]})
@@ -49,7 +50,7 @@ module Bushido
49
50
  puts result["error"]
50
51
  if result["error_type"] == "verification_failure"
51
52
  puts ""
52
- print "If this is your first time using Bushido, would you like to create an account using the email and password you just entered?\n[y/n]"
53
+ print "If this is your first time using Bushido, would you like to create an account using the email and password you just entered?\n[y/n] "
53
54
  if $stdin.gets.chomp == "y"
54
55
  self.create_account(credentials)
55
56
  else
@@ -61,31 +62,16 @@ module Bushido
61
62
 
62
63
  def create_account(credentials)
63
64
  # GET instead of POST because of AuthenticityToken issues. Deal with it later.
64
- begin
65
- raw = RestClient.get "#{Bushido::Temple}/users/create.json", {:params => {:email => credentials[:email], :password => credentials[:password], :accept => :json}}
66
- rescue RestClient::UnprocessableEntity
67
- puts "We ran into an error registering, either our site is down or that name is registered."
68
- exit 1
69
- end
65
+ result = Bushido::Command.post_command "#{Bushido::Temple}/users/create.json", {:email => credentials[:email], :password => credentials[:password]}
70
66
 
71
- begin
72
- result = JSON.parse(raw)
73
- #puts result.inspect
74
- #puts "----------------------------------------------------------------------"
75
- rescue JSON::ParserError
76
- puts "Our servers didn't respond properly while trying to create an account, this seems to be an issue on our end. Please email us at support@bushi.do to clear this up."
77
- exit 1
78
- end
67
+ Bushido::Command.show_response result
79
68
 
80
- if result["errors"]
81
- puts "There were some errors registering: "
82
-
83
- result["errors"].each_pair { |field, error| puts " #{field.capitalize} #{error}" }
69
+ if result["errors"].nil?
70
+ update_account result
71
+ return credentials
72
+ else
84
73
  exit 1
85
74
  end
86
-
87
- update_account result
88
- return credentials
89
75
  end
90
76
 
91
77
  def authentication_token
data/lib/bushido/utils.rb CHANGED
@@ -9,6 +9,10 @@ module Bushido
9
9
  yield
10
10
  end
11
11
  end
12
+
13
+ def home_directory
14
+ ENV['HOME']
15
+ end
12
16
  end
13
17
  end
14
18
  end
@@ -1,3 +1,3 @@
1
1
  module Bushido
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Sean Grove
@@ -16,9 +16,21 @@ cert_chain: []
16
16
 
17
17
  date: 2011-01-26 00:00:00 -08:00
18
18
  default_executable:
19
- dependencies: []
20
-
21
- description: A command line tool to do everything with bushido, from signing up and deploying apps, to claiming, restarting, and updating existing apps
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rest-client
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ description: A command line tool to do everything with bushido, from signing up and deploying new apps, to claiming, restarting, and updating existing apps
22
34
  email:
23
35
  - s@bushi.do
24
36
  executables: