post nested parametes

82 views
Skip to first unread message

luiGi

unread,
Oct 7, 2011, 10:28:50 AM10/7/11
to Typhoeus
Im trying to create a complex model, that recieves multiple nested
parameters.

If I do

Typhoeus::Request.post( "http://localhost:3002/v0/contacts", :params
=> { "contact" => {"first_name" => "lala"]}, :timeout => 200 )

everything works smoothly, but when I try to add a nested model

Typhoeus::Request.post( "http://localhost:3002/v0/contacts", :params
=> { "contact" => { "first_name" => "lala", "contact_attributes" =>
[{"type" => "Telephone", "category" => "home", "value" => "12345",
"public" => 1}]}}, :timeout => 200 )

My contacts service fails to create the contact with this error:

NoMethodError (undefined method `metadata' for #<String:0x9783c38>

It looks like the problem is with the way the service recieves the
nested params:

Parameters: {"contact"=>{"contact_attributes"=>["{\"type\"=>\"Telephone
\", \"category\"=>\"home\", \"value\"=>\"12345\", \"public\"=>1}"],
"first_name"=>"lala"}}

I tested my service to see if the error was there, but it accepts
parameters like the ones I send to typhoeus.

Any suggestions on how to get around this problem?

Thank you!!!
Luis

Bill Doughty

unread,
Oct 7, 2011, 11:54:03 AM10/7/11
to typh...@googlegroups.com
A stacktrace of the exception would be helpful in trouble-shooting your issue.

Sent from my iPhone

> --
> You received this message because you are subscribed to the Google Groups "Typhoeus" group.
> To post to this group, send email to typh...@googlegroups.com.
> To unsubscribe from this group, send email to typhoeus+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/typhoeus?hl=en.
>

luiGi

unread,
Oct 7, 2011, 1:31:31 PM10/7/11
to Typhoeus
Here is everything: https://gist.github.com/1270858
Thanks for looking into it!
Luis

On Oct 7, 12:54 pm, Bill Doughty <billyd....@gmail.com> wrote:
> A stacktrace of the exception would be helpful in trouble-shooting your issue.  
>
> Sent from my iPhone
>

Billy Doughty

unread,
Oct 10, 2011, 10:43:05 AM10/10/11
to typh...@googlegroups.com
Luis,

One thing the strikes me as wrong in your request parameters is that you have the contact_attributes in an array.  Try removing the square brackets from the contact_attributes and just make it a regular hash.

ie.

Typhoeus::Request.post( "http://localhost:3002/v0/contacts", :params => { "contact" => { "first_name" => "lala", "contact_attributes" => {"type" => "Telephone", "category" => "home", "value" => "12345", "public" => 1}}}, :timeout => 200 )
--Bill

luiGi

unread,
Oct 21, 2011, 6:43:26 PM10/21/11
to Typhoeus
Hi Bill!!!
How would you handle a has_many relationship with Typhoeus?
The params are presented in an array because a contact has_many
contact_attributes.
Thank you for looking into it.
Luis

Hans Hasselberg

unread,
Nov 27, 2012, 10:54:38 PM11/27/12
to typh...@googlegroups.com
Hey Nico,

there is an issue explaining your case: https://github.com/typhoeus/typhoeus/issues/201, especially https://github.com/typhoeus/typhoeus/issues/201#issuecomment-7050743. The problem is, that your params are difficult to urlencode.
What you receive in your app is somewhat correct. In order to get what you expect, you could try this solution: https://gist.github.com/3417977. I didn't test that.

--
Hans


On Wednesday, November 28, 2012 at 4:32 AM, Nico Bantatua wrote:

> Hi guys,
>
> I'm currently stumped with this, too.
>
> I have
> response = Typhoeus::Request.new("http://localhost:3000/events/tick.txt", :method => :post, :headers => {:content_type => "application/json", :accept => "application/json"}, :body => @params).run
>
> with @params = {:version=>"0.3.0", :login=>"user", :password=>"password", :items => [{:type=>"Miscellaneous", :length_in_seconds=>"612", :guid=>"22534"}, {:type=>"Work", :length_in_seconds=>"547", :guid=>"43765"}]}
>
> and somehow my app logs receives the :items wrong
> "items"=>{"0"=>{:type=>"Miscellaneous", :length_in_seconds=>"612", :guid=>"22534"}, "1"=>{:type=>"Work", :length_in_seconds=>"547", :guid=>"43765"}}
>
> Thanks in advance!
>
> -Nico
> > > > > > To post to this group, send email to typh...@googlegroups.com (javascript:).
> > > > > > To unsubscribe from this group, send email to
> > > > >
> > > >
> > > > typhoeus+u...@googlegroups.com (javascript:).
> > > > > > For more options, visit this group athttp://
> > > > >
> > > >
> > > > groups.google.com/group/typhoeus?hl=en (http://groups.google.com/group/typhoeus?hl=en).
> > >
> > >
> > > > --
> > > > You received this message because you are subscribed to the Google Groups
> > > > "Typhoeus" group.
> > > > To post to this group, send email to typh...@googlegroups.com (javascript:).
> > > > To unsubscribe from this group, send email to
> > > > typhoeus+u...@googlegroups.com (javascript:).
> > > > For more options, visit this group at
> > > > http://groups.google.com/group/typhoeus?hl=en.
> > >
> >
>
>
> --
> You received this message because you are subscribed to the Google Groups "Typhoeus" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/typhoeus/-/pOczF4zuX_4J.
> To post to this group, send email to typh...@googlegroups.com (mailto:typh...@googlegroups.com).
> To unsubscribe from this group, send email to typhoeus+u...@googlegroups.com (mailto:typhoeus+u...@googlegroups.com).
Reply all
Reply to author
Forward
0 new messages