magellan-cli 0.5.2 → 0.5.3
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/gem_update.rb +1 -0
- data/lib/magellan/cli/messaging/http.rb +4 -4
- data/lib/magellan/cli/version.rb +1 -1
- data/spec/magellan/cli/messaging/http_body.json +4 -0
- data/spec/magellan/cli/messaging/http_body.txt +6 -0
- data/spec/magellan/cli/messaging/http_spec.rb +79 -26
- data/spec/magellan/cli/messaging/mqtt_spec.rb +43 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e376d8606b10e07ef39118cf792f277fe3bea4b0
|
4
|
+
data.tar.gz: 384542ebb224be59570cdfbf8070683753dde5fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6b8495712afa5a10cb0e81d64bf139acc2016fe36a042f697fd31d83ee97e97c43b8e40516485f664a21d4ba91223a7ccd494554e109a6c73d3f3ca856edf20
|
7
|
+
data.tar.gz: ac1be6b59fbcd12181f3a66054f7528530114ebd40ae19e272bbc4ffcb3e0708dd833f047a01f8b646169c6af1d61d59d04b93bf90b6c2f3989d33abd6a380b5
|
data/Gemfile.lock
CHANGED
@@ -17,8 +17,8 @@ module Magellan
|
|
17
17
|
desc "#{m} PATH", I18n.t(m, scope: [:messaging, :http])
|
18
18
|
method_option :headers, aliases: "-H", desc: I18n.t(:headers, scope: [:messaging, :http, :common_options])
|
19
19
|
module_eval(<<-EOM, __FILE__, __LINE__ + 1)
|
20
|
-
def #{m}(path
|
21
|
-
res = core.request(path, :#{m}, nil, try_reading_hash(headers) || {})
|
20
|
+
def #{m}(path)
|
21
|
+
res = core.request(path, :#{m}, nil, try_reading_hash(options[:headers]) || {})
|
22
22
|
puts_res(res)
|
23
23
|
end
|
24
24
|
EOM
|
@@ -29,8 +29,8 @@ module Magellan
|
|
29
29
|
method_option :body , aliases: "-d", desc: I18n.t(:body , scope: [:messaging, :http, :common_options])
|
30
30
|
method_option :headers, aliases: "-H", desc: I18n.t(:headers, scope: [:messaging, :http, :common_options])
|
31
31
|
module_eval(<<-EOM, __FILE__, __LINE__ + 1)
|
32
|
-
def #{m}(path
|
33
|
-
res = core.request(path, :#{m}, try_reading_file(body), try_reading_hash(headers) || {})
|
32
|
+
def #{m}(path)
|
33
|
+
res = core.request(path, :#{m}, try_reading_file(options[:body]), try_reading_hash(options[:headers]) || {})
|
34
34
|
puts_res(res)
|
35
35
|
end
|
36
36
|
EOM
|
data/lib/magellan/cli/version.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
require 'spec_helper'
|
3
|
+
require 'thor/core_ext/hash_with_indifferent_access'
|
3
4
|
|
4
5
|
describe Magellan::Cli::Messaging::Http do
|
5
6
|
|
@@ -10,34 +11,86 @@ describe Magellan::Cli::Messaging::Http do
|
|
10
11
|
|
11
12
|
let(:success_res){ double(:res, code: 200, body: "SUCCESS!\n") }
|
12
13
|
let(:failure_res){ double(:res, code: 401, body: "NOT FOUND!\n") }
|
13
|
-
|
14
|
-
describe :get do
|
15
|
-
it "path only" do
|
16
|
-
expect(core).to receive(:request).with("/foo", :get, nil, {}).and_return(success_res)
|
17
|
-
cmd.get("/foo")
|
18
|
-
end
|
19
|
-
it "path only(401 error)" do
|
20
|
-
expect(core).to receive(:request).with("/foo", :get, nil, {}).and_return(failure_res)
|
21
|
-
cmd.get("/foo")
|
22
|
-
end
|
23
|
-
it "path and query string" do
|
24
|
-
expect(core).to receive(:request).with("/foo?bar=baz", :get, nil, {}).and_return(success_res)
|
25
|
-
cmd.get("/foo?bar=baz")
|
26
|
-
end
|
27
|
-
it "path and headers" do
|
28
|
-
expect(core).to receive(:request).with("/foo", :get, nil, {"bar" => "baz"}).and_return(success_res)
|
29
|
-
cmd.get("/foo", '{"bar":"baz"}')
|
30
|
-
end
|
31
14
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
15
|
+
[:get, :delete, :post, :put, :patch].each do |http_method|
|
16
|
+
describe http_method do
|
17
|
+
it "path only" do
|
18
|
+
expect(core).to receive(:request).with("/foo", http_method, nil, {}).and_return(success_res)
|
19
|
+
cmd.send(http_method, "/foo")
|
20
|
+
end
|
21
|
+
it "path only(401 error)" do
|
22
|
+
expect(core).to receive(:request).with("/foo", http_method, nil, {}).and_return(failure_res)
|
23
|
+
cmd.send(http_method, "/foo")
|
24
|
+
end
|
25
|
+
it "path and query string" do
|
26
|
+
expect(core).to receive(:request).with("/foo?bar=baz", http_method, nil, {}).and_return(success_res)
|
27
|
+
cmd.send(http_method, "/foo?bar=baz")
|
28
|
+
end
|
29
|
+
it "path and headers" do
|
30
|
+
expect(core).to receive(:request).with("/foo", http_method, nil, {"bar" => "baz"}).and_return(success_res)
|
31
|
+
cmd.options = Thor::CoreExt::HashWithIndifferentAccess.new headers: '{"bar":"baz"}'
|
32
|
+
cmd.send(http_method, "/foo")
|
33
|
+
end
|
34
|
+
|
35
|
+
let(:header_content){ YAML.load_file(File.expand_path("../http_headers.yml", __FILE__)) }
|
36
|
+
it "path and headers yaml file" do
|
37
|
+
expect(core).to receive(:request).with("/foo", http_method, nil, header_content).and_return(success_res)
|
38
|
+
cmd.options = Thor::CoreExt::HashWithIndifferentAccess.new headers: File.expand_path("../http_headers.yml", __FILE__)
|
39
|
+
cmd.send(http_method, "/foo")
|
40
|
+
end
|
41
|
+
it "path and headers json file" do
|
42
|
+
expect(core).to receive(:request).with("/foo", http_method, nil, header_content).and_return(success_res)
|
43
|
+
cmd.options = Thor::CoreExt::HashWithIndifferentAccess.new "headers" => File.expand_path("../http_headers.json", __FILE__)
|
44
|
+
cmd.send(http_method, "/foo")
|
45
|
+
end
|
40
46
|
end
|
41
47
|
end
|
42
48
|
|
49
|
+
[:post, :put, :patch].each do |http_method|
|
50
|
+
describe "#{http_method} with body" do
|
51
|
+
text = "foo\nbar\n\nbazbazbaz"
|
52
|
+
text_filename = File.expand_path("../http_body.txt" , __FILE__)
|
53
|
+
json_filename = File.expand_path("../http_body.json", __FILE__)
|
54
|
+
[
|
55
|
+
["text" , text , text],
|
56
|
+
["text file", text_filename, File.read(text_filename)],
|
57
|
+
["JSON file", json_filename, File.read(json_filename)],
|
58
|
+
].each do |context_nane, arg, expected|
|
59
|
+
context context_nane do
|
60
|
+
it "path only" do
|
61
|
+
expect(core).to receive(:request).with("/foo", http_method, expected, {}).and_return(success_res)
|
62
|
+
cmd.options = Thor::CoreExt::HashWithIndifferentAccess.new body: arg
|
63
|
+
cmd.send(http_method, "/foo")
|
64
|
+
end
|
65
|
+
it "path only(401 error)" do
|
66
|
+
expect(core).to receive(:request).with("/foo", http_method, expected, {}).and_return(failure_res)
|
67
|
+
cmd.options = Thor::CoreExt::HashWithIndifferentAccess.new body: arg
|
68
|
+
cmd.send(http_method, "/foo")
|
69
|
+
end
|
70
|
+
it "path and query string" do
|
71
|
+
expect(core).to receive(:request).with("/foo?bar=baz", http_method, expected, {}).and_return(success_res)
|
72
|
+
cmd.options = Thor::CoreExt::HashWithIndifferentAccess.new body: arg
|
73
|
+
cmd.send(http_method, "/foo?bar=baz")
|
74
|
+
end
|
75
|
+
it "path and headers" do
|
76
|
+
expect(core).to receive(:request).with("/foo", http_method, expected, {"bar" => "baz"}).and_return(success_res)
|
77
|
+
cmd.options = Thor::CoreExt::HashWithIndifferentAccess.new body: arg, headers: '{"bar":"baz"}'
|
78
|
+
cmd.send(http_method, "/foo")
|
79
|
+
end
|
80
|
+
|
81
|
+
let(:header_content){ YAML.load_file(File.expand_path("../http_headers.yml", __FILE__)) }
|
82
|
+
it "path and headers yaml file" do
|
83
|
+
expect(core).to receive(:request).with("/foo", http_method, expected, header_content).and_return(success_res)
|
84
|
+
cmd.options = Thor::CoreExt::HashWithIndifferentAccess.new body: arg, headers: File.expand_path("../http_headers.yml", __FILE__)
|
85
|
+
cmd.send(http_method, "/foo")
|
86
|
+
end
|
87
|
+
it "path and headers json file" do
|
88
|
+
expect(core).to receive(:request).with("/foo", http_method, expected, header_content).and_return(success_res)
|
89
|
+
cmd.options = Thor::CoreExt::HashWithIndifferentAccess.new "body" => arg, "headers" => File.expand_path("../http_headers.json", __FILE__)
|
90
|
+
cmd.send(http_method, "/foo")
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
43
96
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'thor/core_ext/hash_with_indifferent_access'
|
4
|
+
|
5
|
+
describe Magellan::Cli::Messaging::Mqtt do
|
6
|
+
|
7
|
+
let(:cmd){ Magellan::Cli::Messaging::Mqtt.new }
|
8
|
+
|
9
|
+
let(:core){ double(:core) }
|
10
|
+
before{ allow(cmd).to receive(:core).and_return(core) }
|
11
|
+
|
12
|
+
let(:success_res){ double(:res, code: 200, body: "SUCCESS!\n") }
|
13
|
+
let(:failure_res){ double(:res, code: 401, body: "NOT FOUND!\n") }
|
14
|
+
|
15
|
+
describe :pub do
|
16
|
+
it do
|
17
|
+
expect(core).to receive(:publish).with("foo.bar", "payload")
|
18
|
+
cmd.pub("foo.bar", "payload")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe :get do
|
23
|
+
it "without argument" do
|
24
|
+
expect(core).to receive(:get_message)
|
25
|
+
cmd.get
|
26
|
+
end
|
27
|
+
|
28
|
+
it "with nil" do
|
29
|
+
expect(core).to receive(:get_message).with(nil)
|
30
|
+
cmd.get(nil)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "with blank string" do
|
34
|
+
expect(core).to receive(:get_message).with("")
|
35
|
+
cmd.get("")
|
36
|
+
end
|
37
|
+
|
38
|
+
it "with topic" do
|
39
|
+
expect(core).to receive(:get_message).with("foo.bar")
|
40
|
+
cmd.get("foo.bar")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
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.5.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- akm2000
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpclient
|
@@ -248,9 +248,12 @@ files:
|
|
248
248
|
- spec/magellan/cli/file_access_spec.rb
|
249
249
|
- spec/magellan/cli/login_page.html
|
250
250
|
- spec/magellan/cli/login_spec.rb
|
251
|
+
- spec/magellan/cli/messaging/http_body.json
|
252
|
+
- spec/magellan/cli/messaging/http_body.txt
|
251
253
|
- spec/magellan/cli/messaging/http_headers.json
|
252
254
|
- spec/magellan/cli/messaging/http_headers.yml
|
253
255
|
- spec/magellan/cli/messaging/http_spec.rb
|
256
|
+
- spec/magellan/cli/messaging/mqtt_spec.rb
|
254
257
|
- spec/magellan/cli/resources/client_version_spec.rb
|
255
258
|
- spec/magellan/cli/resources/organization_spec.rb
|
256
259
|
- spec/magellan/cli/resources/project_spec.rb
|
@@ -288,9 +291,12 @@ test_files:
|
|
288
291
|
- spec/magellan/cli/file_access_spec.rb
|
289
292
|
- spec/magellan/cli/login_page.html
|
290
293
|
- spec/magellan/cli/login_spec.rb
|
294
|
+
- spec/magellan/cli/messaging/http_body.json
|
295
|
+
- spec/magellan/cli/messaging/http_body.txt
|
291
296
|
- spec/magellan/cli/messaging/http_headers.json
|
292
297
|
- spec/magellan/cli/messaging/http_headers.yml
|
293
298
|
- spec/magellan/cli/messaging/http_spec.rb
|
299
|
+
- spec/magellan/cli/messaging/mqtt_spec.rb
|
294
300
|
- spec/magellan/cli/resources/client_version_spec.rb
|
295
301
|
- spec/magellan/cli/resources/organization_spec.rb
|
296
302
|
- spec/magellan/cli/resources/project_spec.rb
|