magellan-cli 0.2.2 → 0.2.3

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: afa7a868a64b02328acb0a38a2bfb053de87e49b
4
- data.tar.gz: bcabb60c11b143ea38770f29c8067c99e52b56eb
3
+ metadata.gz: 5c657e803c1316bbcf6ab385531c2399076d4370
4
+ data.tar.gz: 46fa633ed4fec7b8bb9f55ab446192ff7dbe7a9d
5
5
  SHA512:
6
- metadata.gz: 9f0d1be5fc876158a71a669a6bb216f0ff349c55d9e5617037087b3a21c3bc6addd26fb468081a82073be2cdf88189af2d1def64d0f8c075fab4930902a19bb2
7
- data.tar.gz: eebc2f8eb73895bee74cb42746b983e4f13efbc75dde1fe3a132a354426390bdb11bd8dde8c93d4126823e2b5d1fce9a86017e4662c50945adf867cdd709e0c3
6
+ metadata.gz: c1e084d92a653dbbd5e0596752d60c19ae6e2450efb6ab54920ccbfcbea71813818c7a5774b5e0e0cb32bbe6e0530c6f2df715bcfe3fc074de51fba4727f2c6c
7
+ data.tar.gz: 2e9ecec939e2e7d57718aec804f9a55d6f1aaace363d38b29ee953535d018a84a1c10ba96cbdb3f9c483e65f019520a4eda6e5a648d9a69d0d9efd6b65027416
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- magellan-cli (0.2.2)
4
+ magellan-cli (0.2.3)
5
5
  activesupport (~> 4.1.4)
6
6
  httpclient
7
7
  nokogiri
@@ -13,6 +13,22 @@ module Magellan
13
13
  return block_given? ? yield(cli) : success("OK")
14
14
  end
15
15
 
16
+ def check_response(res)
17
+ case res.status
18
+ when 200...300 then
19
+ r = JSON.parse(res.body)
20
+ verbose(JSON.pretty_generate(r))
21
+ r
22
+ else
23
+ obj = JSON.parse(res.body) rescue nil
24
+ if obj and obj.is_a?(Hash) and obj["message"]
25
+ error(obj["message"])
26
+ else
27
+ error("HTTP Error: status=#{res.status}: #{res.body}")
28
+ end
29
+ end
30
+ end
31
+
16
32
  # ログインしてGETします
17
33
  # @param [String] rel_path cli.base_url からの相対パス
18
34
  # @param [Hash] params クエリ文字列
@@ -28,7 +44,7 @@ module Magellan
28
44
  $stderr, bak = StringIO.new, $stderr
29
45
  begin
30
46
  res = cli.httpclient.get(url)
31
- return JSON.parse(res.body)
47
+ check_response(res)
32
48
  ensure
33
49
  $stderr = bak
34
50
  end
@@ -93,18 +109,7 @@ module Magellan
93
109
  url = "#{cli.base_url}#{rel_path}"
94
110
  verbose("%s %s\n%s" % [http_method, url, args])
95
111
  res = cli.httpclient.send(http_method, url, *args)
96
- case res.status
97
- when 200...300 then
98
- r = JSON.parse(res.body)
99
- verbose(JSON.pretty_generate(r))
100
- unless r["success"]
101
- error(r["message"])
102
- end
103
- return r
104
- else
105
- info("\e[31m[#{res.status}]\e[0m\ #{res.body}")
106
- return nil
107
- end
112
+ check_response(res)
108
113
  end
109
114
 
110
115
  end
@@ -100,6 +100,9 @@ module Magellan
100
100
  res = Ssl.retry_on_ssl_error("login_form"){ @httpclient.get(login_form_url) }
101
101
  doc = Nokogiri::HTML.parse(res.body, login_form_url, res.body_encoding.to_s)
102
102
  node = doc.xpath('//input[@name="authenticity_token"]').first
103
+ unless node
104
+ raise Cli::Error.new("fail to login Magellan")
105
+ end
103
106
  node.attribute('value').value
104
107
  end
105
108
 
@@ -23,7 +23,7 @@ module Magellan
23
23
  "version" => version,
24
24
  }
25
25
  }
26
- post_json("/admin/#{resource_name}/new.js", params)
26
+ post_json("/admin/#{resource_name}/new.json", params)
27
27
  end
28
28
  end
29
29
 
@@ -19,7 +19,7 @@ module Magellan
19
19
  "name" => name,
20
20
  }
21
21
  }
22
- post_json("/admin/#{resource_name}/new.js", params)
22
+ post_json("/admin/#{resource_name}/new.json", params)
23
23
  end
24
24
 
25
25
  desc "delete ID", "delete CloudSQL Database"
@@ -16,7 +16,7 @@ module Magellan
16
16
  "name" => name,
17
17
  }
18
18
  }
19
- post_json("/admin/#{self.resource_name}/new.js", params)
19
+ post_json("/admin/#{self.resource_name}/new.json", params)
20
20
  end
21
21
  end
22
22
 
@@ -27,7 +27,7 @@ module Magellan
27
27
  "name" => name,
28
28
  }
29
29
  }
30
- post_json("/admin/#{resource_name}/new.js", params)
30
+ post_json("/admin/#{resource_name}/new.json", params)
31
31
  end
32
32
  end
33
33
 
@@ -27,7 +27,7 @@ module Magellan
27
27
  "stage_type" => type,
28
28
  }
29
29
  }
30
- post_json("/admin/#{resource_name}/new.js", params)
30
+ post_json("/admin/#{resource_name}/new.json", params)
31
31
  end
32
32
 
33
33
  desc "select NAME", "select Stage named by NAME"
@@ -23,7 +23,7 @@ module Magellan
23
23
  "role" => role,
24
24
  }
25
25
  }
26
- post_json("/admin/#{self.resource_name}/new.js", params)
26
+ post_json("/admin/#{self.resource_name}/new.json", params)
27
27
  end
28
28
 
29
29
  =begin
@@ -19,7 +19,7 @@ module Magellan
19
19
  # "instance_base_name" => name,
20
20
  }
21
21
  }
22
- post_json("/admin/#{self.resource_name}/new.js", params)
22
+ post_json("/admin/#{self.resource_name}/new.json", params)
23
23
  end
24
24
 
25
25
  end
@@ -30,7 +30,7 @@ module Magellan
30
30
  # "instance_base_name" => name,
31
31
  }.update(attrs)
32
32
  }
33
- post_json("/admin/#{self.resource_name}/new.js", params)
33
+ post_json("/admin/#{self.resource_name}/new.json", params)
34
34
  end
35
35
 
36
36
  end
@@ -1,5 +1,5 @@
1
1
  module Magellan
2
2
  module Cli
3
- VERSION = "0.2.2"
3
+ VERSION = "0.2.3"
4
4
  end
5
5
  end
@@ -20,7 +20,7 @@ describe Magellan::Cli::Resources::ClientVersion do
20
20
  describe :success do
21
21
  before do
22
22
  expect(cmd).to receive(:load_selections).and_return({"project" => {"id" => 1, "name" => "ProjectA"}, "stage" => {"id" => 1, "name" => "StageA"} })
23
- expect(cmd).to receive(:post_json).with("/admin/client_version/new.js", { "client_version" => { "stage_title_id" => 1, "version" => "1.1.0" } })
23
+ expect(cmd).to receive(:post_json).with("/admin/client_version/new.json", { "client_version" => { "stage_title_id" => 1, "version" => "1.1.0" } })
24
24
  end
25
25
  it do
26
26
  cmd.create("1.1.0")
@@ -17,7 +17,7 @@ describe Magellan::Cli::Resources::Organization do
17
17
 
18
18
  describe :create do
19
19
  before do
20
- expect(cmd).to receive(:post_json).with("/admin/magellan~auth~organization/new.js", {"magellan_auth_organization" => { "name" => "new1" }})
20
+ expect(cmd).to receive(:post_json).with("/admin/magellan~auth~organization/new.json", {"magellan_auth_organization" => { "name" => "new1" }})
21
21
  end
22
22
  it do
23
23
  cmd.create("new1")
@@ -21,6 +21,7 @@ describe Magellan::Cli::Resources::Project do
21
21
  describe :list do
22
22
  it do
23
23
  allow(res).to receive(:body).and_return("[]")
24
+ allow(res).to receive(:status).and_return(200)
24
25
  expect(httpclient).to receive(:get).with("#{base_url}/admin/project.json").and_return(res)
25
26
  expect($stdout).to receive(:puts)
26
27
  cmd.list
@@ -30,6 +31,7 @@ describe Magellan::Cli::Resources::Project do
30
31
  describe :show do
31
32
  it do
32
33
  allow(res).to receive(:body).and_return("{}")
34
+ allow(res).to receive(:status).and_return(200)
33
35
  expect(httpclient).to receive(:get).with("#{base_url}/admin/project/1.json").and_return(res)
34
36
  expect($stdout).to receive(:puts)
35
37
  cmd.show(1)
@@ -20,7 +20,7 @@ describe Magellan::Cli::Resources::Team do
20
20
  describe :success do
21
21
  before do
22
22
  expect(cmd).to receive(:load_selection).with("magellan_auth_organization").and_return({"id" => 1, "name" => "org1"})
23
- expect(cmd).to receive(:post_json).with("/admin/magellan~auth~team/new.js", { "magellan_auth_team" => { "organization_id" => 1, "name" => "team1", "role" => role } })
23
+ expect(cmd).to receive(:post_json).with("/admin/magellan~auth~team/new.json", { "magellan_auth_team" => { "organization_id" => 1, "name" => "team1", "role" => role } })
24
24
  end
25
25
  context "role=readers" do
26
26
  let(:role){ "readers" }
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.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - akm2000
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-16 00:00:00.000000000 Z
11
+ date: 2014-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient