#ruby #constructor #httparty #attr-accessor
#ruby #конструктор #httparty #attr-accessor
Вопрос:
У меня есть класс, в котором есть конструктор. Конструктор передает параметр в httparty’s default_params
. Однако, когда я анализирую запрос, он не передает параметр. Вот код:
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
Вот результат:
tardis:www$ ruby test.rb
opening connection to console.fm...
opened
<- "GET /api/v2/genres?api_key= HTTP/1.1rnConnection: closernHost: console.fmrnrn"
-> "HTTP/1.1 500 Internal Server Errorrn"
-> "Server: nginx/1.1.0 Phusion Passenger 3.0.9 (mod_rails/mod_rack)rn"
-> "X-Rack-Cache: missrn"
-> "Content-Type: text/html; charset=utf-8rn"
-> "Status: 500rn"
-> "Date: Fri, 28 Oct 2011 00:00:43 GMTrn"
-> "X-Runtime: 0.375296rn"
-> "Connection: closern"
-> "X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.7rn"
-> "Content-Length: 9309rn"
-> "rn"
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>ntt<meta charset="utf-8"/>nttn <!-- Always force latest IE rendering engine (even in intranet) amp; Chrome Frame -->n <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">nn <title>Console // Drunk DJ Error</title>nn <!-- 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 amp; feature detects -->n <script src="modernizr-1.7.min.js"></script>n n <style>n /*tLess Framework 4n thttp://lessframework.comn tby Joni Korpin tLicense: http://creativecommons.org/licenses/MIT/t*/nn /*tResetsn t------t*/nn"
-> " 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 }nn article, aside, canvas, figure, figure img, figcaption, hgroup,n footer, header, nav, section, audio, video {n tdisplay: block;n }nn a img {border: 0;}nn /*tTypography presetsn t------------------t*/nn .gigantic {n tfont-size: 110px;n tline-height: 120px;n tletter-spacing: -2px;n }nn .huge, h1 {n tfont-size: 68px;n tline-height: 72px;n tletter-spacing: -3px;n tfont-weight:900;n }nn .large, h2 {n tfont-size: 42px;n tline-height: 48px;n tfont-weight:700;n }nn .bigger, h3 {n tfont-size: 26px;n tline-height: 36px;n tfont-weight:500;n }nn .big, h4 {n tfont-size: 22px;n tline-height: 30px;n }nn body {n tfont: 16px/24px;n }nn .small, small {n tfont-size: 13px;n tline-height: 18px;n }nn h1, p {n tmargin-bottom: .5em;n }nn /* Selection colours (easy to forget) */nn ::selection t t{background: rgb(0,255,0);}n ::-moz-selection t{background: rgb(0,255,0);}n img::selection tt{background: transparent;}n img::-moz-selectiont{background: transparent;}n body {-webkit-tap-highlight-color: rgb(0,255,0);}nnnn /*ttDefault Layout: 992px. n ttGutters: 24px.n ttOuter margins: 48px.n ttLeftover space for scrollbars @1024px: 32px.n -------------------------------------------------------------------------------n cols 1 2 3 4 5 6 7 8 9 10n px 68 160 252 344 436 528 620 712 804 896 */nn 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 nn 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 }nn .no-rgba article{n tbackground: #333;n }nn .wf-active article {n tvisibility: visible;n }nn 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 }nn a:hover {n tborder-bottom:2px solid rgba(255,255,255,.6);n }nn section ul {n tlist-style-type:none;n }nn section ul li {n tfloat:left;n }nn 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 }nn section ul li img:hover {n topacity:.9;n t-webkit-transform: rotate(25deg);n t-moz-transform: rotate(25deg);n }nn hr {n tclear:both;n }nn /*ttTablet Layout: 768px.n ttGutters: 24px.n ttOuter margins: 28px.n ttInherits styles from: Default Layout.n -----------------------------------------------------------------n cols 1 2 3 4 5 6 7 8n px 68 160 252 344 436 528 620 712 */nn @media only screen and (min-width: 768px) and (max-wi"
-> "dth: 991px) {nn tbody {n ttpadding: 48px 28px 60px;n t}nn tarticle {n ttpadding: 48px 28px 60px;n t}n }nn /*ttMobile Layout: 320px.n ttGutters: 24px.n ttOuter margins: 34px.n ttInherits styles from: Default Layout.n ---------------------------------------------n cols 1 2 3n px 68 160 252 */nn @media only screen and (max-width: 767px) {nn tbody {n ttpadding: 0;n t}nn tarticle {n ttwidth: 252px;n ttpadding: 48px 34px 60px;n t}nn t#hellobar-wrapper {n ttvisibility: hidden;n t}n }n </style>nt</head>nn <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 ttt<h1>Don't Drink and DJ.</h1>n ttt<h2>This PSA brought to you by our broken server.</h2>n ttt<br>n tt <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) amp; 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 amp; 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>
Почему он не передает ключ?
Ответ №1:
Я смог использовать следующее:
def initialize(key)
self.class.default_params :api_key => key
end