bushido 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/bushido.gemspec +2 -2
- data/lib/bushido.rb +4 -1
- data/lib/bushido/app.rb +77 -6
- data/lib/bushido/command.rb +1 -1
- data/lib/bushido/event.rb +32 -0
- data/lib/bushido/platform.rb +1 -1
- data/lib/bushido/user.rb +29 -0
- data/lib/bushido/utils.rb +1 -1
- data/lib/bushido/version.rb +2 -1
- data/test/test_executable.rb +1 -1
- metadata +7 -5
data/Gemfile
CHANGED
data/bushido.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ["Sean Grove"]
|
10
10
|
s.email = ["s@bushi.do"]
|
11
|
-
s.homepage = "
|
12
|
-
s.summary = %q{Command-
|
11
|
+
s.homepage = "https://github.com/sgrove/bushidogem"
|
12
|
+
s.summary = %q{Command-line interface for bushi.do}
|
13
13
|
s.description = %q{A module for a Bushido app to manipulate everything about itself while running on Bushido, from deploying new apps, to claiming, restarting, updating existing apps, changing public domain, subdomains, etc.}
|
14
14
|
|
15
15
|
s.add_dependency "rest-client", ">=1.6.1"
|
data/lib/bushido.rb
CHANGED
@@ -1,12 +1,15 @@
|
|
1
|
-
module Bushido
|
1
|
+
module Bushido #:nodoc:
|
2
2
|
require 'rubygems'
|
3
3
|
require 'optparse'
|
4
4
|
require 'rest-client'
|
5
5
|
require 'json'
|
6
6
|
require 'highline/import'
|
7
|
+
require 'yaml'
|
7
8
|
|
8
9
|
require "bushido/platform"
|
9
10
|
require "bushido/utils"
|
10
11
|
require "bushido/command"
|
11
12
|
require "bushido/app"
|
13
|
+
require "bushido/user"
|
14
|
+
require "bushido/events"
|
12
15
|
end
|
data/lib/bushido/app.rb
CHANGED
@@ -1,53 +1,80 @@
|
|
1
1
|
module Bushido
|
2
|
+
# Bushido::App provides all of the methods to interact with the app it's included in,
|
3
|
+
# and only contains class methods. Each method will check for the most recent data,
|
4
|
+
# so it's possible the data may change between two separate calls.
|
2
5
|
class App
|
3
6
|
class << self
|
4
|
-
def app_url
|
7
|
+
def app_url #:nodoc:
|
5
8
|
"#{Bushido::Platform.host}/apps/#{Bushido::Platform.app}.json"
|
6
9
|
end
|
7
10
|
|
8
11
|
|
9
|
-
def get(params={})
|
12
|
+
def get(params={}) #:nodoc:
|
10
13
|
Bushido::Command.get_command(app_url, params)
|
11
14
|
end
|
12
15
|
|
13
16
|
|
14
|
-
def put(command, params={})
|
17
|
+
def put(command, params={}) #:nodoc:
|
15
18
|
params[:command] = command
|
16
19
|
|
17
20
|
Bushido::Command.put_command(app_url, params)
|
18
21
|
end
|
19
22
|
|
20
23
|
|
24
|
+
# Get all of the information related to the current app, returns a hash
|
21
25
|
def show
|
22
26
|
result = get
|
23
27
|
end
|
24
28
|
|
25
29
|
|
30
|
+
# Starts a currently stopped app
|
31
|
+
# ==== Example Scenario
|
32
|
+
# You may want to use this when recieving a \<tt>rake bushido:message</tt> event to
|
33
|
+
# start up your app for an incoming message
|
26
34
|
def start
|
27
35
|
put :start
|
28
36
|
end
|
29
37
|
|
30
38
|
|
39
|
+
# Stops an app.
|
40
|
+
# ==== Example Scenario
|
41
|
+
# Use this if you want to put your application in 'maintenance mode'.
|
31
42
|
def stop
|
32
43
|
put :stop
|
33
44
|
end
|
34
45
|
|
35
46
|
|
36
|
-
|
47
|
+
# Stops (if started) and then starts an app
|
48
|
+
# ==== Example Scenario
|
49
|
+
# if you've added environmental variables to an application and need the app
|
50
|
+
# to restart to pick them up, use this.
|
51
|
+
def restart # :nodoc:
|
37
52
|
put :restart
|
38
53
|
end
|
39
54
|
|
40
|
-
|
55
|
+
# Claims an app for the current Bushido user
|
56
|
+
# Raises an exception if app is launched anonymously
|
57
|
+
# ==== Example Scenario
|
58
|
+
# Integrate Bushido app claiming behavior directly into your app to help
|
59
|
+
# conversion rates
|
41
60
|
def claim
|
42
61
|
put :claim
|
43
62
|
end
|
44
63
|
|
45
64
|
|
65
|
+
# Updates the app to the latest git checkout, using the branch the app
|
66
|
+
# was initially dpeloyed from
|
67
|
+
# ==== Example Scenario
|
68
|
+
# Allow your users to upgrade to the latest version via a link directly in your application
|
46
69
|
def update
|
47
70
|
put :update
|
48
71
|
end
|
49
72
|
|
50
73
|
|
74
|
+
# Add an environmental variable
|
75
|
+
# ==== Example Scenario
|
76
|
+
# Allows your app to easily integrate into third-party services, e.g. mixpanel.
|
77
|
+
# A user can enter their own API key, and you can activate your mixpanel code.
|
51
78
|
def add_var(key, value)
|
52
79
|
put :add_var, {:key => key, :value => value}
|
53
80
|
if Bushido::Command.last_command_successful?
|
@@ -56,6 +83,9 @@ module Bushido
|
|
56
83
|
end
|
57
84
|
|
58
85
|
|
86
|
+
# Remove an environmental variable
|
87
|
+
# ==== Example Scenario
|
88
|
+
#
|
59
89
|
def remove_var(key)
|
60
90
|
put :remove_var, {:key => key}
|
61
91
|
if Bushido::Command.last_command_successful?
|
@@ -64,16 +94,27 @@ module Bushido
|
|
64
94
|
end
|
65
95
|
|
66
96
|
|
97
|
+
# List all custom domains belonging to the current application
|
98
|
+
# ==== Example Scenario
|
99
|
+
# A CMS may want to use this if hosting multiple sites
|
67
100
|
def domains
|
68
101
|
get()["app"]["domains"]
|
69
102
|
end
|
70
103
|
|
71
104
|
|
105
|
+
# Returns the current subdomain of the app, whether that's the default
|
106
|
+
# (e.g. "happy-rabbit-12") or a custom-set subdomain ("my-example")
|
107
|
+
# ==== Example Scenario
|
108
|
+
# A CMS will use this to know which subdomain to respond to
|
72
109
|
def subdomain
|
73
110
|
get()["app"]["subdomain"]
|
74
111
|
end
|
75
112
|
|
76
113
|
|
114
|
+
# Check if a subdomain of bushi.do is currently available
|
115
|
+
# ==== Example Scenario
|
116
|
+
# An application may want to change its subdomain to something user-chosen;
|
117
|
+
# use this before-hand to ensure it's available
|
77
118
|
def subdomain_available?(subdomain)
|
78
119
|
begin
|
79
120
|
return put :subdomain_available?, {:subdomain => subdomain}
|
@@ -83,6 +124,10 @@ module Bushido
|
|
83
124
|
end
|
84
125
|
|
85
126
|
|
127
|
+
# Set the bushi.do subdomain of an application
|
128
|
+
# ==== Example Scenario
|
129
|
+
# An app is initially launched to a randomly-generated subdomain, but may
|
130
|
+
# want to move to something more memorable for a given user.
|
86
131
|
def set_subdomain(subdomain)
|
87
132
|
result = put :set_subdomain!, {:subdomain => subdomain}
|
88
133
|
if Bushido::Command.last_command_successful?
|
@@ -95,28 +140,54 @@ module Bushido
|
|
95
140
|
end
|
96
141
|
|
97
142
|
|
143
|
+
# Adds a domain to the Bushido webrecords for an app. The app \<b>must</b>
|
144
|
+
# be a premium-app in order to add domains
|
145
|
+
# ==== Example Scenario
|
146
|
+
# If after launching a CMS a user decides to use a custom domain, an app
|
147
|
+
# can allow a user to customize it directly without resorting to the Bushido
|
148
|
+
# app control panel.
|
98
149
|
def add_domain(domain)
|
99
150
|
put :add_domain!, {:domain => domain}
|
100
151
|
end
|
101
152
|
|
102
153
|
|
154
|
+
# Removes a custom domain from the Bushido webrecords. Only works if the
|
155
|
+
# custom domain:
|
156
|
+
# * belongs to the current user
|
157
|
+
# * points at the current app
|
158
|
+
# ==== Example Scenario
|
159
|
+
# A user may decide to migrate a domain to a different app. This allows an app
|
160
|
+
# to remove it from its records without resorting to the Bushido app
|
161
|
+
# control panel
|
103
162
|
def remove_domain(domain)
|
104
163
|
put :remove_domain!, {:domain => domain}
|
105
164
|
end
|
106
165
|
|
107
166
|
|
167
|
+
# Clear out the given log
|
168
|
+
# ==== Example Scenario
|
169
|
+
# An app may keep its production log for analysis by the end-user, but the
|
170
|
+
# user may want to clear out the irrelevant past logs.
|
108
171
|
def clear_log!(name)
|
109
172
|
put :clear_log!, {:name => name}
|
110
173
|
end
|
111
174
|
|
112
175
|
|
176
|
+
# Get all of the new logs. Returns a hash of the form {:name_of_log_X => "content of log X"}
|
177
|
+
# On Bushido, there are by default the following logs:
|
178
|
+
# * access - Any page hit or asset request
|
179
|
+
# * error - Any error we had serving the page/asset
|
180
|
+
# * production - Output from the rails server
|
181
|
+
# * bushido - logs from the bushido deploy, update, start/stop process
|
182
|
+
#--
|
113
183
|
# TODO: Update to use the new logs controller
|
184
|
+
#++
|
114
185
|
def logs
|
115
186
|
get({:gift => "logs"})
|
116
187
|
end
|
117
188
|
|
118
189
|
|
119
|
-
def ssh_key
|
190
|
+
def ssh_key #:nodoc:
|
120
191
|
get({:gift => "ssh_key"})["ssh_key"]
|
121
192
|
end
|
122
193
|
end
|
data/lib/bushido/command.rb
CHANGED
@@ -0,0 +1,32 @@
|
|
1
|
+
module Bushido
|
2
|
+
# Bushido::Event lists all the events from the Bushido server. All events
|
3
|
+
# are hashes with the following keys:
|
4
|
+
# * category
|
5
|
+
# * name
|
6
|
+
# * data
|
7
|
+
# Data will hold the arbitrary data for the type of event signalled
|
8
|
+
class Event
|
9
|
+
begin
|
10
|
+
@@events = YAML.load(ENV["BUSHIDO_EVENTS"]) #:nodoc:
|
11
|
+
rescue
|
12
|
+
@@events = []
|
13
|
+
end
|
14
|
+
|
15
|
+
class << self
|
16
|
+
# Lists all events
|
17
|
+
def all
|
18
|
+
@@events
|
19
|
+
end
|
20
|
+
|
21
|
+
# Lists the first (oldest) event
|
22
|
+
def first
|
23
|
+
@@events.first
|
24
|
+
end
|
25
|
+
|
26
|
+
# Lists the last (newest) event
|
27
|
+
def last
|
28
|
+
@@events.last
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/bushido/platform.rb
CHANGED
data/lib/bushido/user.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Bushido
|
2
|
+
# Bushido User enables user validation against Bushido's server
|
3
|
+
class User
|
4
|
+
class << self
|
5
|
+
def unity_url #:nodoc:
|
6
|
+
"#{Bushido::Platform.host}/connect/v1"
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
# Checks whether user an email and password correspond to a valid bushido
|
11
|
+
# user. Returns nil if false, or the Bushido user's ID if true.
|
12
|
+
def valid?(email, pass)
|
13
|
+
params = {}
|
14
|
+
params[:email] = email
|
15
|
+
params[:pass] = pass
|
16
|
+
Bushido::Command.post_command("#{unity_url}/valid", params)
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
# Checks whether email corresponds to a valid Bushido user.
|
21
|
+
# Returns true or false
|
22
|
+
def exists?(email)
|
23
|
+
params = {}
|
24
|
+
params[:email] = email
|
25
|
+
Bushido::Command.post_command("#{unity_url}/exists", params)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/bushido/utils.rb
CHANGED
data/lib/bushido/version.rb
CHANGED
data/test/test_executable.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: bushido
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.13
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Sean Grove
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-05-27 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -64,12 +64,14 @@ files:
|
|
64
64
|
- lib/bushido.rb
|
65
65
|
- lib/bushido/app.rb
|
66
66
|
- lib/bushido/command.rb
|
67
|
+
- lib/bushido/event.rb
|
67
68
|
- lib/bushido/platform.rb
|
69
|
+
- lib/bushido/user.rb
|
68
70
|
- lib/bushido/utils.rb
|
69
71
|
- lib/bushido/version.rb
|
70
72
|
- test/test_executable.rb
|
71
73
|
has_rdoc: true
|
72
|
-
homepage:
|
74
|
+
homepage: https://github.com/sgrove/bushidogem
|
73
75
|
licenses: []
|
74
76
|
|
75
77
|
post_install_message:
|
@@ -92,9 +94,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
94
|
requirements: []
|
93
95
|
|
94
96
|
rubyforge_project: bushido
|
95
|
-
rubygems_version: 1.
|
97
|
+
rubygems_version: 1.6.2
|
96
98
|
signing_key:
|
97
99
|
specification_version: 3
|
98
|
-
summary: Command-
|
100
|
+
summary: Command-line interface for bushi.do
|
99
101
|
test_files:
|
100
102
|
- test/test_executable.rb
|