rack-faraday_inspector 0.1.0 → 0.2.0
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 +4 -4
- data/.gitignore +3 -0
- data/README.md +16 -5
- data/Rakefile +26 -1
- data/assets/css/style.css +1 -0
- data/assets/html/inspector.html.erb +22 -29
- data/assets/javascripts/inspector.js +83 -0
- data/assets/sass/{styles.scss → style.scss} +52 -16
- data/lib/rack/faraday_inspector.rb +15 -1
- data/lib/rack/faraday_inspector/asset_version.rb +5 -0
- data/lib/rack/faraday_inspector/middleware.rb +47 -29
- data/lib/rack/faraday_inspector/version.rb +1 -1
- data/rack-faraday_inspector.gemspec +10 -8
- metadata +65 -5
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 497118808554cb3dc0a5e578bfe4768512a58f56
         | 
| 4 | 
            +
              data.tar.gz: 6d4b861d47740da72fda849139742b9ec7c6156d
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 31e113cc13671ed00f4102688a58d1c0cb5fb138bc789150b95810df2f4ed81a0a104a0e04e0bb0d9fcd9980cef9bf1d52fe6f4293543d056b4429a42bd2774c
         | 
| 7 | 
            +
              data.tar.gz: 7399a9aa212df6f1173b72b8d63cd0317630797cd8aa7ac72db38094b5c0681a2debdce7e115f31283dfe105c95aab9bac7ac11b15c05b33aae7817b007192b3
         | 
    
        data/.gitignore
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -1,6 +1,8 @@ | |
| 1 1 | 
             
            # Rack::FaradayInspector
         | 
| 2 2 |  | 
| 3 | 
            -
            Rack::FaradayInspector renders a bit of HTML at the bottom of your pages that allows you to inspect all of the requests Faraday made  | 
| 3 | 
            +
            Rack::FaradayInspector renders a bit of HTML at the bottom of your pages that allows you to inspect all of the HTTP requests Faraday made during the current Rails action.
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            It's like your browser's developer tools network view, but for your backend API requests.
         | 
| 4 6 |  | 
| 5 7 | 
             
            
         | 
| 6 8 |  | 
| @@ -14,21 +16,30 @@ Add this line to your application's Gemfile: | |
| 14 16 | 
             
            gem 'rack-faraday_inspector', github: 'chrisb/rack-faraday_inspector'
         | 
| 15 17 | 
             
            ```
         | 
| 16 18 |  | 
| 17 | 
            -
            I'm still actively working on this Gem, so  | 
| 19 | 
            +
            I'm still actively working on this Gem, so pull from GitHub.
         | 
| 18 20 |  | 
| 19 21 | 
             
            ## Usage
         | 
| 20 22 |  | 
| 21 | 
            -
             | 
| 23 | 
            +
            In order to instrument and show Faraday requests, you'll need to add the middleware to your connection:
         | 
| 22 24 |  | 
| 23 25 | 
             
            ```ruby
         | 
| 24 | 
            -
            require 'rack/faraday_inspector'
         | 
| 25 | 
            -
             | 
| 26 26 | 
             
            Faraday.new url: 'http://www.sushi.com' do |faraday|
         | 
| 27 27 | 
             
              faraday.use :inspector
         | 
| 28 28 | 
             
              # ...
         | 
| 29 29 | 
             
            end
         | 
| 30 30 | 
             
            ```
         | 
| 31 31 |  | 
| 32 | 
            +
            By default the inspector web UI is disabled. To enable the inspector, add the following to an initializer, or better yet, to the specific Rails environment configurations that you want to enable the inspector for:
         | 
| 33 | 
            +
             | 
| 34 | 
            +
            i.e. in `config/environments/development.rb`:
         | 
| 35 | 
            +
             | 
| 36 | 
            +
            ```ruby
         | 
| 37 | 
            +
            Rails.application.configure do
         | 
| 38 | 
            +
              # ...
         | 
| 39 | 
            +
              Rack::FaradayInspector.enabled = true
         | 
| 40 | 
            +
            end
         | 
| 41 | 
            +
            ```
         | 
| 42 | 
            +
             | 
| 32 43 | 
             
            Note: only in the `development` environment will requests be instrumented and the inspector rendered.
         | 
| 33 44 |  | 
| 34 45 | 
             
            ## Contributing
         | 
    
        data/Rakefile
    CHANGED
    
    | @@ -1,2 +1,27 @@ | |
| 1 1 | 
             
            require "bundler/gem_tasks"
         | 
| 2 | 
            -
             | 
| 2 | 
            +
             | 
| 3 | 
            +
            task default: :spec
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            desc "compile SASS stylesheets"
         | 
| 6 | 
            +
            task :compile_sass do
         | 
| 7 | 
            +
              `sass assets/sass/style.scss --style compressed > assets/css/style.css`
         | 
| 8 | 
            +
            end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            # copied from rack-mini-profiler
         | 
| 11 | 
            +
            desc "update asset version file"
         | 
| 12 | 
            +
            task update_asset_version: :compile_sass do
         | 
| 13 | 
            +
              require 'digest/md5'
         | 
| 14 | 
            +
              h = []
         | 
| 15 | 
            +
              Dir.glob('assets/**/*.{js,css}').each do |f|
         | 
| 16 | 
            +
                h << Digest::MD5.hexdigest(::File.read(f))
         | 
| 17 | 
            +
              end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
              File.open('lib/rack/faraday_inspector/asset_version.rb','w') do |f|
         | 
| 20 | 
            +
                f.write \
         | 
| 21 | 
            +
            "module Rack
         | 
| 22 | 
            +
              class FaradayInspector
         | 
| 23 | 
            +
                ASSET_VERSION = '#{Digest::MD5.hexdigest(h.sort.join(''))}'.freeze
         | 
| 24 | 
            +
              end
         | 
| 25 | 
            +
            end"
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
            end
         | 
| @@ -0,0 +1 @@ | |
| 1 | 
            +
            .faraday_inspector{position:absolute;bottom:0;left:0;background-color:#f2f2f2;font-size:12px;font-family:'Helvetica Neue', sans-serif}.faraday_inspector.minimized{border:1px solid #eee;border-top-right-radius:8px;padding:8px}.faraday_inspector.minimized table{display:none}.faraday_inspector.minimized .request{display:none}.faraday_inspector.minimized .close{display:none}.faraday_inspector.open{width:100%;border-top:1px solid #eee}.faraday_inspector.open .prompt{display:none}.faraday_inspector.open .close{display:inline-block;position:absolute;top:0;right:0;padding:6px;font-size:14px}.faraday_inspector .event .method{font-weight:bold}.faraday_inspector .event .host,.faraday_inspector .event .duration,.faraday_inspector .event .status{color:#aaa}.faraday_inspector .event .host,.faraday_inspector .event .duration,.faraday_inspector .event .status,.faraday_inspector .event .method{width:60px}.faraday_inspector .event .host,.faraday_inspector .event .duration,.faraday_inspector .event .status{text-align:right}.faraday_inspector .event .method{text-align:center}.faraday_inspector .request{max-height:400px;text-overflow:scroll;overflow:scroll;font-family:'Source Code Pro Light', 'Menlo', monospace;margin:10px;background-color:#fff;padding:8px}.faraday_inspector .request.json{background-color:ghostwhite;border:1px solid silver;padding:10px 20px;margin:20px}.faraday_inspector .request.json .json-key{color:brown}.faraday_inspector .request.json .json-value{color:navy}.faraday_inspector .request.json .json-string{color:olive}.faraday_inspector .prompt,.faraday_inspector .close{cursor:pointer;cursor:hand;font-weight:bold}.faraday_inspector table{width:100%;font-family:'Source Code Pro Light', 'Menlo', monospace;border-spacing:0}.faraday_inspector table .request{display:none}.faraday_inspector table .request.open{display:block}.faraday_inspector table tr.event:hover{cursor:hand;cursor:pointer;background-color:#ffe}
         | 
| @@ -3,7 +3,13 @@ | |
| 3 3 | 
             
              <%= @css %>
         | 
| 4 4 | 
             
            -->
         | 
| 5 5 | 
             
            </style>
         | 
| 6 | 
            -
             | 
| 6 | 
            +
             | 
| 7 | 
            +
            <script type="text/javascript">
         | 
| 8 | 
            +
            //<![CDATA[
         | 
| 9 | 
            +
              <%= @javascript %>
         | 
| 10 | 
            +
            //]]>
         | 
| 11 | 
            +
            </script>
         | 
| 12 | 
            +
             | 
| 7 13 | 
             
            <div class='faraday_inspector minimized'>
         | 
| 8 14 | 
             
              <div class='prompt'>
         | 
| 9 15 | 
             
                <%= Thread.current[:faraday_requests].count %> Faraday Request<%= 's' unless Thread.current[:faraday_requests].to_a.count == 1 %>
         | 
| @@ -12,20 +18,30 @@ | |
| 12 18 | 
             
              <table class='faraday_inspector-requests'>
         | 
| 13 19 | 
             
                <% Thread.current[:faraday_requests].to_a.each do |event| %>
         | 
| 14 20 | 
             
                  <% req = event[:env] %>
         | 
| 21 | 
            +
                  <% request_id = event.hash %>
         | 
| 22 | 
            +
                  <% is_json = req[:body].present? && req[:response_header].try(:[], 'content-type').to_s.include?('json') || req.url.host.include?('json') %>
         | 
| 15 23 | 
             
                  <tr class='event'>
         | 
| 16 24 | 
             
                    <td class='method'><%= req.method.upcase %></td>
         | 
| 17 25 | 
             
                    <td class='host'><%= req.url.host %></td>
         | 
| 18 26 | 
             
                    <td class='path'><%= req.url.path %></td>
         | 
| 19 | 
            -
                    <td class='duration'><%= event[:duration].round( | 
| 27 | 
            +
                    <td class='duration'><%= event[:duration].round(3) %>s</td>
         | 
| 20 28 | 
             
                    <td class='status'><%= req.status %></td>
         | 
| 21 29 | 
             
                  </tr>
         | 
| 22 30 | 
             
                  <tr>
         | 
| 23 31 | 
             
                    <td colspan='5'>
         | 
| 24 | 
            -
                      <div class='request'>
         | 
| 32 | 
            +
                      <div class='request <%= 'json' if is_json %>' id='request-<%= request_id %>'>
         | 
| 25 33 | 
             
                        <% if req[:body].present? %>
         | 
| 26 | 
            -
                          <%  | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 34 | 
            +
                          <% if is_json %>
         | 
| 35 | 
            +
                            <pre></pre>
         | 
| 36 | 
            +
                            <script type="text/javascript">
         | 
| 37 | 
            +
                            //<![CDATA[
         | 
| 38 | 
            +
                              var responseObject = <%= req[:body] %>;
         | 
| 39 | 
            +
                              $('#request-<%= request_id %> pre').html(library.json.prettyPrint(responseObject));
         | 
| 40 | 
            +
                            //]]>
         | 
| 41 | 
            +
                            </script>
         | 
| 42 | 
            +
                          <% else %>
         | 
| 43 | 
            +
                            <%= CGI.escapeHTML(req[:body]).gsub("\n", "<br />") %>
         | 
| 44 | 
            +
                          <% end %>
         | 
| 29 45 | 
             
                        <% else %>
         | 
| 30 46 | 
             
                          (No body for this request.)
         | 
| 31 47 | 
             
                        <% end %>
         | 
| @@ -35,26 +51,3 @@ | |
| 35 51 | 
             
                <% end %>
         | 
| 36 52 | 
             
              </table>
         | 
| 37 53 | 
             
            </div>
         | 
| 38 | 
            -
            <script type="text/javascript">
         | 
| 39 | 
            -
            //<![CDATA[
         | 
| 40 | 
            -
              var closeAllRequests = function() {
         | 
| 41 | 
            -
                $('.faraday_inspector table .request').removeClass('open');
         | 
| 42 | 
            -
              }
         | 
| 43 | 
            -
             | 
| 44 | 
            -
              var showFaradayRequest = function(e) {
         | 
| 45 | 
            -
                var $el = $(this).next().find('.request');
         | 
| 46 | 
            -
                var isOpen = $el.hasClass('open');
         | 
| 47 | 
            -
                closeAllRequests();
         | 
| 48 | 
            -
                if(!isOpen) { $el.addClass('open'); }
         | 
| 49 | 
            -
              }
         | 
| 50 | 
            -
             | 
| 51 | 
            -
              var toggleFardayInspector = function(e) {
         | 
| 52 | 
            -
                closeAllRequests();
         | 
| 53 | 
            -
                $('.faraday_inspector').toggleClass('minimized');
         | 
| 54 | 
            -
                $('.faraday_inspector').toggleClass('open');
         | 
| 55 | 
            -
              };
         | 
| 56 | 
            -
             | 
| 57 | 
            -
              $('.faraday_inspector tr.event').click(showFaradayRequest);
         | 
| 58 | 
            -
              $('.faraday_inspector .prompt, .faraday_inspector .close').click(toggleFardayInspector);
         | 
| 59 | 
            -
            //]]>
         | 
| 60 | 
            -
            </script>
         | 
| @@ -0,0 +1,83 @@ | |
| 1 | 
            +
            // for now, this project depends on jQuery but the frontend is not complex
         | 
| 2 | 
            +
            // and so it could probably be written without jQuery...
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            if (window.jQuery) {
         | 
| 5 | 
            +
              window.jQuery(function(){
         | 
| 6 | 
            +
                var setItem = function(name, value) {
         | 
| 7 | 
            +
                  if(typeof(Storage) !== "undefined") {
         | 
| 8 | 
            +
                    localStorage.setItem(name, value);
         | 
| 9 | 
            +
                  }
         | 
| 10 | 
            +
                };
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                var getItem = function(name, default_value) {
         | 
| 13 | 
            +
                  if(typeof(Storage) !== "undefined") {
         | 
| 14 | 
            +
                    return localStorage[name];
         | 
| 15 | 
            +
                  } else {
         | 
| 16 | 
            +
                    return default_value;
         | 
| 17 | 
            +
                  }
         | 
| 18 | 
            +
                };
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                var closeFaradayInspector = function(e) {
         | 
| 21 | 
            +
                  setItem("rack_faraday_inspector_open", 'false');
         | 
| 22 | 
            +
                  toggleFardayInspector();
         | 
| 23 | 
            +
                };
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                var openFaradayInspector = function(e) {
         | 
| 26 | 
            +
                  setItem("rack_faraday_inspector_open", 'true');
         | 
| 27 | 
            +
                  toggleFardayInspector();
         | 
| 28 | 
            +
                };
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                var closeAllRequests = function() {
         | 
| 31 | 
            +
                  $('.faraday_inspector table .request').removeClass('open');
         | 
| 32 | 
            +
                };
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                var showFaradayRequest = function(e) {
         | 
| 35 | 
            +
                  var $el = $(this).next().find('.request');
         | 
| 36 | 
            +
                  var isOpen = $el.hasClass('open');
         | 
| 37 | 
            +
                  closeAllRequests();
         | 
| 38 | 
            +
                  if (!isOpen) {
         | 
| 39 | 
            +
                    $el.addClass('open');
         | 
| 40 | 
            +
                  }
         | 
| 41 | 
            +
                };
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                var toggleFardayInspector = function(e) {
         | 
| 44 | 
            +
                  closeAllRequests();
         | 
| 45 | 
            +
                  $('.faraday_inspector').toggleClass('minimized');
         | 
| 46 | 
            +
                  $('.faraday_inspector').toggleClass('open');
         | 
| 47 | 
            +
                };
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                if(getItem('rack_faraday_inspector_open', 'false') == 'true') {
         | 
| 50 | 
            +
                  $('.faraday_inspector').removeClass('minimized');
         | 
| 51 | 
            +
                  $('.faraday_inspector').addClass('open');
         | 
| 52 | 
            +
                }
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                $('.faraday_inspector tr.event').click(showFaradayRequest);
         | 
| 55 | 
            +
                $('.faraday_inspector .close').click(closeFaradayInspector);
         | 
| 56 | 
            +
                $('.faraday_inspector .prompt').click(openFaradayInspector);
         | 
| 57 | 
            +
              });
         | 
| 58 | 
            +
            }
         | 
| 59 | 
            +
             | 
| 60 | 
            +
            if (!library)
         | 
| 61 | 
            +
              var library = {};
         | 
| 62 | 
            +
             | 
| 63 | 
            +
            library.json = {
         | 
| 64 | 
            +
              replacer: function(match, pIndent, pKey, pVal, pEnd) {
         | 
| 65 | 
            +
                var key = "<span class='json-item json-key'>";
         | 
| 66 | 
            +
                var val = "<span class='json-item json-value'>";
         | 
| 67 | 
            +
                var str = "<span class='json-item json-string'>";
         | 
| 68 | 
            +
                var r = pIndent || '';
         | 
| 69 | 
            +
                if (pKey)
         | 
| 70 | 
            +
                  r = r + key + pKey.replace(/[": ]/g, '') + '</span>: ';
         | 
| 71 | 
            +
                if (pVal)
         | 
| 72 | 
            +
                  r = r + (pVal[0] == '"' ? str : val) + pVal + '</span>';
         | 
| 73 | 
            +
                var rval = r + (pEnd || '');
         | 
| 74 | 
            +
                return "<span class='json-line'>" + rval + "</span>";
         | 
| 75 | 
            +
              },
         | 
| 76 | 
            +
              prettyPrint: function(obj) {
         | 
| 77 | 
            +
                var jsonLine = /^( *)("[\w]+": )?("[^"]*"|[\w.+-]*)?([,[{])?$/mg;
         | 
| 78 | 
            +
                return JSON.stringify(obj, null, 3)
         | 
| 79 | 
            +
                  .replace(/&/g, '&').replace(/\\"/g, '"')
         | 
| 80 | 
            +
                  .replace(/</g, '<').replace(/>/g, '>')
         | 
| 81 | 
            +
                  .replace(jsonLine, library.json.replacer);
         | 
| 82 | 
            +
              }
         | 
| 83 | 
            +
            };
         | 
| @@ -5,20 +5,26 @@ | |
| 5 5 | 
             
              background-color: #f2f2f2;
         | 
| 6 6 | 
             
              font-size: 12px;
         | 
| 7 7 | 
             
              font-family: 'Helvetica Neue', sans-serif;
         | 
| 8 | 
            -
             | 
| 9 8 | 
             
              &.minimized {
         | 
| 10 9 | 
             
                border: 1px solid #eee;
         | 
| 11 10 | 
             
                border-top-right-radius: 8px;
         | 
| 12 11 | 
             
                padding: 8px;
         | 
| 13 | 
            -
                table { | 
| 14 | 
            -
             | 
| 15 | 
            -
                 | 
| 12 | 
            +
                table {
         | 
| 13 | 
            +
                  display: none;
         | 
| 14 | 
            +
                }
         | 
| 15 | 
            +
                .request {
         | 
| 16 | 
            +
                  display: none;
         | 
| 17 | 
            +
                }
         | 
| 18 | 
            +
                .close {
         | 
| 19 | 
            +
                  display: none;
         | 
| 20 | 
            +
                }
         | 
| 16 21 | 
             
              }
         | 
| 17 | 
            -
             | 
| 18 22 | 
             
              &.open {
         | 
| 19 23 | 
             
                width: 100%;
         | 
| 20 24 | 
             
                border-top: 1px solid #eee;
         | 
| 21 | 
            -
                .prompt { | 
| 25 | 
            +
                .prompt {
         | 
| 26 | 
            +
                  display: none;
         | 
| 27 | 
            +
                }
         | 
| 22 28 | 
             
                .close {
         | 
| 23 29 | 
             
                  display: inline-block;
         | 
| 24 30 | 
             
                  position: absolute;
         | 
| @@ -28,15 +34,30 @@ | |
| 28 34 | 
             
                  font-size: 14px;
         | 
| 29 35 | 
             
                }
         | 
| 30 36 | 
             
              }
         | 
| 31 | 
            -
             | 
| 32 37 | 
             
              .event {
         | 
| 33 | 
            -
                .method { | 
| 34 | 
            -
             | 
| 35 | 
            -
                 | 
| 36 | 
            -
                .host, | 
| 37 | 
            -
                . | 
| 38 | 
            +
                .method {
         | 
| 39 | 
            +
                  font-weight: bold;
         | 
| 40 | 
            +
                }
         | 
| 41 | 
            +
                .host,
         | 
| 42 | 
            +
                .duration,
         | 
| 43 | 
            +
                .status {
         | 
| 44 | 
            +
                  color: #aaa;
         | 
| 45 | 
            +
                }
         | 
| 46 | 
            +
                .host,
         | 
| 47 | 
            +
                .duration,
         | 
| 48 | 
            +
                .status,
         | 
| 49 | 
            +
                .method {
         | 
| 50 | 
            +
                  width: 60px;
         | 
| 51 | 
            +
                }
         | 
| 52 | 
            +
                .host,
         | 
| 53 | 
            +
                .duration,
         | 
| 54 | 
            +
                .status {
         | 
| 55 | 
            +
                  text-align: right;
         | 
| 56 | 
            +
                }
         | 
| 57 | 
            +
                .method {
         | 
| 58 | 
            +
                  text-align: center;
         | 
| 59 | 
            +
                }
         | 
| 38 60 | 
             
              }
         | 
| 39 | 
            -
             | 
| 40 61 | 
             
              .request {
         | 
| 41 62 | 
             
                max-height: 400px;
         | 
| 42 63 | 
             
                text-overflow: scroll;
         | 
| @@ -46,17 +67,32 @@ | |
| 46 67 | 
             
                background-color: #fff;
         | 
| 47 68 | 
             
                // border: 1px solid #aaa;
         | 
| 48 69 | 
             
                padding: 8px;
         | 
| 70 | 
            +
                &.json {
         | 
| 71 | 
            +
                  background-color: ghostwhite;
         | 
| 72 | 
            +
                  border: 1px solid silver;
         | 
| 73 | 
            +
                  padding: 10px 20px;
         | 
| 74 | 
            +
                  margin: 20px;
         | 
| 75 | 
            +
                  .json-key {
         | 
| 76 | 
            +
                    color: brown;
         | 
| 77 | 
            +
                  }
         | 
| 78 | 
            +
                  .json-value {
         | 
| 79 | 
            +
                    color: navy;
         | 
| 80 | 
            +
                  }
         | 
| 81 | 
            +
                  .json-string {
         | 
| 82 | 
            +
                    color: olive;
         | 
| 83 | 
            +
                  }
         | 
| 84 | 
            +
                }
         | 
| 49 85 | 
             
              }
         | 
| 50 | 
            -
             | 
| 51 | 
            -
              . | 
| 86 | 
            +
              .prompt,
         | 
| 87 | 
            +
              .close {
         | 
| 52 88 | 
             
                cursor: pointer;
         | 
| 53 89 | 
             
                cursor: hand;
         | 
| 54 90 | 
             
                font-weight: bold;
         | 
| 55 91 | 
             
              }
         | 
| 56 | 
            -
             | 
| 57 92 | 
             
              table {
         | 
| 58 93 | 
             
                width: 100%;
         | 
| 59 94 | 
             
                font-family: 'Source Code Pro Light', 'Menlo', monospace;
         | 
| 95 | 
            +
                border-spacing: 0;
         | 
| 60 96 | 
             
                .request {
         | 
| 61 97 | 
             
                  display: none;
         | 
| 62 98 | 
             
                }
         | 
| @@ -1,4 +1,18 @@ | |
| 1 1 | 
             
            require 'faraday/inspector'
         | 
| 2 2 | 
             
            require 'rack/faraday_inspector/version'
         | 
| 3 3 | 
             
            require 'rack/faraday_inspector/middleware'
         | 
| 4 | 
            -
            require ' | 
| 4 | 
            +
            require 'active_support/configurable'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            if defined?(::Rails) && ::Rails::VERSION::MAJOR.to_i >= 3
         | 
| 7 | 
            +
              require 'rack/faraday_inspector/railtie'
         | 
| 8 | 
            +
            end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            module Rack
         | 
| 11 | 
            +
              module FaradayInspector
         | 
| 12 | 
            +
                include ActiveSupport::Configurable
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                config.development_mode = false
         | 
| 15 | 
            +
                config.enabled = false
         | 
| 16 | 
            +
                config_accessor :enabled
         | 
| 17 | 
            +
              end
         | 
| 18 | 
            +
            end
         | 
| @@ -5,33 +5,46 @@ module Rack | |
| 5 5 | 
             
                    @app = app
         | 
| 6 6 | 
             
                  end
         | 
| 7 7 |  | 
| 8 | 
            -
                  def  | 
| 8 | 
            +
                  def config
         | 
| 9 | 
            +
                    Rack::FaradayInspector.config
         | 
| 10 | 
            +
                  end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                  def asset_path(*paths)
         | 
| 9 13 | 
             
                    ::File.expand_path(::File.join(::File.dirname(__FILE__), '..', '..', '..', 'assets', *paths))
         | 
| 10 14 | 
             
                  end
         | 
| 11 15 |  | 
| 12 | 
            -
                  def  | 
| 13 | 
            -
                     | 
| 16 | 
            +
                  def compile_css
         | 
| 17 | 
            +
                    path_to_sass = asset_path('sass', 'style.scss')
         | 
| 18 | 
            +
                    @css = Sass::Engine.new(::File.open(path_to_sass).read,
         | 
| 19 | 
            +
                                            cache: true,
         | 
| 20 | 
            +
                                            syntax: :scss,
         | 
| 21 | 
            +
                                            style: :compressed,
         | 
| 22 | 
            +
                                            filename: path_to_sass).render
         | 
| 23 | 
            +
                  end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                  def should_compile_css_at_runtime?
         | 
| 26 | 
            +
                    config.development_mode && defined?(Sass)
         | 
| 14 27 | 
             
                  end
         | 
| 15 28 |  | 
| 16 | 
            -
                  def  | 
| 17 | 
            -
                    ::File.open( | 
| 29 | 
            +
                  def read_compiled_css
         | 
| 30 | 
            +
                    ::File.open(asset_path('css', 'style.css')).read
         | 
| 18 31 | 
             
                  end
         | 
| 19 32 |  | 
| 20 | 
            -
                  def  | 
| 21 | 
            -
                    @ | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
                    }).render
         | 
| 33 | 
            +
                  def set_javascript
         | 
| 34 | 
            +
                    @javascript = ::File.open(asset_path('javascripts', 'inspector.js')).read
         | 
| 35 | 
            +
                  end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                  def set_css
         | 
| 38 | 
            +
                    @css = should_compile_css_at_runtime? ? compile_css : read_compiled_css
         | 
| 27 39 | 
             
                  end
         | 
| 28 40 |  | 
| 29 41 | 
             
                  def template
         | 
| 30 | 
            -
                    ::File.open( | 
| 42 | 
            +
                    ::File.open(asset_path('html', 'inspector.html.erb')).read
         | 
| 31 43 | 
             
                  end
         | 
| 32 44 |  | 
| 33 45 | 
             
                  def content
         | 
| 34 | 
            -
                     | 
| 46 | 
            +
                    set_css
         | 
| 47 | 
            +
                    set_javascript
         | 
| 35 48 | 
             
                    ERB.new(template).result(binding)
         | 
| 36 49 | 
             
                  end
         | 
| 37 50 |  | 
| @@ -39,26 +52,31 @@ module Rack | |
| 39 52 | 
             
                    Thread.current[:faraday_requests] = nil
         | 
| 40 53 | 
             
                  end
         | 
| 41 54 |  | 
| 55 | 
            +
                  def inject_inspector_into(response)
         | 
| 56 | 
            +
                    new_response = []
         | 
| 57 | 
            +
                    response.each do |body|
         | 
| 58 | 
            +
                      partition = body.rpartition('</body>')
         | 
| 59 | 
            +
                      partition[0] += content.to_s
         | 
| 60 | 
            +
                      new_response << partition.join
         | 
| 61 | 
            +
                    end
         | 
| 62 | 
            +
                    new_response
         | 
| 63 | 
            +
                  end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                  def should_inject_inspector?(headers)
         | 
| 66 | 
            +
                    config.enabled && headers['Content-Type'].to_s.include?('text/html')
         | 
| 67 | 
            +
                  end
         | 
| 68 | 
            +
             | 
| 42 69 | 
             
                  def call(env)
         | 
| 43 70 | 
             
                    status, headers, response = @app.call(env)
         | 
| 44 71 |  | 
| 45 | 
            -
                    if headers | 
| 46 | 
            -
                       | 
| 47 | 
            -
                      response. | 
| 48 | 
            -
                         | 
| 49 | 
            -
                        partition[0] += content.to_s
         | 
| 50 | 
            -
                        new_response << partition.join
         | 
| 51 | 
            -
                      end
         | 
| 52 | 
            -
             | 
| 53 | 
            -
                      # Update the content-length
         | 
| 54 | 
            -
                      headers['Content-Length'] = new_response.inject(0) do |len, body|
         | 
| 55 | 
            -
                        len += body.bytesize
         | 
| 72 | 
            +
                    if should_inject_inspector?(headers)
         | 
| 73 | 
            +
                      response = inject_inspector_into(response)
         | 
| 74 | 
            +
                      headers['Content-Length'] = response.inject(0) do |len, body|
         | 
| 75 | 
            +
                        len + body.bytesize
         | 
| 56 76 | 
             
                      end.to_s
         | 
| 57 | 
            -
             | 
| 58 | 
            -
                      [status, headers, new_response]
         | 
| 59 | 
            -
                    else
         | 
| 60 | 
            -
                      [status, headers, response]
         | 
| 61 77 | 
             
                    end
         | 
| 78 | 
            +
             | 
| 79 | 
            +
                    [status, headers, response]
         | 
| 62 80 | 
             
                  ensure
         | 
| 63 81 | 
             
                    clear_requests
         | 
| 64 82 | 
             
                  end
         | 
| @@ -4,22 +4,24 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | |
| 4 4 | 
             
            require 'rack/faraday_inspector/version'
         | 
| 5 5 |  | 
| 6 6 | 
             
            Gem::Specification.new do |spec|
         | 
| 7 | 
            -
              spec.name          =  | 
| 7 | 
            +
              spec.name          = 'rack-faraday_inspector'
         | 
| 8 8 | 
             
              spec.version       = Rack::FaradayInspector::VERSION
         | 
| 9 | 
            -
              spec.authors       = [ | 
| 10 | 
            -
              spec.email         = [ | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
              spec. | 
| 14 | 
            -
              spec.homepage      = "https://github.com/chrisb/rack-faraday_inspector"
         | 
| 15 | 
            -
             | 
| 9 | 
            +
              spec.authors       = ['Chris Bielinski']
         | 
| 10 | 
            +
              spec.email         = ['chris@shadow.io']
         | 
| 11 | 
            +
              spec.summary       = 'A web UI for inspecting your Faraday HTTP requests'
         | 
| 12 | 
            +
              spec.description   = 'Provides the ability to inspect your backend Faraday requests via a web UI.'
         | 
| 13 | 
            +
              spec.homepage      = 'https://github.com/chrisb/rack-faraday_inspector'
         | 
| 16 14 | 
             
              spec.files         = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
         | 
| 17 15 | 
             
              spec.bindir        = "exe"
         | 
| 18 16 | 
             
              spec.executables   = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
         | 
| 19 17 | 
             
              spec.require_paths = ["lib"]
         | 
| 20 18 |  | 
| 21 19 | 
             
              spec.add_dependency 'faraday_middleware'
         | 
| 20 | 
            +
              spec.add_dependency 'awesome_print', '>= 1.6.1'
         | 
| 21 | 
            +
              spec.add_dependency 'activesupport', '>= 4.1.0'
         | 
| 22 22 |  | 
| 23 23 | 
             
              spec.add_development_dependency "bundler", "~> 1.11"
         | 
| 24 24 | 
             
              spec.add_development_dependency "rake", "~> 10.0"
         | 
| 25 | 
            +
              spec.add_development_dependency "rspec", "~> 3.3"
         | 
| 26 | 
            +
              spec.add_development_dependency 'sass'
         | 
| 25 27 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: rack-faraday_inspector
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.2.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Chris Bielinski
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2016-02- | 
| 11 | 
            +
            date: 2016-02-14 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: faraday_middleware
         | 
| @@ -24,6 +24,34 @@ dependencies: | |
| 24 24 | 
             
                - - ">="
         | 
| 25 25 | 
             
                  - !ruby/object:Gem::Version
         | 
| 26 26 | 
             
                    version: '0'
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: awesome_print
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - ">="
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: 1.6.1
         | 
| 34 | 
            +
              type: :runtime
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - ">="
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: 1.6.1
         | 
| 41 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            +
              name: activesupport
         | 
| 43 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 | 
            +
                requirements:
         | 
| 45 | 
            +
                - - ">="
         | 
| 46 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            +
                    version: 4.1.0
         | 
| 48 | 
            +
              type: :runtime
         | 
| 49 | 
            +
              prerelease: false
         | 
| 50 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 | 
            +
                requirements:
         | 
| 52 | 
            +
                - - ">="
         | 
| 53 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            +
                    version: 4.1.0
         | 
| 27 55 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 28 56 | 
             
              name: bundler
         | 
| 29 57 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -52,7 +80,36 @@ dependencies: | |
| 52 80 | 
             
                - - "~>"
         | 
| 53 81 | 
             
                  - !ruby/object:Gem::Version
         | 
| 54 82 | 
             
                    version: '10.0'
         | 
| 55 | 
            -
             | 
| 83 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 84 | 
            +
              name: rspec
         | 
| 85 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 86 | 
            +
                requirements:
         | 
| 87 | 
            +
                - - "~>"
         | 
| 88 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 89 | 
            +
                    version: '3.3'
         | 
| 90 | 
            +
              type: :development
         | 
| 91 | 
            +
              prerelease: false
         | 
| 92 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 93 | 
            +
                requirements:
         | 
| 94 | 
            +
                - - "~>"
         | 
| 95 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 96 | 
            +
                    version: '3.3'
         | 
| 97 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 98 | 
            +
              name: sass
         | 
| 99 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 100 | 
            +
                requirements:
         | 
| 101 | 
            +
                - - ">="
         | 
| 102 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 103 | 
            +
                    version: '0'
         | 
| 104 | 
            +
              type: :development
         | 
| 105 | 
            +
              prerelease: false
         | 
| 106 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 107 | 
            +
                requirements:
         | 
| 108 | 
            +
                - - ">="
         | 
| 109 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 110 | 
            +
                    version: '0'
         | 
| 111 | 
            +
            description: Provides the ability to inspect your backend Faraday requests via a web
         | 
| 112 | 
            +
              UI.
         | 
| 56 113 | 
             
            email:
         | 
| 57 114 | 
             
            - chris@shadow.io
         | 
| 58 115 | 
             
            executables: []
         | 
| @@ -63,12 +120,15 @@ files: | |
| 63 120 | 
             
            - Gemfile
         | 
| 64 121 | 
             
            - README.md
         | 
| 65 122 | 
             
            - Rakefile
         | 
| 123 | 
            +
            - assets/css/style.css
         | 
| 66 124 | 
             
            - assets/html/inspector.html.erb
         | 
| 67 | 
            -
            - assets/ | 
| 125 | 
            +
            - assets/javascripts/inspector.js
         | 
| 126 | 
            +
            - assets/sass/style.scss
         | 
| 68 127 | 
             
            - bin/console
         | 
| 69 128 | 
             
            - bin/setup
         | 
| 70 129 | 
             
            - lib/faraday/inspector.rb
         | 
| 71 130 | 
             
            - lib/rack/faraday_inspector.rb
         | 
| 131 | 
            +
            - lib/rack/faraday_inspector/asset_version.rb
         | 
| 72 132 | 
             
            - lib/rack/faraday_inspector/middleware.rb
         | 
| 73 133 | 
             
            - lib/rack/faraday_inspector/railtie.rb
         | 
| 74 134 | 
             
            - lib/rack/faraday_inspector/version.rb
         | 
| @@ -96,6 +156,6 @@ rubyforge_project: | |
| 96 156 | 
             
            rubygems_version: 2.4.5.1
         | 
| 97 157 | 
             
            signing_key: 
         | 
| 98 158 | 
             
            specification_version: 4
         | 
| 99 | 
            -
            summary:  | 
| 159 | 
            +
            summary: A web UI for inspecting your Faraday HTTP requests
         | 
| 100 160 | 
             
            test_files: []
         | 
| 101 161 | 
             
            has_rdoc: 
         |