I need to POST an array with HTTParty.
My array is [1, 2, 3]
and the API expects to receive the body to be in the form
"story_hash=1&story_hash=2&story_hash=3"
It's not really important but here's the docs for the API in question.
The solution I have at the moment is:
params = [1, 2, 3].inject('') { |memo, h| memo += "&story_hash=#{h}" }
# Strip the first '&'
params.slice!(0)
options = { body: params }
HTTParty.post('/reader/mark_story_hashes_as_read', options)
Is there a better way (the ideal solution would be a feature of HTTParty that I just don't know of)?
I tried the following method:
options = {
body: { story_hash: [1, 2, 3] }
}
HTTParty.post('/reader/mark_story_hashes_as_read', options)
But that seems to erroneously send a body like this:
"story_hash[]=1&story_hash[]=2&story_hash[]=3"