Question

I have a class that has a constructor. The constructor passes a param to HTTParty's default_params. However, when I analyze the request, it isn't passing the param. Here's the code:

module Dance
  class Client
    include HTTParty

    attr_accessor :api

    base_uri 'console.fm/api/v2'
    default_params :api_key => @api
    debug_output $stderr

    def initialize(key)
      @api = key
    end

    def artists
      Artists
    end

    def genres
      Genres
    end

    def users
      Users
    end

    def tracks
      Tracks
    end

  end

end

Here is the output:

tardis:www$ ruby test.rb 
opening connection to console.fm...
opened
<- "GET /api/v2/genres?api_key= HTTP/1.1\r\nConnection: close\r\nHost: console.fm\r\n\r\n"
-> "HTTP/1.1 500 Internal Server Error\r\n"
-> "Server: nginx/1.1.0 + Phusion Passenger 3.0.9 (mod_rails/mod_rack)\r\n"
-> "X-Rack-Cache: miss\r\n"
-> "Content-Type: text/html; charset=utf-8\r\n"
-> "Status: 500\r\n"
-> "Date: Fri, 28 Oct 2011 00:00:43 GMT\r\n"
-> "X-Runtime: 0.375296\r\n"
-> "Connection: close\r\n"
-> "X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.7\r\n"
-> "Content-Length: 9309\r\n"
-> "\r\n"
reading 9309 bytes...
-> "<!doctype html>\n<!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ -->\n<!--[if lt IE 7 ]> <html class=\"no-js ie6\" lang=\"en\"> <![endif]-->\n<!--[if IE 7 ]> <html class=\"no-js ie7\" lang=\"en\"> <![endif]-->\n<!--[if IE 8 ]> <html class=\"no-js ie8\" lang=\"en\"> <![endif]-->\n<!--[if (gte IE 9)|!(IE)]><!--> <html class=\"no-js\" lang=\"en\"> <!--<![endif]-->\n  \n  <head>\n\t\t<meta charset=\"utf-8\"/>\n\t\t\n    <!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame -->\n    <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge,chrome=1\">\n\n    <title>Console // Drunk DJ Error</title>\n\n    <!-- Mobile viewport optimized: j.mp/bplateviewport -->\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    \n    <!-- All JavaScript at the bottom, except for Modernizr which enables HTML5 elements & feature detects -->\n    <script src=\"modernizr-1.7.min.js\"></script>\n    \n    <style>\n      /*\tLess Framework 4\n      \thttp://lessframework.com\n      \tby Joni Korpi\n      \tLicense: http://creativecommons.org/licenses/MIT/\t*/\n\n      /*\tResets\n      \t------\t*/\n\n"
-> "      html, body, div, span, object, iframe, h1, h2, h3, h4, h5, h6, \n      p, blockquote, pre, a, abbr, address, cite, code, del, dfn, em, \n      img, ins, kbd, q, samp, small, strong, sub, sup, var, b, i, hr, \n      dl, dt, dd, ol, ul, li, fieldset, form, label, legend, \n      table, caption, tbody, tfoot, thead, tr, th, td,\n      article, aside, canvas, details, figure, figcaption, hgroup, \n      menu, footer, header, nav, section, summary, time, mark, audio, video {\n      \tmargin: 0;\n      \tpadding: 0;\n      \tborder: 0;\n      }\n\n      article, aside, canvas, figure, figure img, figcaption, hgroup,\n      footer, header, nav, section, audio, video {\n      \tdisplay: block;\n      }\n\n      a img {border: 0;}\n\n      /*\tTypography presets\n      \t------------------\t*/\n\n      .gigantic {\n      \tfont-size: 110px;\n      \tline-height: 120px;\n      \tletter-spacing: -2px;\n      }\n\n      .huge, h1 {\n      \tfont-size: 68px;\n      \tline-height: 72px;\n      \tletter-spacing: -3px;\n      \tfont-weight:900;\n      }\n\n      .large, h2 {\n      \tfont-size: 42px;\n      \tline-height: 48px;\n      \tfont-weight:700;\n      }\n\n      .bigger, h3 {\n      \tfont-size: 26px;\n      \tline-height: 36px;\n      \tfont-weight:500;\n      }\n\n      .big, h4 {\n      \tfont-size: 22px;\n      \tline-height: 30px;\n      }\n\n      body {\n      \tfont: 16px/24px;\n      }\n\n      .small, small {\n      \tfont-size: 13px;\n      \tline-height: 18px;\n      }\n\n      h1, p {\n      \tmargin-bottom: .5em;\n      }\n\n      /* Selection colours (easy to forget) */\n\n      ::selection \t \t{background: rgb(0,255,0);}\n      ::-moz-selection \t{background: rgb(0,255,0);}\n      img::selection \t\t{background: transparent;}\n      img::-moz-selection\t{background: transparent;}\n      body {-webkit-tap-highlight-color: rgb(0,255,0);}\n\n\n\n      /*\t\tDefault Layout: 992px. \n      \t\tGutters: 24px.\n      \t\tOuter margins: 48px.\n      \t\tLeftover space for scrollbars @1024px: 32px.\n      -------------------------------------------------------------------------------\n      cols    1     2      3      4      5      6      7      8      9      10\n      px      68    160    252    344    436    528    620    712    804    896    */\n\n      body {\n      \tbackground: #333;\n      \tcolor: #fff;\n      \tfont-family: \"proxima-nova-1\",\"proxima-nova-2\", \"Helvetica Nueue\", helvetica, sans-serif;\n      \t-webkit-font-smoothing: antialiased;\n      \t-webkit-text-size-adjust: 100%; /* Stops Mobile Safari from auto-adjusting font-sizes */\n      \tpadding: 72px 48px 84px;\n      \tbackground: url(http://s3.amazonaws.com/consolefm/500.jpg) repeat center center fixed;\n        -webkit-background-size: cover;\n        -moz-background-size: cover;\n        -o-background-size: cover;\n        background-size: cover;\n      }\n      \n\n      article {\n        margin:0 auto;\n      \tpadding: 72px 48px 84px;\n      \tvisibility: hidden;\n      \ttext-shadow:1px 1px 8px #000000;\n  "
-> "    \ttext-align:center;\n      }\n\n      .no-rgba article{\n      \tbackground: #333;\n      }\n\n      .wf-active article {\n      \tvisibility: visible;\n      }\n\n      a {\n      \tfont-weight:bold;\n      \ttext-decoration:none;\n      \tcolor:#fff;\n      \tborder-bottom:2px solid rgba(255,255,255,.3);\n      \t-webkit-transition: all .33s ease;\n      \t-moz-transition: all .33s ease;\n      \t-o-transition: all .33s ease;\n      \ttransition: all .33s ease;\n      }\n\n      a:hover {\n      \tborder-bottom:2px solid rgba(255,255,255,.6);\n      }\n\n      section ul {\n      \tlist-style-type:none;\n      }\n\n      section ul li {\n      \tfloat:left;\n      }\n\n      section ul li img {\n      \topacity:.6;\n      \tmargin:12px 12px 0 0;\n      \t-webkit-transition: all .33s ease;\n      \t-moz-transition: all .33s ease;\n      \t-o-transition: all .33s ease;\n      \ttransition: all .33s ease;\n      }\n\n      section ul li img:hover {\n      \topacity:.9;\n      \t-webkit-transform: rotate(25deg);\n      \t-moz-transform: rotate(25deg);\n      }\n\n      hr {\n      \tclear:both;\n      }\n\n      /*\t\tTablet Layout: 768px.\n      \t\tGutters: 24px.\n      \t\tOuter margins: 28px.\n      \t\tInherits styles from: Default Layout.\n      -----------------------------------------------------------------\n      cols    1     2      3      4      5      6      7      8\n      px      68    160    252    344    436    528    620    712    */\n\n      @media only screen and (min-width: 768px) and (max-wi"
-> "dth: 991px) {\n\n      \tbody {\n      \t\tpadding: 48px 28px 60px;\n      \t}\n\n      \tarticle {\n      \t\tpadding: 48px 28px 60px;\n      \t}\n      }\n\n      /*\t\tMobile Layout: 320px.\n      \t\tGutters: 24px.\n      \t\tOuter margins: 34px.\n      \t\tInherits styles from: Default Layout.\n      ---------------------------------------------\n      cols    1     2      3\n      px      68    160    252    */\n\n      @media only screen and (max-width: 767px) {\n\n      \tbody {\n      \t\tpadding: 0;\n      \t}\n\n      \tarticle {\n      \t\twidth: 252px;\n      \t\tpadding: 48px 34px 60px;\n      \t}\n\n      \t#hellobar-wrapper {\n      \t\tvisibility: hidden;\n      \t}\n      }\n    </style>\n\t</head>\n\n  <body> \n    \n                               <!--    \n                               //|                              ,|\n                             //,/                             -~ |\n                           // / |                         _-~   /  ,\n                         /'/ / /                       _-~   _/_-~ |\n                        ( ( / /'                   _ -~     _-~ ,/'\n                         \\~\\/'/|             ____~~____\\ _-~  _/,\n                 ,,)))))));, \\/~-_     ____~~  __~~  __/~  _-~ /\n              __))))))))))))));,>/\\   /        ____~~  \\-~~ _-~\n             -\\(((((''''(((((((( >~\\/     __~~   ____~' _-~ ~|\n    __==//////((''  .     `)))))), /     _____-~~  ~~\\~~____~ \n            ))| @    ;-.     (((((/           _____~~'~~/\n            ("
-> " `|    /  )      )))/      ~~~~~__\\____-~~____~~___\n               |   |   |       (/      __-~~~/______-~~  ,;::'  \\         ,\n               o_);   ;        /      ____~~/           \\,-~~~\\  |       /|\n                     ;        (      __-~~/         `:::|      |;|      < >\n                    |   _      `____~~~~'      /      `:|       \\;\\_____// \n              ______/\\/~    |                 /        /         ~______~\n            /~;;.____/;;'  /          _______(   `;;;/               \n           / //  _;______;'_______~~~~~    |;;/\\    /          \n          //  | |                        /  |  \\;;,\\              \n         (<_  | ;                      /',/_____'  _>\n          \\_| ||_                     //~;~~~~~~~~~ \n              `\\_|                   (,~~ \n                                      \\~\\ \n                                       -->  \n        \n    <article>\n  \t\t\t<h1>Don't Drink and DJ.</h1>\n  \t\t\t<h2>This PSA brought to you by our broken server.</h2>\n  \t\t\t<br>\n  \t\t  <h3>Sorry about that, go back <a href=\"http://console.fm\" title=\"Console.fm\">home</a> or <a href=\"http://twitter.com/consolefm\" title=\"Contact Console.fm\">contact us</a> about what's not working.</h3>\n    </article>\n    \n    <!-- Proxima Nova provided by Typekit -->\n    <script src=\"http://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js\"></script>\n    <script>\n      WebFont.load({\n        typekit: {\n          id: 'fbv1rsb'\n        }\n      "
-> "});\n    </script>\n      \n    <!-- jQuery from Google CDN and local fallback -->\n    <script src=\"//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.js\"></script>\n    <script>window.jQuery || document.write(\"<script src='javascripts/jquery-1.5.1.min.js'>\\x3C/script>\")</script>\n    \n    <!--[if lt IE 7 ]>\n      <script src=\"js/libs/dd_belatedpng.js\"></script>\n      <script>DD_belatedPNG.fix(\"img, .png_bg\"); // Fix any <img> or .png_bg bg-images. Also, please read goo.gl/mZiyb </script>\n    <![endif]-->\n    \n    <!-- mathiasbynens.be/notes/async-analytics-snippet Change UA-XXXXX-X to be your site's ID -->\n    <script>\n      var _gaq=[[\"_setAccount\",\"UA-10020436-28\"],[\"_trackPageview\"]];\n      (function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.async=1;\n      g.src=(\"https:\"==location.protocol?\"//ssl\":\"//www\")+\".google-analytics.com/ga.js\";\n      s.parentNode.insertBefore(g,s)}(document,\"script\"));\n    </script>\n  </body>\n  \n</html>"
read 9309 bytes
Conn close
#<Net::HTTPInternalServerError:0x9f85ecc>
<!doctype html>
<!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ -->
<!--[if lt IE 7 ]> <html class="no-js ie6" lang="en"> <![endif]-->
<!--[if IE 7 ]> <html class="no-js ie7" lang="en"> <![endif]-->
<!--[if IE 8 ]> <html class="no-js ie8" lang="en"> <![endif]-->
<!--[if (gte IE 9)|!(IE)]><!--> <html class="no-js" lang="en"> <!--<![endif]-->

  <head>
        <meta charset="utf-8"/>

    <!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <title>Console // Drunk DJ Error</title>

    <!-- Mobile viewport optimized: j.mp/bplateviewport -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <!-- All JavaScript at the bottom, except for Modernizr which enables HTML5 elements & feature detects -->
    <script src="modernizr-1.7.min.js"></script>

    <style>
      /*    Less Framework 4
        http://lessframework.com
        by Joni Korpi
        License: http://creativecommons.org/licenses/MIT/   */

      /*    Resets
        ------  */

      html, body, div, span, object, iframe, h1, h2, h3, h4, h5, h6, 
      p, blockquote, pre, a, abbr, address, cite, code, del, dfn, em, 
      img, ins, kbd, q, samp, small, strong, sub, sup, var, b, i, hr, 
      dl, dt, dd, ol, ul, li, fieldset, form, label, legend, 
      table, caption, tbody, tfoot, thead, tr, th, td,
      article, aside, canvas, details, figure, figcaption, hgroup, 
      menu, footer, header, nav, section, summary, time, mark, audio, video {
        margin: 0;
        padding: 0;
        border: 0;
      }

      article, aside, canvas, figure, figure img, figcaption, hgroup,
      footer, header, nav, section, audio, video {
        display: block;
      }

      a img {border: 0;}

      /*    Typography presets
        ------------------  */

      .gigantic {
        font-size: 110px;
        line-height: 120px;
        letter-spacing: -2px;
      }

      .huge, h1 {
        font-size: 68px;
        line-height: 72px;
        letter-spacing: -3px;
        font-weight:900;
      }

      .large, h2 {
        font-size: 42px;
        line-height: 48px;
        font-weight:700;
      }

      .bigger, h3 {
        font-size: 26px;
        line-height: 36px;
        font-weight:500;
      }

      .big, h4 {
        font-size: 22px;
        line-height: 30px;
      }

      body {
        font: 16px/24px;
      }

      .small, small {
        font-size: 13px;
        line-height: 18px;
      }

      h1, p {
        margin-bottom: .5em;
      }

      /* Selection colours (easy to forget) */

      ::selection       {background: rgb(0,255,0);}
      ::-moz-selection  {background: rgb(0,255,0);}
      img::selection        {background: transparent;}
      img::-moz-selection   {background: transparent;}
      body {-webkit-tap-highlight-color: rgb(0,255,0);}



      /*        Default Layout: 992px. 
            Gutters: 24px.
            Outer margins: 48px.
            Leftover space for scrollbars @1024px: 32px.
      -------------------------------------------------------------------------------
      cols    1     2      3      4      5      6      7      8      9      10
      px      68    160    252    344    436    528    620    712    804    896    */

      body {
        background: #333;
        color: #fff;
        font-family: "proxima-nova-1","proxima-nova-2", "Helvetica Nueue", helvetica, sans-serif;
        -webkit-font-smoothing: antialiased;
        -webkit-text-size-adjust: 100%; /* Stops Mobile Safari from auto-adjusting font-sizes */
        padding: 72px 48px 84px;
        background: url(http://s3.amazonaws.com/consolefm/500.jpg) repeat center center fixed;
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-size: cover;
      }


      article {
        margin:0 auto;
        padding: 72px 48px 84px;
        visibility: hidden;
        text-shadow:1px 1px 8px #000000;
        text-align:center;
      }

      .no-rgba article{
        background: #333;
      }

      .wf-active article {
        visibility: visible;
      }

      a {
        font-weight:bold;
        text-decoration:none;
        color:#fff;
        border-bottom:2px solid rgba(255,255,255,.3);
        -webkit-transition: all .33s ease;
        -moz-transition: all .33s ease;
        -o-transition: all .33s ease;
        transition: all .33s ease;
      }

      a:hover {
        border-bottom:2px solid rgba(255,255,255,.6);
      }

      section ul {
        list-style-type:none;
      }

      section ul li {
        float:left;
      }

      section ul li img {
        opacity:.6;
        margin:12px 12px 0 0;
        -webkit-transition: all .33s ease;
        -moz-transition: all .33s ease;
        -o-transition: all .33s ease;
        transition: all .33s ease;
      }

      section ul li img:hover {
        opacity:.9;
        -webkit-transform: rotate(25deg);
        -moz-transform: rotate(25deg);
      }

      hr {
        clear:both;
      }

      /*        Tablet Layout: 768px.
            Gutters: 24px.
            Outer margins: 28px.
            Inherits styles from: Default Layout.
      -----------------------------------------------------------------
      cols    1     2      3      4      5      6      7      8
      px      68    160    252    344    436    528    620    712    */

      @media only screen and (min-width: 768px) and (max-width: 991px) {

        body {
            padding: 48px 28px 60px;
        }

        article {
            padding: 48px 28px 60px;
        }
      }

      /*        Mobile Layout: 320px.
            Gutters: 24px.
            Outer margins: 34px.
            Inherits styles from: Default Layout.
      ---------------------------------------------
      cols    1     2      3
      px      68    160    252    */

      @media only screen and (max-width: 767px) {

        body {
            padding: 0;
        }

        article {
            width: 252px;
            padding: 48px 34px 60px;
        }

        #hellobar-wrapper {
            visibility: hidden;
        }
      }
    </style>
    </head>

  <body> 

                               <!--    
                               //|                              ,|
                             //,/                             -~ |
                           // / |                         _-~   /  ,
                         /'/ / /                       _-~   _/_-~ |
                        ( ( / /'                   _ -~     _-~ ,/'
                         \~\/'/|             ____~~____\ _-~  _/,
                 ,,)))))));, \/~-_     ____~~  __~~  __/~  _-~ /
              __))))))))))))));,>/\   /        ____~~  \-~~ _-~
             -\(((((''''(((((((( >~\/     __~~   ____~' _-~ ~|
    __==//////((''  .     `)))))), /     _____-~~  ~~\~~____~ 
            ))| @    ;-.     (((((/           _____~~'~~/
            ( `|    /  )      )))/      ~~~~~__\____-~~____~~___
               |   |   |       (/      __-~~~/______-~~  ,;::'  \         ,
               o_);   ;        /      ____~~/           \,-~~~\  |       /|
                     ;        (      __-~~/         `:::|      |;|      < >
                    |   _      `____~~~~'      /      `:|       \;\_____// 
              ______/\/~    |                 /        /         ~______~
            /~;;.____/;;'  /          _______(   `;;;/               
           / //  _;______;'_______~~~~~    |;;/\    /          
          //  | |                        /  |  \;;,\              
         (<_  | ;                      /',/_____'  _>
          \_| ||_                     //~;~~~~~~~~~ 
              `\_|                   (,~~ 
                                      \~\ 
                                       -->  

    <article>
            <h1>Don't Drink and DJ.</h1>
            <h2>This PSA brought to you by our broken server.</h2>
            <br>
          <h3>Sorry about that, go back <a href="http://console.fm" title="Console.fm">home</a> or <a href="http://twitter.com/consolefm" title="Contact Console.fm">contact us</a> about what's not working.</h3>
    </article>

    <!-- Proxima Nova provided by Typekit -->
    <script src="http://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js"></script>
    <script>
      WebFont.load({
        typekit: {
          id: 'fbv1rsb'
        }
      });
    </script>

    <!-- jQuery from Google CDN and local fallback -->
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.js"></script>
    <script>window.jQuery || document.write("<script src='javascripts/jquery-1.5.1.min.js'>\x3C/script>")</script>

    <!--[if lt IE 7 ]>
      <script src="js/libs/dd_belatedpng.js"></script>
      <script>DD_belatedPNG.fix("img, .png_bg"); // Fix any <img> or .png_bg bg-images. Also, please read goo.gl/mZiyb </script>
    <![endif]-->

    <!-- mathiasbynens.be/notes/async-analytics-snippet Change UA-XXXXX-X to be your site's ID -->
    <script>
      var _gaq=[["_setAccount","UA-10020436-28"],["_trackPageview"]];
      (function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.async=1;
      g.src=("https:"==location.protocol?"//ssl":"//www")+".google-analytics.com/ga.js";
      s.parentNode.insertBefore(g,s)}(document,"script"));
    </script>
  </body>

</html>

Why is it not passing the key?

Was it helpful?

Solution

I was able to use the following:

def initialize(key)
  self.class.default_params :api_key => key
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top