api_taster 0.2.1 → 0.2.2

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.
@@ -11,6 +11,16 @@ var ApiTaster = {
11
11
  },
12
12
  restoreFormActionFor: function(form) {
13
13
  $(form).attr("action", ApiTaster.formAction);
14
+ },
15
+ detectContentType: function(response) {
16
+ var contentType = response.getResponseHeader("Content-Type");
17
+ var detectedContentType = null
18
+
19
+ if (contentType.match(/application\/json/)) {
20
+ detectedContentType = 'json';
21
+ }
22
+
23
+ return detectedContentType;
14
24
  }
15
25
  };
16
26
 
@@ -46,6 +56,14 @@ $.fn.extend({
46
56
  $(contentElement + "[ref=" + $(this).attr("id") + "]", container).show();
47
57
  });
48
58
  },
59
+ showNavTab: function(name) {
60
+ $("ul.nav-tabs li", this).removeClass("active");
61
+ $("ul.nav-tabs li a#response-" + name, this).parent().show().addClass("active");
62
+
63
+ $("pre", this).hide();
64
+
65
+ return $("pre[ref=response-" + name + "]", this).show();
66
+ },
49
67
  displayOnlySelectedParamsFieldset: function() {
50
68
  $("fieldset", this).hide();
51
69
  $("fieldset[ref=" + $("ul.nav-tabs li.active a").attr("id") + "]", this).show();
@@ -86,10 +104,15 @@ jQuery(function($) {
86
104
  $("#show-api-response-div").slideDown(100);
87
105
  }
88
106
 
107
+ switch (ApiTaster.detectContentType(xhr)) {
108
+ case "json":
109
+ $("#show-api-response-div").showNavTab("json").text(
110
+ JSON.stringify(JSON.parse(xhr.responseText), null, 2)
111
+ );
112
+ break;
113
+ }
114
+
89
115
  $("#show-api-response-div pre[ref=response-raw]").text(xhr.responseText);
90
- $("#show-api-response-div pre[ref=response-json]").text(
91
- JSON.stringify(JSON.parse(xhr.responseText), null, 2)
92
- );
93
116
 
94
117
  prettyPrint();
95
118
  });
@@ -55,9 +55,9 @@
55
55
  <div id="show-api-response-div" class="well hidden">
56
56
  <ul class="nav nav-tabs">
57
57
  <li class="nav-label">Response</li>
58
- <li class="active"><a href="#" id="response-json">JSON</a></li>
59
- <li><a href="#" id="response-raw">Raw</a></li>
58
+ <li class="hidden"><a href="#" id="response-json">JSON</a></li>
59
+ <li class="active"><a href="#" id="response-raw">Raw</a></li>
60
60
  </ul>
61
- <pre class="prettyprint nowrap" ref="response-json"></pre>
62
- <pre class="prettyprint hidden" ref="response-raw"></pre>
61
+ <pre class="prettyprint nowrap hidden" ref="response-json"></pre>
62
+ <pre class="prettyprint" ref="response-raw"></pre>
63
63
  </div>
@@ -1,3 +1,3 @@
1
1
  module ApiTaster
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_taster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -349,7 +349,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
349
349
  version: '0'
350
350
  segments:
351
351
  - 0
352
- hash: 2843027510352515993
352
+ hash: -3781747277784541610
353
353
  required_rubygems_version: !ruby/object:Gem::Requirement
354
354
  none: false
355
355
  requirements:
@@ -358,7 +358,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
358
358
  version: '0'
359
359
  segments:
360
360
  - 0
361
- hash: 2843027510352515993
361
+ hash: -3781747277784541610
362
362
  requirements: []
363
363
  rubyforge_project:
364
364
  rubygems_version: 1.8.24