1

I am trying to get a artist profile from Echonest. I need to have a parameter named 'bucket' multiple times in the query string. I am trying to set it with an array with the object that I am passing. Is this possible to pass this in an array?

I have this:

bucket:['biographies', 'images', 'artist_location', 'urls'];

I want this:

bucket=biographies&bucket=images&bucket=artist_location&bucket=urls

Client:

getArtistProfile = function(artistName){
    var params = {
        format:'json',
        bucket:['biographies', 'images', 'artist_location', 'urls'],
        name:artistName
    };

     Meteor.call('getEchoNestData', params, function(error, result) {
        if (error)
            console.warn(error);
        else
            console.log(result);
    });
};

Server Method:

getEchoNestData:function(type, params){
    check(type, String);

    params.api_key = Meteor.settings.echonest.apiKey;

    var result = HTTP.get('http://developer.echonest.com/api/v4/artist/profile' + type, {timeout:5000, params:params});
    return result;
 }
1
  • 1
    i don't think there is a convenient way of doing that. I would just write a for loop or use _.reduce or something. Commented Sep 9, 2014 at 4:50

1 Answer 1

1

I could be misinterpreting your question, but it seems like you are asking how to dynamically build a set of query string parameters. You could have a simple helper like this:

function getParams( arr ) {
    var params = [];

    for ( i = 0; i < arr.length; ++i ) {
        params.push( 'bucket=' + arr[ i ] );
    }

    return params.join( '&' );
}

and pass in your array of param values like this:

var params = getParams( bucket );

http://jsfiddle.net/7vaLcjxs/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.