better_rest 0.2.2 → 0.2.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e990eb58751881bf19708d2bb4a521c954a07850
4
- data.tar.gz: baee501acb9b69804a6b903601e1dc1d96c6e24e
3
+ metadata.gz: bfaa3bbcd0d6672673e20e65445adf86c73f5a6e
4
+ data.tar.gz: 12f00f9fe9fde98badb210259983162dad385666
5
5
  SHA512:
6
- metadata.gz: 6840e1c632dd3d70ee43979c40bffdf63585787a016b0fdba43a5d555433e16f0a261df189226d01632bb7e577068823e22e8ecbdcf3adb3ea61340bbdbdf822
7
- data.tar.gz: 361612d6422112d2fd219ec56397f859fc1a35e37f3d161b5917ee2ee7ed1112d8b116a523abed26ae86e0be97f2fbcf2ef967364ed85349ea0106c0f0334565
6
+ metadata.gz: 141d47a6c68f753520bbc8f84b21bcc3d2e8e9be62ac10bf9e0c03d80a6c1fd3b28c0e012383b186cfad111b27bccd704e2b859b91a7917b54b9fe453ffdfe68
7
+ data.tar.gz: 179de131c5a8df2f23d95dbe4dae2df4f692090a564957a0d0acf31d1122e382a6a3adc4026512606f3f6c041c617f4b59c754eda385fe1afd887d46705c60a5
@@ -1,13 +1,13 @@
1
1
  Gem::Specification.new do |s|
2
- s.name = "better_rest"
3
- s.version = "0.2.2"
4
- s.licenses = ['MIT']
5
- s.summary = "REST Test Client"
6
- s.date = "2014-12-13"
7
- s.description = "Configurable REST API test client accessible via your browser"
8
- s.authors = ["Jason Willems"]
9
- s.email = ["jason@willems.ca"]
10
- s.homepage = "https://github.com/at1as/BetteR"
11
- s.files = `git ls-files`.split("\n")
2
+ s.name = "better_rest"
3
+ s.version = "0.2.3"
4
+ s.licenses = ['MIT']
5
+ s.summary = "REST Test Client"
6
+ s.date = "2015-02-01"
7
+ s.description = "Configurable REST API test client accessible via your browser"
8
+ s.authors = ["Jason Willems"]
9
+ s.email = ["jason@willems.ca"]
10
+ s.homepage = "https://github.com/at1as/BetteR"
11
+ s.files = `git ls-files`.split("\n")
12
12
  s.executables << 'better_rest'
13
13
  end
@@ -8,8 +8,16 @@ require 'sinatra'
8
8
  require 'typhoeus'
9
9
  require 'json'
10
10
 
11
+ set :environment, :development
11
12
  set :public_dir, File.expand_path('../../public', __FILE__)
12
13
  set :views, File.expand_path('../../views', __FILE__)
14
+ set :bind, '0.0.0.0'
15
+
16
+ configure :development do
17
+ enable :logging, :dump_errors, :raise_errors
18
+ end
19
+ set :show_exceptions, true if development?
20
+
13
21
 
14
22
  helpers do
15
23
  include Rack::Utils
@@ -17,9 +25,12 @@ helpers do
17
25
 
18
26
  def parse_cookies(cookies)
19
27
  cookie_hash = {}
20
- cookies.each do |c|
21
- key, value = c.split('; ').first.split('=', 2)
22
- cookie_hash[key] = value
28
+ cookies_list = [*cookies]
29
+ cookies_list.each do |cookie|
30
+ cookie.split('; ').each do |c|
31
+ key, value = c.split('=', 2)
32
+ cookie_hash[key] = value
33
+ end
23
34
  end
24
35
  cookie_hash.to_json
25
36
  end
@@ -135,7 +146,7 @@ post '/request' do
135
146
  end
136
147
 
137
148
  # Write cookie to file
138
- if response.headers_hash['set-cookie']
149
+ if @cookies && response.headers_hash['set-cookie']
139
150
  cookies = parse_cookies(response.headers_hash['set-cookie'])
140
151
  File.open('cookiejar', 'w') { |file| file.write(cookies) }
141
152
  end
@@ -161,7 +172,7 @@ post '/request' do
161
172
  @response_body['return_body'] = response.body.force_encoding('ISO-8859-1')
162
173
  end
163
174
 
164
- @response_body['return_headers'] = response.response_headers
175
+ @response_body['return_headers'] = response.response_headers.force_encoding('ISO-8859-1')
165
176
 
166
177
  @response_body.to_json
167
178
  end
@@ -276,7 +287,18 @@ get '/logs/:log' do
276
287
  end
277
288
 
278
289
 
279
- # Delete log
290
+ # Delete logs
291
+ delete '/logs' do
292
+ logs = Dir["logs/*.log"]
293
+
294
+ logs.each do |log|
295
+ File.delete(log)
296
+ end
297
+ 200
298
+ end
299
+
300
+
301
+ # Delete log entry
280
302
  delete '/logs/:log' do
281
303
  log = "logs/#{params[:log]}.log"
282
304
 
@@ -375,7 +397,8 @@ get '/env' do
375
397
  Ruby: #{RUBY_VERSION} <br/>
376
398
  Rack: #{Rack::VERSION} <br/>
377
399
  Sinatra: #{Sinatra::VERSION} <br/>
378
- API: v#{API_VERSION}
400
+ API: v#{API_VERSION} <br/>
401
+ Env: #{settings.environment}
379
402
  ENDRESPONSE
380
403
  end
381
404
 
@@ -98,7 +98,7 @@ ul li:hover ul {
98
98
 
99
99
  /* Classes */
100
100
  .container{
101
- max-width:700px;
101
+ max-width:720px;
102
102
  }
103
103
  .width13{
104
104
  width:13%;
@@ -264,18 +264,30 @@ ul li:hover ul {
264
264
  .semi-bold{
265
265
  font-weight:500;
266
266
  }
267
+ .logEntry{
268
+ text-align:center;
269
+ padding-top:4px;
270
+ padding-bottom:4px;
271
+ }
267
272
  .logNodes{
268
- display:block;
273
+ display:inline-block;
269
274
  text-align:center;
270
275
  margin-right:auto;
271
276
  margin-left:auto;
272
- padding-left:40px;
273
277
  padding-right:40px;
274
278
  }
275
279
  .navbar-nav>li>a {
276
280
  line-height:1.2;
277
281
  }
278
-
282
+ .headerContainer{
283
+ margin-bottom:2px;
284
+ }
285
+ .float-red:hover{
286
+ color:red;
287
+ }
288
+ .form-control{
289
+ height: 32px;
290
+ }
279
291
 
280
292
  /* By ID */
281
293
  #add{
@@ -366,6 +378,13 @@ ul li:hover ul {
366
378
  #logs-modal{
367
379
  width:400px;
368
380
  }
381
+ #clearAllLogs{
382
+ margin-left:auto;
383
+ margin-right:auto;
384
+ margin-top:15px;
385
+ width:100%;
386
+ text-align:center;
387
+ }
369
388
 
370
389
 
371
390
  /* Tooltips */
@@ -105,9 +105,9 @@
105
105
  <div class="box" id="headers">
106
106
  <div id="headerfieldsAll">
107
107
  <% @header_hash.each_with_index do |(key, value), index| %>
108
- <div id="headerfields<%= index %>" style="margin-bottom:2px;" >
109
- <input type="text" value="<%=key%>" name="key<%=index%>" id="key<%=index%>" placeholder=" Name" class="key form-control head-input" />
110
- <input type="text" value="<%=value%>" name="value<%=index%>" id="value<%=index%>" placeholder=" Value" class="value form-control head-input" />
108
+ <div id="headerfields<%= index %>" class="headerContainer" >
109
+ <input type="text" value="<%=key%>" name="key" id="key<%=index%>" placeholder=" Name" class="key form-control head-input" autocomplete="off"/>
110
+ <input type="text" value="<%=value%>" name="value" id="value<%=index%>" placeholder=" Value" class="value form-control head-input" autocomplete="off"/>
111
111
 
112
112
  <button id="close<%= index %>" tabindex="-1" type="button" class="close" onclick="removeRow(this)">
113
113
  <span style="line-height:inherit" aria-hidden="true">&times;</span>
@@ -299,6 +299,9 @@
299
299
  <hr>
300
300
  <div class="modal-body">
301
301
  <div id="logsdata"></div>
302
+ <div id="clearAllLogs">
303
+ <div class="btn btn-simple" style="width:200px" onclick="deleteAllLogs()">Delete All</div>
304
+ </div>
302
305
  </div>
303
306
  </div>
304
307
  </div>
@@ -664,8 +667,28 @@
664
667
  }
665
668
 
666
669
 
670
+ /* delete log from list */
671
+ function deleteLog(button_id){
672
+ var log_name = button_id.getAttribute('name');
673
+
674
+ var url = '/logs/' + log_name;
675
+ var client = new XMLHttpRequest();
676
+
677
+ client.onreadystatechange = function() {
678
+ if (client.readyState == 4 && client.status == 200) {
679
+ modalHideAll();
680
+ logsList();
681
+ } else if (client.readyState == 4) {
682
+ console.log('Unknown Error: DELETE ' + log_name + ' failed');
683
+ }
684
+ }
685
+
686
+ client.open('DELETE', url, true);
687
+ client.send();
688
+ }
689
+
690
+
667
691
  /* Retrieve a list of all log entries */
668
- /* TODO: Add Log Deletion */
669
692
  function logsList(){
670
693
  var url = '/logs';
671
694
  var client = new XMLHttpRequest();
@@ -687,15 +710,21 @@
687
710
  for (j=0; j<log_list.length; j++) {
688
711
  var log_item = document.createElement('a');
689
712
  var item_txt = document.createTextNode(log_list[j]);
690
- //var close = document.createElement('span');
691
- //var entry_container = document.createElement('div');
713
+ var close = document.createElement('span');
714
+ var entry_container = document.createElement('div');
692
715
 
693
716
  log_item.href = '/logs/' + log_list[j];
694
717
  log_item.className = 'logNodes';
695
718
  log_item.appendChild(item_txt);
696
- //close.innerHTML = 'x';
697
- //close.setAttribute('onclick', deleteLog(log_list[j]));
698
- document.getElementById('logsdata').appendChild(log_item);
719
+ close.innerHTML = 'x';
720
+ close.className = 'float-red';
721
+ close.setAttribute('onclick', 'deleteLog(this)');
722
+ close.setAttribute('name', log_list[j]);
723
+
724
+ entry_container.className = 'logEntry';
725
+ entry_container.appendChild(log_item);
726
+ entry_container.appendChild(close);
727
+ document.getElementById('logsdata').appendChild(entry_container);
699
728
  }
700
729
  } else {
701
730
  console.log('Unknown Error: GET ' + logs + ' failed');
@@ -781,12 +810,12 @@
781
810
  var header_val = document.createElement('input');
782
811
  var close_btn = document.createElement('button');
783
812
 
784
- input_container.type = 'div';
785
- input_container.style = 'margin-bottom:2px;';
786
- input_container.id = 'headerfields' + clickCount;
813
+ input_container.type = 'div';
814
+ input_container.id = 'headerfields' + clickCount;
815
+ input_container.className = 'headerContainer';
787
816
 
788
817
  header_key.type = 'text';
789
- header_key.name = 'key' + clickCount;
818
+ header_key.name = 'key';
790
819
  header_key.id = 'key' + clickCount;
791
820
  header_key.className = 'key form-control head-input';
792
821
  header_key.placeholder = ' Name';
@@ -795,10 +824,10 @@
795
824
  header_key.value = header_key.value.replace('key', 'key' + clickCount);
796
825
 
797
826
  /* Not sure why this is necessary. But it is */
798
- header_key.style = 'margin-right:9px';
827
+ //header_key.style = 'margin-right:9px';
799
828
 
800
829
  header_val.type = 'text';
801
- header_val.name = 'value' + clickCount;
830
+ header_val.name = 'value';
802
831
  header_val.id = 'value' + clickCount;
803
832
  header_val.className = 'value form-control head-input';
804
833
  header_val.placeholder = ' Value';
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: better_rest
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
  - Jason Willems
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-13 00:00:00.000000000 Z
11
+ date: 2015-02-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Configurable REST API test client accessible via your browser
14
14
  email: