MuranoCLI 2.2.4 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. checksums.yaml +4 -4
  2. data/.agignore +3 -0
  3. data/.gitignore +18 -1
  4. data/.rubocop.yml +222 -0
  5. data/.trustme.sh +185 -0
  6. data/.trustme.vim +24 -0
  7. data/Gemfile +23 -4
  8. data/LICENSE.txt +1 -1
  9. data/MuranoCLI.gemspec +43 -8
  10. data/README.markdown +9 -11
  11. data/Rakefile +187 -143
  12. data/TODO.taskpaper +2 -2
  13. data/bin/murano +51 -52
  14. data/docs/basic_example.rst +436 -0
  15. data/docs/completions/murano_completion-bash +3484 -0
  16. data/docs/demo.md +32 -32
  17. data/docs/develop.rst +391 -0
  18. data/lib/MrMurano.rb +21 -7
  19. data/lib/MrMurano/Account.rb +159 -174
  20. data/lib/MrMurano/Business.rb +381 -0
  21. data/lib/MrMurano/Config-Migrate.rb +32 -26
  22. data/lib/MrMurano/Config.rb +407 -128
  23. data/lib/MrMurano/Content.rb +191 -0
  24. data/lib/MrMurano/Gateway.rb +489 -0
  25. data/lib/MrMurano/Keystore.rb +48 -0
  26. data/lib/MrMurano/Passwords.rb +103 -0
  27. data/lib/MrMurano/ProjectFile.rb +121 -79
  28. data/lib/MrMurano/ReCommander.rb +114 -10
  29. data/lib/MrMurano/Setting.rb +90 -0
  30. data/lib/MrMurano/Solution-ServiceConfig.rb +89 -45
  31. data/lib/MrMurano/Solution-Services.rb +461 -166
  32. data/lib/MrMurano/Solution-Users.rb +70 -31
  33. data/lib/MrMurano/Solution.rb +372 -13
  34. data/lib/MrMurano/SolutionId.rb +73 -0
  35. data/lib/MrMurano/SyncRoot.rb +137 -0
  36. data/lib/MrMurano/SyncUpDown.rb +594 -284
  37. data/lib/MrMurano/Webservice-Cors.rb +71 -0
  38. data/lib/MrMurano/Webservice-Endpoint.rb +234 -0
  39. data/lib/MrMurano/Webservice-File.rb +193 -0
  40. data/lib/MrMurano/Webservice.rb +51 -0
  41. data/lib/MrMurano/commands.rb +18 -15
  42. data/lib/MrMurano/commands/business.rb +300 -6
  43. data/lib/MrMurano/commands/completion-bash.erb +166 -0
  44. data/lib/MrMurano/commands/{zshcomplete.erb → completion-zsh.erb} +0 -0
  45. data/lib/MrMurano/commands/completion.rb +76 -39
  46. data/lib/MrMurano/commands/config.rb +108 -44
  47. data/lib/MrMurano/commands/content.rb +115 -72
  48. data/lib/MrMurano/commands/cors.rb +29 -14
  49. data/lib/MrMurano/commands/devices.rb +286 -0
  50. data/lib/MrMurano/commands/domain.rb +52 -12
  51. data/lib/MrMurano/commands/gb.rb +24 -9
  52. data/lib/MrMurano/commands/globals.rb +64 -0
  53. data/lib/MrMurano/commands/init.rb +377 -155
  54. data/lib/MrMurano/commands/keystore.rb +92 -82
  55. data/lib/MrMurano/commands/link.rb +300 -0
  56. data/lib/MrMurano/commands/login.rb +74 -11
  57. data/lib/MrMurano/commands/logs.rb +63 -32
  58. data/lib/MrMurano/commands/mock.rb +57 -29
  59. data/lib/MrMurano/commands/password.rb +57 -39
  60. data/lib/MrMurano/commands/postgresql.rb +127 -94
  61. data/lib/MrMurano/commands/settings.rb +203 -0
  62. data/lib/MrMurano/commands/show.rb +79 -38
  63. data/lib/MrMurano/commands/solution.rb +423 -5
  64. data/lib/MrMurano/commands/solution_picker.rb +547 -0
  65. data/lib/MrMurano/commands/status.rb +195 -61
  66. data/lib/MrMurano/commands/sync.rb +78 -39
  67. data/lib/MrMurano/commands/timeseries.rb +71 -55
  68. data/lib/MrMurano/commands/tsdb.rb +113 -87
  69. data/lib/MrMurano/commands/usage.rb +57 -15
  70. data/lib/MrMurano/hash.rb +100 -10
  71. data/lib/MrMurano/http.rb +187 -43
  72. data/lib/MrMurano/makePretty.rb +16 -14
  73. data/lib/MrMurano/optparse.rb +2178 -0
  74. data/lib/MrMurano/progress.rb +138 -0
  75. data/lib/MrMurano/schema/resource-v1.0.0.yaml +32 -0
  76. data/lib/MrMurano/template/projectFile.murano.erb +16 -13
  77. data/lib/MrMurano/verbosing.rb +166 -29
  78. data/lib/MrMurano/version.rb +30 -1
  79. data/spec/Account-Passwords_spec.rb +21 -4
  80. data/spec/Account_spec.rb +69 -146
  81. data/spec/Business_spec.rb +290 -0
  82. data/spec/ConfigFile_spec.rb +1 -0
  83. data/spec/ConfigMigrate_spec.rb +12 -8
  84. data/spec/Config_spec.rb +40 -34
  85. data/spec/Content_spec.rb +363 -0
  86. data/spec/GatewayBase_spec.rb +54 -0
  87. data/spec/GatewayDevice_spec.rb +321 -0
  88. data/spec/GatewayResource_spec.rb +266 -0
  89. data/spec/GatewaySettings_spec.rb +120 -0
  90. data/spec/Http_spec.rb +18 -8
  91. data/spec/Mock_spec.rb +2 -2
  92. data/spec/ProjectFile_spec.rb +25 -14
  93. data/spec/Setting_spec.rb +110 -0
  94. data/spec/Solution-ServiceConfig_spec.rb +44 -5
  95. data/spec/Solution-ServiceEventHandler_spec.rb +23 -14
  96. data/spec/Solution-ServiceModules_spec.rb +47 -37
  97. data/spec/Solution-UsersRoles_spec.rb +10 -8
  98. data/spec/Solution_spec.rb +17 -8
  99. data/spec/SyncRoot_spec.rb +46 -20
  100. data/spec/SyncUpDown_spec.rb +437 -201
  101. data/spec/Verbosing_spec.rb +12 -4
  102. data/spec/{Solution-Cors_spec.rb → Webservice-Cors_spec.rb} +23 -20
  103. data/spec/{Solution-Endpoint_spec.rb → Webservice-Endpoint_spec.rb} +43 -41
  104. data/spec/{Solution-File_spec.rb → Webservice-File_spec.rb} +44 -33
  105. data/spec/Webservice-Setting_spec.rb +89 -0
  106. data/spec/_workspace.rb +4 -4
  107. data/spec/cmd_business_spec.rb +9 -4
  108. data/spec/cmd_common.rb +44 -1
  109. data/spec/cmd_content_spec.rb +43 -17
  110. data/spec/cmd_cors_spec.rb +4 -4
  111. data/spec/cmd_device_spec.rb +61 -16
  112. data/spec/cmd_domain_spec.rb +29 -6
  113. data/spec/cmd_init_spec.rb +281 -126
  114. data/spec/cmd_keystore_spec.rb +3 -3
  115. data/spec/cmd_link_spec.rb +98 -0
  116. data/spec/cmd_password_spec.rb +1 -1
  117. data/spec/cmd_setting_application_spec.rb +260 -0
  118. data/spec/cmd_setting_product_spec.rb +220 -0
  119. data/spec/cmd_status_spec.rb +223 -114
  120. data/spec/cmd_syncdown_spec.rb +115 -35
  121. data/spec/cmd_syncup_spec.rb +68 -15
  122. data/spec/cmd_usage_spec.rb +35 -8
  123. data/spec/fixtures/dumped_config +6 -4
  124. data/spec/fixtures/gateway_resource_files/resources.notyaml +12 -0
  125. data/spec/fixtures/gateway_resource_files/resources.yaml +13 -0
  126. data/spec/fixtures/gateway_resource_files/resources_invalid.yaml +13 -0
  127. data/spec/fixtures/mrmuranorc_deleted_bob +0 -2
  128. data/spec/fixtures/product_spec_files/lightbulb.yaml +20 -13
  129. data/spec/fixtures/{syncable_content → syncable_conflict}/services/devdata.lua +1 -1
  130. data/spec/fixtures/{syncable_content → syncable_conflict}/services/timers.lua +0 -0
  131. data/spec/spec_helper.rb +5 -0
  132. metadata +262 -171
  133. data/bin/mr +0 -8
  134. data/lib/MrMurano/Product-1P-Device.rb +0 -145
  135. data/lib/MrMurano/Product-Resources.rb +0 -205
  136. data/lib/MrMurano/Product.rb +0 -358
  137. data/lib/MrMurano/Solution-Cors.rb +0 -47
  138. data/lib/MrMurano/Solution-Endpoint.rb +0 -191
  139. data/lib/MrMurano/Solution-File.rb +0 -166
  140. data/lib/MrMurano/commands/assign.rb +0 -57
  141. data/lib/MrMurano/commands/businessList.rb +0 -45
  142. data/lib/MrMurano/commands/product.rb +0 -14
  143. data/lib/MrMurano/commands/productCreate.rb +0 -39
  144. data/lib/MrMurano/commands/productDelete.rb +0 -33
  145. data/lib/MrMurano/commands/productDevice.rb +0 -87
  146. data/lib/MrMurano/commands/productDeviceIdCmds.rb +0 -89
  147. data/lib/MrMurano/commands/productList.rb +0 -45
  148. data/lib/MrMurano/commands/productWrite.rb +0 -27
  149. data/lib/MrMurano/commands/solutionCreate.rb +0 -41
  150. data/lib/MrMurano/commands/solutionDelete.rb +0 -34
  151. data/lib/MrMurano/commands/solutionList.rb +0 -45
  152. data/spec/ProductBase_spec.rb +0 -113
  153. data/spec/ProductContent_spec.rb +0 -162
  154. data/spec/ProductResources_spec.rb +0 -329
  155. data/spec/Product_1P_Device_spec.rb +0 -202
  156. data/spec/Product_1P_RPC_spec.rb +0 -175
  157. data/spec/Product_spec.rb +0 -153
  158. data/spec/Solution-ServiceDevice_spec.rb +0 -176
  159. data/spec/cmd_assign_spec.rb +0 -51
@@ -1,6 +1,13 @@
1
+ # Last Modified: 2017.07.03 /coding: utf-8
2
+ # frozen_string_literal: probably not yet
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 'highline/import'
2
- require 'MrMurano/version'
3
9
  require 'MrMurano/hash'
10
+ require 'MrMurano/version'
4
11
  require 'MrMurano/verbosing'
5
12
  require 'MrMurano/Config'
6
13
  require '_workspace'
@@ -128,7 +135,9 @@ RSpec.describe MrMurano::Verbose do
128
135
 
129
136
  it "errors if it can't" do
130
137
  $stdout = StringIO.new
131
- expect(@tst).to receive(:error).with("Don't know how to tabularize data.").once
138
+ # 2017-07-03: [lb] converted to class func.
139
+ #expect(@tst).to receive(:error).with(MrMurano::Verbose::TABULARIZE_DATA_FORMAT_ERROR).once
140
+ expect(MrMurano::Verbose).to receive(:error).with(MrMurano::Verbose::TABULARIZE_DATA_FORMAT_ERROR).once
132
141
  @tst.tabularize(12)
133
142
  end
134
143
 
@@ -274,6 +283,5 @@ RSpec.describe MrMurano::Verbose do
274
283
  expect($stdout.string).to eq("pop\n")
275
284
  end
276
285
  end
277
-
278
286
  end
279
- # vim: set ai et sw=2 ts=2 :
287
+
@@ -1,26 +1,29 @@
1
- require 'MrMurano/version'
2
- require 'MrMurano/Solution-Cors'
3
- require 'MrMurano/ProjectFile'
4
1
  require 'tempfile'
5
2
  require 'yaml'
3
+ require 'MrMurano/version'
4
+ require 'MrMurano/ProjectFile'
5
+ require 'MrMurano/SyncRoot'
6
+ require 'MrMurano/Webservice-Cors'
6
7
  require '_workspace'
7
8
 
8
- RSpec.describe MrMurano::Cors do
9
+ RSpec.describe MrMurano::Webservice::Cors do
9
10
  include_context "WORKSPACE"
10
11
  before(:example) do
11
- MrMurano::SyncRoot.reset
12
+ MrMurano::SyncRoot.instance.reset
12
13
  $cfg = MrMurano::Config.new
13
14
  $cfg.load
14
15
  $cfg['net.host'] = 'bizapi.hosted.exosite.io'
15
- $cfg['solution.id'] = 'XYZ'
16
+ $cfg['application.id'] = 'XYZ'
16
17
 
17
- @srv = MrMurano::Cors.new
18
+ @srv = MrMurano::Webservice::Cors.new
18
19
  allow(@srv).to receive(:token).and_return("TTTTTTTTTT")
20
+
21
+ @baseURI = "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/cors"
19
22
  end
20
23
 
21
24
  it "initializes" do
22
- uri = @srv.endPoint('/')
23
- expect(uri.to_s).to eq("https://bizapi.hosted.exosite.io/api:1/solution/XYZ/cors/")
25
+ uri = @srv.endpoint('/')
26
+ expect(uri.to_s).to eq("#{@baseURI}/")
24
27
  end
25
28
 
26
29
  context "when server gives string" do
@@ -31,7 +34,7 @@ RSpec.describe MrMurano::Cors do
31
34
  :headers=>["Content-Type","Cookie","Authorization"],
32
35
  :credentials=>true}
33
36
  body = {:cors=>cors.to_json}
34
- stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/cors").
37
+ stub_request(:get, "#{@baseURI}").
35
38
  with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
36
39
  'Content-Type'=>'application/json'}).
37
40
  to_return(body: body.to_json)
@@ -45,7 +48,7 @@ RSpec.describe MrMurano::Cors do
45
48
  :headers=>["Content-Type","Cookie","Authorization"],
46
49
  :credentials=>true}
47
50
  body = {:cors=>cors.to_json}
48
- stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/cors").
51
+ stub_request(:get, "#{@baseURI}").
49
52
  with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
50
53
  'Content-Type'=>'application/json'}).
51
54
  to_return(body: body.to_json)
@@ -70,7 +73,7 @@ RSpec.describe MrMurano::Cors do
70
73
  :headers=>["Content-Type","Cookie","Authorization"],
71
74
  :credentials=>true}
72
75
  body = cors
73
- stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/cors").
76
+ stub_request(:get, "#{@baseURI}").
74
77
  with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
75
78
  'Content-Type'=>'application/json'}).
76
79
  to_return(body: body.to_json)
@@ -84,7 +87,7 @@ RSpec.describe MrMurano::Cors do
84
87
  :headers=>["Content-Type","Cookie","Authorization"],
85
88
  :credentials=>true}
86
89
  body = cors
87
- stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/cors").
90
+ stub_request(:get, "#{@baseURI}").
88
91
  with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
89
92
  'Content-Type'=>'application/json'}).
90
93
  to_return(body: body.to_json)
@@ -111,8 +114,8 @@ RSpec.describe MrMurano::Cors do
111
114
  :credentials=>true}
112
115
  end
113
116
  it "specified file" do
114
- File.open(File.join(@projectDir, 'bob.yaml'), 'w'){|io| io << @cors.to_yaml}
115
- stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/cors").
117
+ File.open(File.join(@project_dir, 'bob.yaml'), 'w'){|io| io << @cors.to_yaml}
118
+ stub_request(:put, "#{@baseURI}").
116
119
  with(:body=>@cors.to_json,
117
120
  :headers=>{'Authorization'=>'token TTTTTTTTTT',
118
121
  'Content-Type'=>'application/json'}).
@@ -123,9 +126,9 @@ RSpec.describe MrMurano::Cors do
123
126
  end
124
127
 
125
128
  it "file in $project" do
126
- File.open(File.join(@projectDir, 'bob.yaml'), 'w'){|io| io << @cors.to_yaml}
129
+ File.open(File.join(@project_dir, 'bob.yaml'), 'w'){|io| io << @cors.to_yaml}
127
130
  $project['routes.cors'] = 'bob.yaml'
128
- stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/cors").
131
+ stub_request(:put, "#{@baseURI}").
129
132
  with(:body=>@cors.to_json,
130
133
  :headers=>{'Authorization'=>'token TTTTTTTTTT',
131
134
  'Content-Type'=>'application/json'}).
@@ -136,8 +139,8 @@ RSpec.describe MrMurano::Cors do
136
139
  end
137
140
 
138
141
  it "file defaults thru $project" do
139
- File.open(File.join(@projectDir, 'cors.yaml'), 'w'){|io| io << @cors.to_yaml}
140
- stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/cors").
142
+ File.open(File.join(@project_dir, 'cors.yaml'), 'w'){|io| io << @cors.to_yaml}
143
+ stub_request(:put, "#{@baseURI}").
141
144
  with(:body=>@cors.to_json,
142
145
  :headers=>{'Authorization'=>'token TTTTTTTTTT',
143
146
  'Content-Type'=>'application/json'}).
@@ -149,7 +152,7 @@ RSpec.describe MrMurano::Cors do
149
152
 
150
153
  it "cors in $project" do
151
154
  $project['routes.cors'] = @cors
152
- stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/cors").
155
+ stub_request(:put, "#{@baseURI}").
153
156
  with(:body=>@cors.to_json,
154
157
  :headers=>{'Authorization'=>'token TTTTTTTTTT',
155
158
  'Content-Type'=>'application/json'}).
@@ -1,9 +1,10 @@
1
- require 'MrMurano/version'
2
- require 'MrMurano/Solution-Endpoint'
3
1
  require 'tempfile'
4
2
  require '_workspace'
3
+ require 'MrMurano/version'
4
+ require 'MrMurano/ProjectFile'
5
+ require 'MrMurano/Webservice-Endpoint'
5
6
 
6
- RSpec.describe MrMurano::Endpoint do
7
+ RSpec.describe MrMurano::Webservice::Endpoint do
7
8
  include_context "WORKSPACE"
8
9
  before(:example) do
9
10
  $cfg = MrMurano::Config.new
@@ -11,15 +12,17 @@ RSpec.describe MrMurano::Endpoint do
11
12
  $project = MrMurano::ProjectFile.new
12
13
  $project.load
13
14
  $cfg['net.host'] = 'bizapi.hosted.exosite.io'
14
- $cfg['solution.id'] = 'XYZ'
15
+ $cfg['application.id'] = 'XYZ'
15
16
 
16
- @srv = MrMurano::Endpoint.new
17
+ @srv = MrMurano::Webservice::Endpoint.new
17
18
  allow(@srv).to receive(:token).and_return("TTTTTTTTTT")
19
+
20
+ @baseURI = "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint"
18
21
  end
19
22
 
20
23
  it "initializes" do
21
- uri = @srv.endPoint('/')
22
- expect(uri.to_s).to eq("https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint/")
24
+ uri = @srv.endpoint('/')
25
+ expect(uri.to_s).to eq("#{@baseURI}/")
23
26
  end
24
27
 
25
28
  context "lists" do
@@ -36,12 +39,12 @@ RSpec.describe MrMurano::Endpoint do
36
39
  :content_type=>"application/json",
37
40
  :script=> "--#ENDPOINT WEBSOCKET /api/v1/foo/{id}\nresponse.message = \"HI\"\n\n-- BOB WAS HERE\n",
38
41
  }]
39
- stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint").
42
+ stub_request(:get, @baseURI).
40
43
  with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
41
44
  'Content-Type'=>'application/json'}).
42
45
  to_return(body: body.to_json)
43
46
 
44
- ret = @srv.list()
47
+ ret = @srv.list
45
48
  expect(ret).to eq(body)
46
49
  end
47
50
 
@@ -58,12 +61,12 @@ RSpec.describe MrMurano::Endpoint do
58
61
  :content_type=>"application/json",
59
62
  :script=> "response.message = \"HI\"\n\n-- BOB WAS HERE\n",
60
63
  }]
61
- stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint").
64
+ stub_request(:get, @baseURI).
62
65
  with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
63
66
  'Content-Type'=>'application/json'}).
64
67
  to_return(body: body.to_json)
65
68
 
66
- ret = @srv.list()
69
+ ret = @srv.list
67
70
  expect(ret).to eq(body)
68
71
  end
69
72
 
@@ -80,12 +83,12 @@ RSpec.describe MrMurano::Endpoint do
80
83
  :content_type=>"image/png",
81
84
  :script=> "--#ENDPOINT WEBSOCKET /api/v1/foo/{id} image/png\nresponse.message = \"HI\"\n\n-- BOB WAS HERE\n",
82
85
  }]
83
- stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint").
86
+ stub_request(:get, @baseURI).
84
87
  with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
85
88
  'Content-Type'=>'application/json'}).
86
89
  to_return(body: body.to_json)
87
90
 
88
- ret = @srv.list()
91
+ ret = @srv.list
89
92
  expect(ret).to eq(body)
90
93
  end
91
94
 
@@ -102,12 +105,12 @@ RSpec.describe MrMurano::Endpoint do
102
105
  :content_type=>"image/png",
103
106
  :script=> "--#ENDPOINT WEBSOCKET /api/v1/foo/{id}\nresponse.message = \"HI\"\n\n-- BOB WAS HERE\n",
104
107
  }]
105
- stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint").
108
+ stub_request(:get, @baseURI).
106
109
  with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
107
110
  'Content-Type'=>'application/json'}).
108
111
  to_return(body: body.to_json)
109
112
 
110
- ret = @srv.list()
113
+ ret = @srv.list
111
114
  expect(ret).to eq(body)
112
115
  end
113
116
 
@@ -124,12 +127,11 @@ RSpec.describe MrMurano::Endpoint do
124
127
  :content_type=>"image/png",
125
128
  :script=> "--#ENDPOINT WEBSOCKET /api/v1/foo/{id}\nresponse.message = \"HI\"\n\n-- BOB WAS HERE\n",
126
129
  }]
127
- stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint").
130
+ stub_request(:get, @baseURI).
128
131
  with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
129
132
  'Content-Type'=>'application/json'}).
130
133
  to_return(body: body.to_json)
131
-
132
- ret = @srv.list()
134
+ ret = @srv.list
133
135
  body.first.merge!({:content_type=>'application/json'})
134
136
  expect(ret).to eq(body)
135
137
  end
@@ -146,12 +148,12 @@ RSpec.describe MrMurano::Endpoint do
146
148
  :content_type=>"image/png",
147
149
  :script=> "--#ENDPOINT WEBSOCKET /api/v1/foo/{id}\nresponse.message = \"HI\"\n\n-- BOB WAS HERE\n",
148
150
  }]
149
- stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint").
151
+ stub_request(:get, @baseURI).
150
152
  with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
151
153
  'Content-Type'=>'application/json'}).
152
154
  to_return(body: body.to_json)
153
155
 
154
- ret = @srv.list()
156
+ ret = @srv.list
155
157
  body.first.merge!({:content_type=>'application/json'})
156
158
  expect(ret).to eq(body)
157
159
  end
@@ -167,7 +169,7 @@ RSpec.describe MrMurano::Endpoint do
167
169
  :content_type=>"application/json",
168
170
  :script=>"--#ENDPOINT WEBSOCKET /api/v1/bar\nresponse.message = \"HI\"\n",
169
171
  }
170
- stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint/9K0").
172
+ stub_request(:get, "#{@baseURI}/9K0").
171
173
  with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
172
174
  'Content-Type'=>'application/json'}).
173
175
  to_return(body: body.to_json)
@@ -183,7 +185,7 @@ RSpec.describe MrMurano::Endpoint do
183
185
  :content_type=>"application/json",
184
186
  :script=>"--#ENDPOINT WEBSOCKET /api/v1/bar\nresponse.message = \"HI\"\n",
185
187
  }
186
- stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint/9K0").
188
+ stub_request(:get, "#{@baseURI}/9K0").
187
189
  with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
188
190
  'Content-Type'=>'application/json'}).
189
191
  to_return(body: body.to_json)
@@ -202,7 +204,7 @@ RSpec.describe MrMurano::Endpoint do
202
204
  :content_type=>"application/json",
203
205
  :script=>"response.message = \"HI\"\n",
204
206
  }
205
- stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint/9K0").
207
+ stub_request(:get, "#{@baseURI}/9K0").
206
208
  with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
207
209
  'Content-Type'=>'application/json'}).
208
210
  to_return(body: body.to_json)
@@ -218,7 +220,7 @@ RSpec.describe MrMurano::Endpoint do
218
220
  :content_type=>"text/csv",
219
221
  :script=>"--#ENDPOINT WEBSOCKET /api/v1/bar text/csv\nresponse.message = \"HI\"\n",
220
222
  }
221
- stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint/9K0").
223
+ stub_request(:get, "#{@baseURI}/9K0").
222
224
  with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
223
225
  'Content-Type'=>'application/json'}).
224
226
  to_return(body: body.to_json)
@@ -234,7 +236,7 @@ RSpec.describe MrMurano::Endpoint do
234
236
  :content_type=>"text/csv",
235
237
  :script=>"--#ENDPOINT WEBSOCKET /api/v1/bar\nresponse.message = \"HI\"\n",
236
238
  }
237
- stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint/9K0").
239
+ stub_request(:get, "#{@baseURI}/9K0").
238
240
  with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
239
241
  'Content-Type'=>'application/json'}).
240
242
  to_return(body: body.to_json)
@@ -250,7 +252,7 @@ RSpec.describe MrMurano::Endpoint do
250
252
  :content_type=>"text/csv",
251
253
  :script=>"--#ENDPOINT WEBSOCKET /api/v1/bar image/png\nresponse.message = \"HI\"\n",
252
254
  }
253
- stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint/9K0").
255
+ stub_request(:get, "#{@baseURI}/9K0").
254
256
  with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
255
257
  'Content-Type'=>'application/json'}).
256
258
  to_return(body: body.to_json)
@@ -261,7 +263,7 @@ RSpec.describe MrMurano::Endpoint do
261
263
  end
262
264
 
263
265
  it "removes" do
264
- stub_request(:delete, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint/9K0").
266
+ stub_request(:delete, "#{@baseURI}/9K0").
265
267
  with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
266
268
  'Content-Type'=>'application/json'}).
267
269
  to_return(body: "")
@@ -285,13 +287,13 @@ RSpec.describe MrMurano::Endpoint do
285
287
  end
286
288
 
287
289
  it "over old version" do
288
- stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint/9K0").
290
+ stub_request(:put, "#{@baseURI}/9K0").
289
291
  with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
290
292
  'Content-Type'=>'application/json'}).
291
293
  to_return(body: "")
292
294
 
293
295
  ret = @srv.upload(@tio_.path,
294
- MrMurano::Endpoint::RouteItem.new(
296
+ MrMurano::Webservice::Endpoint::RouteItem.new(
295
297
  :id=>"9K0",
296
298
  :method=>"websocket",
297
299
  :path=>"/api/v1/bar",
@@ -301,17 +303,17 @@ RSpec.describe MrMurano::Endpoint do
301
303
  end
302
304
 
303
305
  it "when nothing is there" do
304
- stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint/9K0").
306
+ stub_request(:put, "#{@baseURI}/9K0").
305
307
  with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
306
308
  'Content-Type'=>'application/json'}).
307
309
  to_return(status: 404)
308
- stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint/").
310
+ stub_request(:post, "#{@baseURI}/").
309
311
  with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
310
312
  'Content-Type'=>'application/json'}).
311
313
  to_return(body: "")
312
314
 
313
315
  ret = @srv.upload(@tio_.path,
314
- MrMurano::Endpoint::RouteItem.new(
316
+ MrMurano::Webservice::Endpoint::RouteItem.new(
315
317
  :id=>"9K0",
316
318
  :method=>"websocket",
317
319
  :path=>"/api/v1/bar",
@@ -321,13 +323,13 @@ RSpec.describe MrMurano::Endpoint do
321
323
  end
322
324
 
323
325
  it "without an itemkey" do
324
- stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint/").
326
+ stub_request(:post, @baseURI).
325
327
  with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
326
328
  'Content-Type'=>'application/json'}).
327
329
  to_return(body: "")
328
330
 
329
331
  ret = @srv.upload(@tio_.path,
330
- MrMurano::Endpoint::RouteItem.new(
332
+ MrMurano::Webservice::Endpoint::RouteItem.new(
331
333
  :method=>"websocket",
332
334
  :path=>"/api/v1/bar",
333
335
  :content_type=>"application/json",
@@ -336,14 +338,14 @@ RSpec.describe MrMurano::Endpoint do
336
338
  end
337
339
 
338
340
  it "Handles others errors" do
339
- stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint/9K0").
341
+ stub_request(:put, "#{@baseURI}/9K0").
340
342
  with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
341
343
  'Content-Type'=>'application/json'}).
342
344
  to_return(status: 502, body: "{}")
343
345
 
344
346
  expect(@srv).to receive(:error).and_return(nil)
345
347
  ret = @srv.upload(@tio_.path,
346
- MrMurano::Endpoint::RouteItem.new(
348
+ MrMurano::Webservice::Endpoint::RouteItem.new(
347
349
  :id=>"9K0",
348
350
  :method=>"websocket",
349
351
  :path=>"/api/v1/bar",
@@ -432,7 +434,7 @@ RSpec.describe MrMurano::Endpoint do
432
434
  end
433
435
  end
434
436
 
435
- context "toRemoteItem" do
437
+ context "to_remote_item" do
436
438
  it "reads one" do
437
439
  Tempfile.open("foo") do |tio|
438
440
  tio << %{--#ENDPOINT GET /one/two
@@ -441,7 +443,7 @@ RSpec.describe MrMurano::Endpoint do
441
443
  }.gsub(/^\s+/,'')
442
444
  tio.close
443
445
 
444
- ret = @srv.toRemoteItem(nil, tio.path)
446
+ ret = @srv.to_remote_item(nil, tio.path)
445
447
  e = {:method=>"GET",
446
448
  :path=>"/one/two",
447
449
  :content_type=>"application/json",
@@ -466,7 +468,7 @@ RSpec.describe MrMurano::Endpoint do
466
468
  }.gsub(/^\s+/,'')
467
469
  tio.close
468
470
 
469
- ret = @srv.toRemoteItem(nil, tio.path)
471
+ ret = @srv.to_remote_item(nil, tio.path)
470
472
 
471
473
  expect(ret).to eq([
472
474
  {
@@ -508,7 +510,7 @@ RSpec.describe MrMurano::Endpoint do
508
510
  }.gsub(/^\s+/,'')
509
511
  tio.close
510
512
 
511
- ret = @srv.toRemoteItem(nil, tio.path)
513
+ ret = @srv.to_remote_item(nil, tio.path)
512
514
  expect(ret).to eq([])
513
515
  end
514
516
  end
@@ -523,7 +525,7 @@ RSpec.describe MrMurano::Endpoint do
523
525
  }.gsub(/^\s+/,'')
524
526
  tio.close
525
527
 
526
- ret = @srv.toRemoteItem(nil, tio.path)
528
+ ret = @srv.to_remote_item(nil, tio.path)
527
529
  e = {:method=>"GET",
528
530
  :path=>"/one/two",
529
531
  :content_type=>"application/json",
@@ -1,8 +1,9 @@
1
1
  require 'MrMurano/version'
2
- require 'MrMurano/Solution-File'
2
+ require 'MrMurano/ProjectFile'
3
+ require 'MrMurano/Webservice-File'
3
4
  require '_workspace'
4
5
 
5
- RSpec.describe MrMurano::File do
6
+ RSpec.describe MrMurano::Webservice::File do
6
7
  include_context "WORKSPACE"
7
8
  before(:example) do
8
9
  $cfg = MrMurano::Config.new
@@ -10,40 +11,49 @@ RSpec.describe MrMurano::File do
10
11
  $project = MrMurano::ProjectFile.new
11
12
  $project.load
12
13
  $cfg['net.host'] = 'bizapi.hosted.exosite.io'
13
- $cfg['solution.id'] = 'XYZ'
14
+ $cfg['product.id'] = 'XYZ'
15
+ $cfg['application.id'] = 'XYZ'
14
16
 
15
- @srv = MrMurano::File.new
17
+ @srv = MrMurano::Webservice::File.new
16
18
  allow(@srv).to receive(:token).and_return("TTTTTTTTTT")
19
+
20
+ @baseURI = "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/file"
21
+ @fileuploadURI = "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/fileupload"
17
22
  end
18
23
 
19
24
  it "initializes" do
20
- uri = @srv.endPoint('/')
21
- expect(uri.to_s).to eq("https://bizapi.hosted.exosite.io/api:1/solution/XYZ/file/")
25
+ uri = @srv.endpoint('/')
26
+ expect(uri.to_s).to eq("#{@baseURI}/")
22
27
  end
23
28
 
24
29
  it "lists" do
25
30
  body = [
26
- {:path=>"/",
27
- :mime_type=>"text/html",
28
- :checksum=>"f535dad52b2877a49717a034b4eee5ff1cdb8a18"},
29
- {:path=>"/batteryMeter.svg",
30
- :mime_type=>"image/svg+xml",
31
- :checksum=>"06a1aab86ba8cb9b3f2913c673d4aa243c553494"},
32
- {:path=>"/meter.html",
33
- :mime_type=>"text/html",
34
- :checksum=>"82e12125c2f1324bbf7bd64bf187f3334416117e"}
31
+ {
32
+ :path=>"/",
33
+ :mime_type=>"text/html",
34
+ :checksum=>"f535dad52b2877a49717a034b4eee5ff1cdb8a18",
35
+ },
36
+ {
37
+ :path=>"/batteryMeter.svg",
38
+ :mime_type=>"image/svg+xml",
39
+ :checksum=>"06a1aab86ba8cb9b3f2913c673d4aa243c553494",
40
+ },
41
+ {
42
+ :path=>"/meter.html",
43
+ :mime_type=>"text/html",
44
+ :checksum=>"82e12125c2f1324bbf7bd64bf187f3334416117e",
45
+ }
35
46
  ]
36
- stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/file").
47
+ stub_request(:get, @baseURI).
37
48
  with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
38
49
  'Content-Type'=>'application/json'}).
39
50
  to_return(body: body.to_json)
40
-
41
- ret = @srv.list()
51
+ ret = @srv.list
42
52
  expect(ret).to eq(body)
43
53
  end
44
54
 
45
55
  it "removes" do
46
- stub_request(:delete, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/file/index.html").
56
+ stub_request(:delete, "#{@baseURI}/index.html").
47
57
  with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
48
58
  'Content-Type'=>'application/json'}).
49
59
  to_return(status: 200)
@@ -53,7 +63,7 @@ RSpec.describe MrMurano::File do
53
63
 
54
64
  context "fetches" do
55
65
  it "gets an error" do
56
- stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/file/bob").
66
+ stub_request(:get, "#{@baseURI}/bob").
57
67
  with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
58
68
  'Content-Type'=>'application/json'}).
59
69
  to_return(status: 404, body: "nope")
@@ -66,7 +76,7 @@ RSpec.describe MrMurano::File do
66
76
  end
67
77
 
68
78
  it "gets $stdout" do
69
- stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/file/bob").
79
+ stub_request(:get, "#{@baseURI}/bob").
70
80
  with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
71
81
  'Content-Type'=>'application/json'}).
72
82
  to_return(status: 200, body: "nope")
@@ -79,7 +89,7 @@ RSpec.describe MrMurano::File do
79
89
  end
80
90
 
81
91
  it "gets to block" do
82
- stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/file/bob").
92
+ stub_request(:get, "#{@baseURI}/bob").
83
93
  with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
84
94
  'Content-Type'=>'application/json'}).
85
95
  to_return(status: 200, body: "nope")
@@ -92,14 +102,14 @@ RSpec.describe MrMurano::File do
92
102
 
93
103
  context "uploads" do
94
104
  before(:example) do
95
- FileUtils.mkpath(@projectDir + '/files')
96
- @lp = Pathname.new(@projectDir + '/files/one.text')
105
+ FileUtils.mkpath(@project_dir + '/files')
106
+ @lp = Pathname.new(@project_dir + '/files/one.text')
97
107
  @lp.open('w') {|io| io << %{Just some text}}
98
108
  @lp = @lp.realpath
99
109
  end
100
110
 
101
111
  it "an item" do
102
- stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/fileupload/one.text").
112
+ stub_request(:put, "#{@baseURI}upload/one.text").
103
113
  with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
104
114
  'Content-Type'=>%r{multipart/form-data; boundary=.*}},
105
115
  )
@@ -108,7 +118,7 @@ RSpec.describe MrMurano::File do
108
118
  end
109
119
 
110
120
  it "gets an error" do
111
- stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/fileupload/one.text").
121
+ stub_request(:put, "#{@baseURI}upload/one.text").
112
122
  with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
113
123
  'Content-Type'=>%r{multipart/form-data; boundary=.*}},
114
124
  ).
@@ -122,15 +132,16 @@ RSpec.describe MrMurano::File do
122
132
  end
123
133
 
124
134
  it "an item with curl debug" do
125
- stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/fileupload/one.text").
135
+ stub_request(:put, "#{@baseURI}upload/one.text").
126
136
  with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
127
137
  'Content-Type'=>%r{multipart/form-data; boundary=.*}},
128
138
  )
129
139
  $cfg['tool.curldebug'] = true
140
+ $cfg.curlfile_f = nil
130
141
  saved = $stdout
131
142
  $stdout = StringIO.new
132
143
  @srv.upload(@lp, {:path=>'/one.text'}, false)
133
- expect($stdout.string).to match(%r{^curl -s -H 'Authorization: token TTTTTTTTTT'.*-X PUT 'https://bizapi.hosted.exosite.io/api:1/solution/XYZ/fileupload/one.text' -F file=@.*$})
144
+ expect($stdout.string).to match(%r{^curl -s -H 'Authorization: token TTTTTTTTTT'.*-X PUT '#{@fileuploadURI}/one.text' -F file=@.*$})
134
145
  $stdout = saved
135
146
  end
136
147
  end
@@ -191,16 +202,16 @@ RSpec.describe MrMurano::File do
191
202
  end
192
203
  end
193
204
 
194
- context "toRemoteItem" do
205
+ context "to_remote_item" do
195
206
  before(:example) do
196
- FileUtils.mkpath(@projectDir + '/files')
197
- @lp = Pathname.new(@projectDir + '/files/one.text')
207
+ FileUtils.mkpath(@project_dir + '/files')
208
+ @lp = Pathname.new(@project_dir + '/files/one.text')
198
209
  @lp.open('w') {|io| io << %{Just some text}}
199
210
  @lp = @lp.realpath
200
211
  end
201
212
  it "gets item" do
202
- prj = Pathname.new(@projectDir).realpath
203
- ret = @srv.toRemoteItem(prj, @lp)
213
+ prj = Pathname.new(@project_dir).realpath
214
+ ret = @srv.to_remote_item(prj, @lp)
204
215
  expect(ret).to eq({
205
216
  :path=>"/files/one.text",
206
217
  :mime_type=>"text/plain",