MuranoCLI 3.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +50 -27
  3. data/.trustme.vim +12 -8
  4. data/bin/murano +23 -8
  5. data/docs/basic_example.rst +1 -1
  6. data/docs/completions/murano_completion-bash +88 -0
  7. data/lib/MrMurano/Account.rb +3 -3
  8. data/lib/MrMurano/Business.rb +6 -6
  9. data/lib/MrMurano/Config-Migrate.rb +1 -3
  10. data/lib/MrMurano/Config.rb +16 -8
  11. data/lib/MrMurano/Content.rb +56 -45
  12. data/lib/MrMurano/Gateway.rb +62 -21
  13. data/lib/MrMurano/Mock.rb +27 -19
  14. data/lib/MrMurano/Passwords.rb +7 -7
  15. data/lib/MrMurano/ReCommander.rb +171 -28
  16. data/lib/MrMurano/Setting.rb +38 -40
  17. data/lib/MrMurano/Solution-ServiceConfig.rb +2 -1
  18. data/lib/MrMurano/Solution-Services.rb +196 -61
  19. data/lib/MrMurano/Solution-Users.rb +7 -7
  20. data/lib/MrMurano/Solution.rb +22 -8
  21. data/lib/MrMurano/SolutionId.rb +10 -4
  22. data/lib/MrMurano/SubCmdGroupContext.rb +14 -5
  23. data/lib/MrMurano/SyncAllowed.rb +42 -0
  24. data/lib/MrMurano/SyncUpDown.rb +122 -65
  25. data/lib/MrMurano/Webservice-Cors.rb +9 -3
  26. data/lib/MrMurano/Webservice-Endpoint.rb +39 -33
  27. data/lib/MrMurano/Webservice-File.rb +35 -24
  28. data/lib/MrMurano/commands/business.rb +18 -18
  29. data/lib/MrMurano/commands/content.rb +3 -2
  30. data/lib/MrMurano/commands/devices.rb +137 -22
  31. data/lib/MrMurano/commands/globals.rb +8 -2
  32. data/lib/MrMurano/commands/keystore.rb +3 -2
  33. data/lib/MrMurano/commands/link.rb +13 -13
  34. data/lib/MrMurano/commands/login.rb +3 -2
  35. data/lib/MrMurano/commands/mock.rb +4 -3
  36. data/lib/MrMurano/commands/password.rb +4 -2
  37. data/lib/MrMurano/commands/postgresql.rb +5 -3
  38. data/lib/MrMurano/commands/settings.rb +78 -62
  39. data/lib/MrMurano/commands/show.rb +79 -74
  40. data/lib/MrMurano/commands/solution.rb +6 -4
  41. data/lib/MrMurano/commands/solution_picker.rb +5 -4
  42. data/lib/MrMurano/commands/status.rb +15 -4
  43. data/lib/MrMurano/commands/timeseries.rb +3 -2
  44. data/lib/MrMurano/commands/tsdb.rb +3 -2
  45. data/lib/MrMurano/hash.rb +6 -6
  46. data/lib/MrMurano/http.rb +66 -67
  47. data/lib/MrMurano/makePretty.rb +18 -12
  48. data/lib/MrMurano/progress.rb +9 -2
  49. data/lib/MrMurano/verbosing.rb +14 -2
  50. data/lib/MrMurano/version.rb +2 -2
  51. data/spec/GatewayDevice_spec.rb +190 -149
  52. data/spec/Mock_spec.rb +3 -3
  53. data/spec/Solution-ServiceEventHandler_spec.rb +170 -137
  54. data/spec/SyncUpDown_spec.rb +205 -191
  55. metadata +3 -2
@@ -1,20 +1,27 @@
1
+ # Last Modified: 2017.08.20 /coding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ # Copyright © 2016-2017 Exosite LLC.
5
+ # License: MIT. See LICENSE.txt.
6
+ # vim:tw=0:ts=2:sw=2:et:ai
7
+
1
8
  require 'date'
2
9
  require 'json'
3
10
  require 'highline'
4
11
 
5
12
  module MrMurano
6
13
  module Pretties
7
-
8
- HighLine::Style.new(:name=>:on_aliceblue, :code=>"\e[48;5;231m", :rgb=>[240, 248, 255])
14
+ HighLine::Style.new(name: :on_aliceblue, code: "\e[48;5;231m", rgb: [240, 248, 255])
9
15
  PRETTIES_COLORSCHEME = HighLine::ColorScheme.new do |cs|
10
- cs[:subject] = [:red, :on_aliceblue]
16
+ cs[:subject] = %i[red on_aliceblue]
11
17
  cs[:timestamp] = [:blue]
12
18
  cs[:json] = [:magenta]
13
19
  end
14
20
  HighLine.color_scheme = PRETTIES_COLORSCHEME
15
21
 
22
+ # rubocop:disable Style/MethodName: "Use snake_case for method names."
16
23
  def self.makeJsonPretty(data, options)
17
- if options.pretty then
24
+ if options.pretty
18
25
  ret = JSON.pretty_generate(data).to_s
19
26
  ret[0] = HighLine.color(ret[0], :json)
20
27
  ret[-1] = HighLine.color(ret[-1], :json)
@@ -31,9 +38,9 @@ module MrMurano
31
38
  out += HighLine.color("#{line[:type] || '--'} ".upcase, :subject)
32
39
  out += HighLine.color("[#{line[:subject] || ''}]", :subject)
33
40
  out += ' '
34
- if line.has_key?(:timestamp) then
35
- if line[:timestamp].kind_of? Numeric then
36
- if options.localtime then
41
+ if line.key?(:timestamp)
42
+ if line[:timestamp].is_a? Numeric
43
+ if options.localtime
37
44
  curtime = Time.at(line[:timestamp]).localtime.to_datetime.iso8601(3)
38
45
  else
39
46
  curtime = Time.at(line[:timestamp]).gmtime.to_datetime.iso8601(3)
@@ -46,11 +53,11 @@ module MrMurano
46
53
  end
47
54
  out += HighLine.color(curtime, :timestamp)
48
55
  out += ":\n"
49
- if line.has_key?(:data) then
56
+ if line.key?(:data)
50
57
  data = line[:data]
51
58
 
52
- if data.kind_of?(Hash) then
53
- if data.has_key?(:request) and data.has_key?(:response) then
59
+ if data.is_a?(Hash)
60
+ if data.key?(:request) && data.key?(:response)
54
61
  out += "---------\nrequest:"
55
62
  out += makeJsonPretty(data[:request], options)
56
63
 
@@ -71,7 +78,6 @@ module MrMurano
71
78
  end
72
79
  out
73
80
  end
74
-
75
81
  end
76
82
  end
77
- # vim: set ai et sw=2 ts=2 :
83
+
@@ -1,4 +1,4 @@
1
- # Last Modified: 2017.08.02 /coding: utf-8
1
+ # Last Modified: 2017.08.22 /coding: utf-8
2
2
  # frozen_string_literal: true
3
3
 
4
4
  # Copyright © 2016-2017 Exosite LLC.
@@ -32,6 +32,13 @@ module MrMurano
32
32
  '▗',
33
33
  ].freeze
34
34
 
35
+ EXO_QUADRANTS_7 = [
36
+ '-',
37
+ '\\',
38
+ '|',
39
+ '/',
40
+ ].freeze
41
+
35
42
  def whirly_start(msg)
36
43
  if $cfg['tool.verbose']
37
44
  whirly_pause if @whirly_users > 0
@@ -54,7 +61,7 @@ module MrMurano
54
61
 
55
62
  def whirly_show
56
63
  Whirly.start(
57
- spinner: EXO_QUADRANTS,
64
+ spinner: $cfg['tool.ascii'] && EXO_QUADRANTS_7 || EXO_QUADRANTS,
58
65
  status: @whirly_msg,
59
66
  append_newline: false,
60
67
  #remove_after_stop: false,
@@ -1,4 +1,4 @@
1
- # Last Modified: 2017.08.17 /coding: utf-8
1
+ # Last Modified: 2017.08.23 /coding: utf-8
2
2
  # frozen_string_literal: true
3
3
 
4
4
  # Copyright © 2016-2017 Exosite LLC.
@@ -149,7 +149,7 @@ module MrMurano
149
149
  return true
150
150
  end
151
151
  confirmed = MrMurano::Verbose.ask_yes_no(
152
- "Really delete ‘#{name}’? [y/N] ", false
152
+ "Really delete #{MrMurano::Verbose.fancy_ticks(name)}? [y/N] ", false
153
153
  )
154
154
  MrMurano::Verbose.warning(exit_msg) if !confirmed && exit_msg
155
155
  if block_given?
@@ -172,6 +172,18 @@ module MrMurano
172
172
  MrMurano::Verbose.pluralize?(word, count)
173
173
  end
174
174
 
175
+ def self.fancy_ticks(obj)
176
+ if $cfg.nil? || $cfg['tool.ascii']
177
+ "'#{obj}'"
178
+ else
179
+ "‘#{obj}’"
180
+ end
181
+ end
182
+
183
+ def fancy_ticks(obj)
184
+ MrMurano::Verbose.fancy_ticks(obj)
185
+ end
186
+
175
187
  # 2017-07-01: Whirly wrappers. Maybe delete someday
176
188
  # (after replacing all MrMurano::Verbose.whirly_*
177
189
  # with MrMurano::Progress.whirly_*).
@@ -1,4 +1,4 @@
1
- # Last Modified: 2017.08.18 /coding: utf-8
1
+ # Last Modified: 2017.08.23 /coding: utf-8
2
2
  # frozen_string_literal: true
3
3
 
4
4
  # Copyright © 2016-2017 Exosite LLC.
@@ -26,7 +26,7 @@ module MrMurano
26
26
  # '3.0.0-beta.2' is changed to '3.0.0.pre.beta.2'
27
27
  # which breaks our build (which expects the version to match herein).
28
28
  # So stick to using the '.pre.X' syntax, which ruby/gems knows.
29
- VERSION = '3.0.0'
29
+ VERSION = '3.0.1'
30
30
  EXE_NAME = File.basename($PROGRAM_NAME)
31
31
  SIGN_UP_URL = 'https://exosite.com/signup/'
32
32
  end
@@ -1,3 +1,10 @@
1
+ # Last Modified: 2017.08.23 /coding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ # Copyright © 2016-2017 Exosite LLC.
5
+ # License: MIT. See LICENSE.txt.
6
+ # vim:tw=0:ts=2:sw=2:et:ai
7
+
1
8
  require 'fileutils'
2
9
  require 'MrMurano/version'
3
10
  require 'MrMurano/Gateway'
@@ -25,31 +32,33 @@ RSpec.describe MrMurano::Gateway::Device do
25
32
  context "listing" do
26
33
  it "lists" do
27
34
  body = {
28
- :mayLoadMore=>false,
29
- :devices=>
30
- [{:identity=>"58",
31
- :auth=>{:type=>"cik"},
32
- :state=>{},
33
- :locked=>false,
34
- :reprovision=>false,
35
- :devmode=>false,
36
- :lastip=>"",
37
- :lastseen=>1487021743864000,
38
- :status=>"provisioned",
39
- :online=>false},
40
- {:identity=>"56",
41
- :auth=>{:type=>"cik"},
42
- :state=>{},
43
- :locked=>false,
44
- :reprovision=>false,
45
- :devmode=>false,
46
- :lastip=>"",
47
- :lastseen=>1487021650584000,
48
- :status=>"provisioned",
49
- :online=>false},
35
+ mayLoadMore: false,
36
+ devices:
37
+ [{identity: "58",
38
+ auth: {type: "cik"},
39
+ state: {},
40
+ locked: false,
41
+ reprovision: false,
42
+ devmode: false,
43
+ lastip: "",
44
+ lastseen: 1487021743864000,
45
+ status: "provisioned",
46
+ online: false},
47
+ {identity: "56",
48
+ auth: {type: "cik"},
49
+ state: {},
50
+ locked: false,
51
+ reprovision: false,
52
+ devmode: false,
53
+ lastip: "",
54
+ lastseen: 1487021650584000,
55
+ status: "provisioned",
56
+ online: false},
50
57
  ]}
51
- stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identity/").
52
- to_return(:body=>body.to_json)
58
+ stub_request(
59
+ :get,
60
+ "https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identity/"
61
+ ).to_return(body: body.to_json)
53
62
 
54
63
  ret = @gw.list
55
64
  expect(ret).to eq(body)
@@ -57,22 +66,24 @@ RSpec.describe MrMurano::Gateway::Device do
57
66
 
58
67
  it "lists with limit" do
59
68
  body = {
60
- :mayLoadMore=>false,
61
- :devices=>
62
- [{:identity=>"58",
63
- :auth=>{:type=>"cik"},
64
- :state=>{},
65
- :locked=>false,
66
- :reprovision=>false,
67
- :devmode=>false,
68
- :lastip=>"",
69
- :lastseen=>1487021743864000,
70
- :status=>"provisioned",
71
- :online=>false},
69
+ mayLoadMore: false,
70
+ devices:
71
+ [{identity: "58",
72
+ auth: {type: "cik"},
73
+ state: {},
74
+ locked: false,
75
+ reprovision: false,
76
+ devmode: false,
77
+ lastip: "",
78
+ lastseen: 1487021743864000,
79
+ status: "provisioned",
80
+ online: false},
72
81
  ]}
73
- stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identity/").
74
- with(:query=>{:limit=>'1'}).
75
- to_return(:body=>body.to_json)
82
+ stub_request(
83
+ :get,
84
+ "https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identity/"
85
+ ).with(query: {limit: '1'}
86
+ ).to_return(body: body.to_json)
76
87
 
77
88
  ret = @gw.list(1)
78
89
  expect(ret).to eq(body)
@@ -80,22 +91,24 @@ RSpec.describe MrMurano::Gateway::Device do
80
91
 
81
92
  it "lists with before" do
82
93
  body = {
83
- :mayLoadMore=>false,
84
- :devices=>
85
- [{:identity=>"58",
86
- :auth=>{:type=>"cik"},
87
- :state=>{},
88
- :locked=>false,
89
- :reprovision=>false,
90
- :devmode=>false,
91
- :lastip=>"",
92
- :lastseen=>1487021743864000,
93
- :status=>"provisioned",
94
- :online=>false},
94
+ mayLoadMore: false,
95
+ devices:
96
+ [{identity: "58",
97
+ auth: {type: "cik"},
98
+ state: {},
99
+ locked: false,
100
+ reprovision: false,
101
+ devmode: false,
102
+ lastip: "",
103
+ lastseen: 1487021743864000,
104
+ status: "provisioned",
105
+ online: false},
95
106
  ]}
96
- stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identity/").
97
- with(:query=>{:limit=>'1', :before=>'1487021743864000'}).
98
- to_return(:body=>body.to_json)
107
+ stub_request(
108
+ :get,
109
+ "https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identity/"
110
+ ).with(query: { limit: '1', before: '1487021743864000' }
111
+ ).to_return(body: body.to_json)
99
112
 
100
113
  ret = @gw.list(1, 1487021743864000)
101
114
  expect(ret).to eq(body)
@@ -104,18 +117,20 @@ RSpec.describe MrMurano::Gateway::Device do
104
117
 
105
118
  it "fetches one" do
106
119
  body = {
107
- :identity=>"58",
108
- :auth=>{:type=>"cik"},
109
- :state=>{},
110
- :locked=>false,
111
- :reprovision=>false,
112
- :devmode=>false,
113
- :lastip=>"",
114
- :lastseen=>1487021743864000,
115
- :status=>"provisioned",
116
- :online=>false}
117
- stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identity/58").
118
- to_return(:body=>body.to_json)
120
+ identity: "58",
121
+ auth: {type: "cik"},
122
+ state: {},
123
+ locked: false,
124
+ reprovision: false,
125
+ devmode: false,
126
+ lastip: "",
127
+ lastseen: 1487021743864000,
128
+ status: "provisioned",
129
+ online: false}
130
+ stub_request(
131
+ :get,
132
+ "https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identity/58"
133
+ ).to_return(body: body.to_json)
119
134
 
120
135
  ret = @gw.fetch(58)
121
136
  expect(ret).to eq(body)
@@ -123,18 +138,20 @@ RSpec.describe MrMurano::Gateway::Device do
123
138
 
124
139
  it "enables one" do
125
140
  body = {
126
- :identity=>"58",
127
- :auth=>{:type=>"cik"},
128
- :state=>{},
129
- :locked=>false,
130
- :reprovision=>false,
131
- :devmode=>false,
132
- :lastip=>"",
133
- :lastseen=>1487021743864000,
134
- :status=>"provisioned",
135
- :online=>false}
136
- stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identity/58").
137
- to_return(:body=>body.to_json)
141
+ identity: "58",
142
+ auth: {type: "cik"},
143
+ state: {},
144
+ locked: false,
145
+ reprovision: false,
146
+ devmode: false,
147
+ lastip: "",
148
+ lastseen: 1487021743864000,
149
+ status: "provisioned",
150
+ online: false}
151
+ stub_request(
152
+ :put,
153
+ "https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identity/58"
154
+ ).to_return(body: body.to_json)
138
155
 
139
156
  ret = @gw.enable(58)
140
157
  expect(ret).to eq(body)
@@ -142,58 +159,64 @@ RSpec.describe MrMurano::Gateway::Device do
142
159
 
143
160
  it "enables with options" do
144
161
  body = {
145
- :identity=>"58",
146
- :auth=>{:type=>"cik"},
147
- :state=>{},
148
- :locked=>false,
149
- :reprovision=>false,
150
- :devmode=>false,
151
- :lastip=>"",
152
- :lastseen=>1487021743864000,
153
- :status=>"provisioned",
154
- :online=>false}
155
- stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identity/58").
156
- with(:body=>{:type=>:certificate,:expire=>123456}.to_json).
157
- to_return(:body=>body.to_json)
158
-
159
- ret = @gw.enable(58, :type=>:certificate, :expire=>123456)
162
+ identity: "58",
163
+ auth: {type: "cik"},
164
+ state: {},
165
+ locked: false,
166
+ reprovision: false,
167
+ devmode: false,
168
+ lastip: "",
169
+ lastseen: 1487021743864000,
170
+ status: "provisioned",
171
+ online: false}
172
+ stub_request(
173
+ :put,
174
+ "https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identity/58"
175
+ ). with(body: { auth: { expire: 123456, type: :certificate }, locked: false }.to_json
176
+ ).to_return(body: body.to_json)
177
+
178
+ ret = @gw.enable(58, type: :certificate, expire: '123456')
160
179
  expect(ret).to eq(body)
161
180
  end
162
181
 
163
182
  it "enables with extra options" do
164
183
  body = {
165
- :identity=>"58",
166
- :auth=>{:type=>"cik"},
167
- :state=>{},
168
- :locked=>false,
169
- :reprovision=>false,
170
- :devmode=>false,
171
- :lastip=>"",
172
- :lastseen=>1487021743864000,
173
- :status=>"provisioned",
174
- :online=>false}
175
- stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identity/58").
176
- with(:body=>{:type=>:certificate,:expire=>123456}.to_json).
177
- to_return(:body=>body.to_json)
178
-
179
- ret = @gw.enable(58, :go=>:blueteam, :type=>:certificate, :expire=>123456, :bob=>:built)
184
+ identity: "58",
185
+ auth: {type: "cik"},
186
+ state: {},
187
+ locked: false,
188
+ reprovision: false,
189
+ devmode: false,
190
+ lastip: "",
191
+ lastseen: 1487021743864000,
192
+ status: "provisioned",
193
+ online: false}
194
+ stub_request(
195
+ :put,
196
+ "https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identity/58"
197
+ ).with(body: {auth: { expire: 123456, type: :certificate }, locked: false }.to_json
198
+ ).to_return(body: body.to_json)
199
+
200
+ ret = @gw.enable(58, go: :blueteam, type: :certificate, expire: 123456, bob: :built)
180
201
  expect(ret).to eq(body)
181
202
  end
182
203
 
183
204
  it "removes one" do
184
205
  body = {
185
- :identity=>"58",
186
- :auth=>{:type=>"cik"},
187
- :state=>{},
188
- :locked=>false,
189
- :reprovision=>false,
190
- :devmode=>false,
191
- :lastip=>"",
192
- :lastseen=>1487021743864000,
193
- :status=>"provisioned",
194
- :online=>false}
195
- stub_request(:delete, "https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identity/58").
196
- to_return(:body=>body.to_json)
206
+ identity: "58",
207
+ auth: {type: "cik"},
208
+ state: {},
209
+ locked: false,
210
+ reprovision: false,
211
+ devmode: false,
212
+ lastip: "",
213
+ lastseen: 1487021743864000,
214
+ status: "provisioned",
215
+ online: false}
216
+ stub_request(
217
+ :delete,
218
+ "https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identity/58"
219
+ ).to_return(body: body.to_json)
197
220
 
198
221
  ret = @gw.remove(58)
199
222
  expect(ret).to eq(body)
@@ -205,20 +228,26 @@ RSpec.describe MrMurano::Gateway::Device do
205
228
  allow(@bgw).to receive(:token).and_return("TTTTTTTTTT")
206
229
  expect(MrMurano::Gateway::GweBase).to receive(:new).and_return(@bgw)
207
230
  allow(@gw).to receive(:token).and_return("TTTTTTTTTT")
208
- stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2").
209
- to_return(:body=>{:fqdn=>"xxxxx.m2.exosite-staging.io"}.to_json)
231
+ stub_request(
232
+ :get,
233
+ "https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2"
234
+ ).to_return(body: { fqdn: "xxxxx.m2.exosite-staging.io" }.to_json)
210
235
  end
211
236
  it "succeeds" do
212
- stub_request(:post, "https://xxxxx.m2.exosite-staging.io/provision/activate").
213
- to_return(:body=>'XXXXXXXX')
237
+ stub_request(
238
+ :post,
239
+ "https://xxxxx.m2.exosite-staging.io/provision/activate"
240
+ ).to_return(body: 'XXXXXXXX')
214
241
 
215
242
  ret = @gw.activate(58)
216
243
  expect(ret).to eq('XXXXXXXX')
217
244
  end
218
245
 
219
246
  it "was already activated" do
220
- stub_request(:post, "https://xxxxx.m2.exosite-staging.io/provision/activate").
221
- to_return(:status => 409)
247
+ stub_request(
248
+ :post,
249
+ "https://xxxxx.m2.exosite-staging.io/provision/activate"
250
+ ).to_return(status: 409)
222
251
 
223
252
  saved = $stderr
224
253
  $stderr = StringIO.new
@@ -232,8 +261,10 @@ RSpec.describe MrMurano::Gateway::Device do
232
261
  end
233
262
 
234
263
  it "wasn't enabled" do
235
- stub_request(:post, "https://xxxxx.m2.exosite-staging.io/provision/activate").
236
- to_return(:status => 404)
264
+ stub_request(
265
+ :post,
266
+ "https://xxxxx.m2.exosite-staging.io/provision/activate"
267
+ ).to_return(status: 404)
237
268
 
238
269
  saved = $stderr
239
270
  $stderr = StringIO.new
@@ -247,8 +278,10 @@ RSpec.describe MrMurano::Gateway::Device do
247
278
  context "enables batch" do
248
279
  it "enables from cvs" do
249
280
  File.open('ids.csv', 'w') {|io| io << "ID\n1\n2\n3\n4\n5"}
250
- stub_request(:post, 'https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identities').
251
- with(:headers=>{'Content-Type'=>%r{^multipart/form-data.*}}) do |request|
281
+ stub_request(
282
+ :post,
283
+ 'https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identities'
284
+ ).with(headers: { 'Content-Type' => %r{^multipart/form-data.*} }) do |request|
252
285
  request.body.to_s =~ %r{Content-Type: text/csv\r\n\r\nID\r?\n1\r?\n2\r?\n3\r?\n4\r?\n5}
253
286
  end
254
287
  @gw.enable_batch('ids.csv')
@@ -260,8 +293,10 @@ RSpec.describe MrMurano::Gateway::Device do
260
293
 
261
294
  it "but file is not text" do
262
295
  File.open('ids.csv', 'wb') {|io| io << "\0\0\0\0"}
263
- stub_request(:post, 'https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identities').
264
- to_return(:status=>400, :body => "CSV file format invalid")
296
+ stub_request(
297
+ :post,
298
+ 'https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identities'
299
+ ).to_return(status: 400, body: "CSV file format invalid")
265
300
  saved = $stderr
266
301
  $stderr = StringIO.new
267
302
  @gw.enable_batch('ids.csv')
@@ -271,10 +306,12 @@ RSpec.describe MrMurano::Gateway::Device do
271
306
 
272
307
  it "but file is missing header" do
273
308
  File.open('ids.csv', 'w') {|io| io << "1\n2\n3\n4\n5"}
274
- stub_request(:post, 'https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identities').
275
- with(:headers=>{'Content-Type'=>%r{^multipart/form-data.*}}) do |request|
309
+ stub_request(
310
+ :post,
311
+ 'https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identities'
312
+ ).with(headers: { 'Content-Type' => %r{^multipart/form-data.*} }) do |request|
276
313
  request.body.to_s =~ %r{Content-Type: text/csv\r\n\r\n1\r?\n2\r?\n3\r?\n4\r?\n5}
277
- end.to_return(:status=>400, :body => "CSV file format invalid")
314
+ end.to_return(status: 400, body: "CSV file format invalid")
278
315
  saved = $stderr
279
316
  $stderr = StringIO.new
280
317
  @gw.enable_batch('ids.csv')
@@ -284,9 +321,11 @@ RSpec.describe MrMurano::Gateway::Device do
284
321
  end
285
322
 
286
323
  it "reads state" do
287
- body = {:bob=>{:reported=>"9", :set=>"9", :timestamp=>1487021046160363}}
288
- stub_request(:get, 'https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identity/56/state').
289
- to_return(:body=>body.to_json)
324
+ body = {bob: {reported: "9", set: "9", timestamp: 1487021046160363}}
325
+ stub_request(
326
+ :get,
327
+ 'https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identity/56/state'
328
+ ).to_return(body: body.to_json)
290
329
 
291
330
  ret = @gw.read(56)
292
331
  expect(ret).to eq(body)
@@ -294,28 +333,30 @@ RSpec.describe MrMurano::Gateway::Device do
294
333
 
295
334
  context "writes state" do
296
335
  it "succeeds" do
297
- body = {:bob=>"fuzz"}
298
- stub_request(:patch, 'https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identity/56/state').
299
- with(:body=>body.to_json)
336
+ body = {bob: "fuzz"}
337
+ stub_request(
338
+ :patch,
339
+ 'https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identity/56/state'
340
+ ).with(body: body.to_json)
300
341
 
301
- @gw.write(56, :bob=>'fuzz')
342
+ @gw.write(56, bob: 'fuzz')
302
343
  end
303
344
 
304
345
  it "fails" do
305
- body = {:bob=>"fuzz"}
306
- stub_request(:patch, 'https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identity/56/state').
307
- with(:body=>body.to_json).
308
- to_return(:status=> 400, :body => 'Value is not settable')
346
+ body = {bob: "fuzz"}
347
+ stub_request(
348
+ :patch,
349
+ 'https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/identity/56/state'
350
+ ).with(body: body.to_json
351
+ ).to_return(status: 400, body: 'Value is not settable')
309
352
 
310
353
  saved = $stderr
311
354
  $stderr = StringIO.new
312
355
 
313
- @gw.write(56, :bob=>'fuzz')
356
+ @gw.write(56, bob: 'fuzz')
314
357
  expect($stderr.string).to eq("\e[31mRequest Failed: 400: Value is not settable\e[0m\n")
315
358
  $stderr = saved
316
359
  end
317
360
  end
318
-
319
361
  end
320
362
 
321
- # vim: set ai et sw=2 ts=2 :