You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by Kurt Andrews <ku...@gmail.com> on 2015/06/04 18:15:42 UTC

Accessing groovy method parameters as a list

Can I access the method parameters as a list or array?

def sign(method, path, apiKey, userKey, algorithm) {
  // marshal message components into message...
  //   I want to access the method parameters as a list or an array
  //   and create a delimited string from the first 4 elements. Is
  //   there any way to get at the method parameter list directly or
  //   do I need to build the list from the individual parameters?

  def message = ""

  return (hash_hmac(algorithm, apiKey, message).encodeBase64().toString())
}

Re: Accessing groovy method parameters as a list

Posted by Raviteja Lokineni <ra...@gmail.com>.
You can also achieve something similar like this:

/**
 * Sign method
 * @param params Parameters in use: method, path, apiKey, userKey, algorithm
 * @return
 */
def sign(Map params) {
    // marshal message components into message...
    //   I want to access the method parameters as a list or an array
    //   and create a delimited string from the first 4 elements. Is
    //   there any way to get at the method parameter list directly or
    //   do I need to build the list from the individual parameters?

    def message = ""

    return (hash_hmac(params.algorithm, params.apiKey,
message).encodeBase64().toString())
}


On Thu, Jun 4, 2015 at 10:02 PM, Paolo Di Tommaso <paolo.ditommaso@gmail.com
> wrote:

> I think you can achieve something similar using the "methodMissing"
> method, somehow showed in the below link
>
>
> http://stackoverflow.com/questions/15898371/groovy-metaprogramming-intercept-all-method-even-missing-ones
>
>
> Cheers,
> Paolo
>
>
> On Thu, Jun 4, 2015 at 6:15 PM, Kurt Andrews <ku...@gmail.com>
> wrote:
>
>> Can I access the method parameters as a list or array?
>>
>> def sign(method, path, apiKey, userKey, algorithm) {
>>   // marshal message components into message...
>>   //   I want to access the method parameters as a list or an array
>>   //   and create a delimited string from the first 4 elements. Is
>>   //   there any way to get at the method parameter list directly or
>>   //   do I need to build the list from the individual parameters?
>>
>>   def message = ""
>>
>>   return (hash_hmac(algorithm, apiKey, message).encodeBase64().toString())
>> }
>>
>>
>


-- 
*Ravi Teja Lokineni* | Application Developer
ServiceNow | Transform IT

E: raviteja.lokineni@gmail.com

[image: View Raviteja Lokineni's profile on LinkedIn]
<http://in.linkedin.com/in/ravitejalokineni>

Re: Accessing groovy method parameters as a list

Posted by Paolo Di Tommaso <pa...@gmail.com>.
I think you can achieve something similar using the "methodMissing" method,
somehow showed in the below link

http://stackoverflow.com/questions/15898371/groovy-metaprogramming-intercept-all-method-even-missing-ones


Cheers,
Paolo


On Thu, Jun 4, 2015 at 6:15 PM, Kurt Andrews <ku...@gmail.com>
wrote:

> Can I access the method parameters as a list or array?
>
> def sign(method, path, apiKey, userKey, algorithm) {
>   // marshal message components into message...
>   //   I want to access the method parameters as a list or an array
>   //   and create a delimited string from the first 4 elements. Is
>   //   there any way to get at the method parameter list directly or
>   //   do I need to build the list from the individual parameters?
>
>   def message = ""
>
>   return (hash_hmac(algorithm, apiKey, message).encodeBase64().toString())
> }
>
>