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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5ffea5bcd7bf13121cbf9e58662b75de1ace8694
4
- data.tar.gz: 22b93face9e89b75cbe2ebfd5ea7a9f92a5f8c24
3
+ metadata.gz: 7cd91c5264b5b8b3aa6e0a7172e7b68fef0bfd82
4
+ data.tar.gz: 419ff7705b031d3ff303fa133656db92d6c6ff08
5
5
  SHA512:
6
- metadata.gz: 4d7ac5841f949b8728266a25bf6b8fb3767dd74fb5f0dae2d51c1ab58d3e7b86675dd9f5ecf434ab2d06ab60097d32a62d42d73206afcf70b248a3377ad8b438
7
- data.tar.gz: 0ad0a1baab410fde48a00034c8515248e0cf13f65573a408c207068539a839f6e6796685b2b48a1663ed034d9d7cc7e1866777e6e64de96e027ad5db5fcba1e5
6
+ metadata.gz: 28d06fad824df305db85e0d3e8d2ebe0bc0deba5931f4389a8a8f237ac5f3a00c0f14d4f70eff6d942f111568043cc72fc6d812c92ad2c3e8a3ed21d0f2ae2c0
7
+ data.tar.gz: 42b3ec7c4912d5528da0b0fc6c91572528b308043bd553380af37fa6fe370a684b2f7376fdf95b6873d1bd3ad299c07436150cfde3f211b5bbd891fee4594607
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- magellan-cli (0.7.10)
4
+ magellan-cli (0.7.11)
5
5
  activesupport (~> 4.1.4)
6
6
  groovenauts-thor
7
7
  httpclient (~> 2.5)
@@ -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
- doc = Nokogiri::HTML.parse(res.body, login_form_url, res.body_encoding.to_s)
147
- node = doc.xpath('//input[@name="authenticity_token"]').first
148
- unless node
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で出力しないようにします。
@@ -2,16 +2,36 @@ require 'magellan/cli'
2
2
 
3
3
  require 'shellwords'
4
4
 
5
- def cli(args, options = {})
6
- args = Shellwords.split(args) if args.is_a?(String)
7
- args << "-V" if ARGV.include?("-V")
8
- $PROGRAM_NAME, backup = "magellan-cli", $PROGRAM_NAME
9
- puts "[CLI] `#{$PROGRAM_NAME} #{args.join(' ')}`"
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
- ensure
15
- $PROGRAM_NAME = backup
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
@@ -1,5 +1,5 @@
1
1
  module Magellan
2
2
  module Cli
3
- VERSION = "0.7.10"
3
+ VERSION = "0.7.11"
4
4
  end
5
5
  end
@@ -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.10
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-14 00:00:00.000000000 Z
11
+ date: 2015-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient