magellan-cli 0.7.10 → 0.7.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/magellan/cli/http.rb +21 -4
- data/lib/magellan/cli/script.rb +30 -10
- data/lib/magellan/cli/version.rb +1 -1
- data/spec/magellan/cli/login_spec.rb +9 -0
- data/spec/magellan/cli/script_spec.rb +4 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7cd91c5264b5b8b3aa6e0a7172e7b68fef0bfd82
|
4
|
+
data.tar.gz: 419ff7705b031d3ff303fa133656db92d6c6ff08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28d06fad824df305db85e0d3e8d2ebe0bc0deba5931f4389a8a8f237ac5f3a00c0f14d4f70eff6d942f111568043cc72fc6d812c92ad2c3e8a3ed21d0f2ae2c0
|
7
|
+
data.tar.gz: 42b3ec7c4912d5528da0b0fc6c91572528b308043bd553380af37fa6fe370a684b2f7376fdf95b6873d1bd3ad299c07436150cfde3f211b5bbd891fee4594607
|
data/Gemfile.lock
CHANGED
data/lib/magellan/cli/http.rb
CHANGED
@@ -143,12 +143,29 @@ module Magellan
|
|
143
143
|
|
144
144
|
def get_auth_token
|
145
145
|
res = Ssl.retry_on_ssl_error("login_form"){ debug_lf{ @httpclient.get(login_form_url) } }
|
146
|
-
|
147
|
-
|
148
|
-
|
146
|
+
case res.status
|
147
|
+
when 200
|
148
|
+
doc = Nokogiri::HTML.parse(res.body, login_form_url, res.body_encoding.to_s)
|
149
|
+
node = doc.xpath('//input[@name="authenticity_token"]').first
|
150
|
+
unless node
|
151
|
+
raise Cli::Error.new("fail to login Magellan")
|
152
|
+
end
|
153
|
+
node.attribute('value').value
|
154
|
+
when 503
|
155
|
+
begin
|
156
|
+
obj = JSON.parse(res.body)
|
157
|
+
if obj and obj["message"]
|
158
|
+
err_message = obj["message"]
|
159
|
+
else
|
160
|
+
err_message = "Under Maintenance"
|
161
|
+
end
|
162
|
+
rescue
|
163
|
+
err_message = "Under Maintenance"
|
164
|
+
end
|
165
|
+
raise Cli::Error.new("Under Maintenance")
|
166
|
+
else
|
149
167
|
raise Cli::Error.new("fail to login Magellan")
|
150
168
|
end
|
151
|
-
node.attribute('value').value
|
152
169
|
end
|
153
170
|
|
154
171
|
# @httpclient.inspectの戻り値の文字列が巨大なので、inspectで出力しないようにします。
|
data/lib/magellan/cli/script.rb
CHANGED
@@ -2,16 +2,36 @@ require 'magellan/cli'
|
|
2
2
|
|
3
3
|
require 'shellwords'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
begin
|
11
|
-
Magellan::Cli::Command.start(args) do |e|
|
12
|
-
exit(1) unless e.message =~ options[:allow]
|
5
|
+
module Magellan::Cli
|
6
|
+
module Script
|
7
|
+
SETTINGS = [:io, :prompt, :program_name]
|
8
|
+
class << self
|
9
|
+
attr_accessor *SETTINGS
|
13
10
|
end
|
14
|
-
|
15
|
-
|
11
|
+
self.io = $stdout
|
12
|
+
self.prompt = "[CLI] "
|
13
|
+
self.program_name = "magellan-cli"
|
14
|
+
|
15
|
+
SETTINGS.each do |name|
|
16
|
+
module_eval("def #{name}; Magellan::Cli::Script.#{name}; end")
|
17
|
+
end
|
18
|
+
|
19
|
+
def cli(args, options = {})
|
20
|
+
args = Shellwords.split(args) if args.is_a?(String)
|
21
|
+
args << "-V" if ARGV.include?("-V")
|
22
|
+
$PROGRAM_NAME, backup = program_name, $PROGRAM_NAME
|
23
|
+
self.io.puts "#{prompt}#{$PROGRAM_NAME} #{args.join(' ')}"
|
24
|
+
begin
|
25
|
+
Magellan::Cli::Command.start(args) do |e|
|
26
|
+
exit(1) unless e.message =~ options[:allow]
|
27
|
+
end
|
28
|
+
ensure
|
29
|
+
$PROGRAM_NAME = backup
|
30
|
+
end
|
31
|
+
end
|
32
|
+
module_function :cli
|
33
|
+
|
16
34
|
end
|
17
35
|
end
|
36
|
+
|
37
|
+
include Magellan::Cli::Script
|
data/lib/magellan/cli/version.rb
CHANGED
@@ -53,6 +53,15 @@ describe Magellan::Cli::Http do
|
|
53
53
|
allow(res).to receive(:body_encoding).and_return(Encoding.find("UTF-8"))
|
54
54
|
expect(cli.api_login!(email, password)).to eq false
|
55
55
|
end
|
56
|
+
|
57
|
+
it :login_under_maintenance do
|
58
|
+
res = double(:res)
|
59
|
+
allow(cli.httpclient).to receive(:get).with("https://example.com/users/sign_in.html").and_return(res)
|
60
|
+
allow(res).to receive(:status).and_return(503)
|
61
|
+
allow(res).to receive(:body).and_return({"success" => false, "message" => "Under Maintenance"}.to_json)
|
62
|
+
allow(res).to receive(:body_encoding).and_return(Encoding.find("UTF-8"))
|
63
|
+
expect{cli.api_login!(email, password)}.to raise_error(Magellan::Cli::Error, "Under Maintenance")
|
64
|
+
end
|
56
65
|
end
|
57
66
|
|
58
67
|
context :development do
|
@@ -4,6 +4,10 @@ require 'magellan/cli/script'
|
|
4
4
|
|
5
5
|
describe Magellan::Cli do
|
6
6
|
describe "cli" do
|
7
|
+
before do
|
8
|
+
Magellan::Cli::Script.io = StringIO.new
|
9
|
+
end
|
10
|
+
|
7
11
|
it "pass args to Magellan::Cli::Command.start" do
|
8
12
|
expect(Magellan::Cli::Command).to receive(:start).with(%w[foo bar])
|
9
13
|
cli %w[foo bar]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: magellan-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- akm2000
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpclient
|