The each
API returns the array itself (without modification). You might want to use map
, which returns an array of the results of the block:
[1, 2, 3].each { |x| x*2 }
# => [1, 2, 3]
[1, 2, 3].map { |x| x*2 }
# => [2, 4, 6]
So try (you also missed the location of the curly braces of the hash result in your block):
def update_order
HTTParty.post("APIURL",
:body =>
@all_lines.map do |line|
{
:ProductCode => line.ProductCode,
:Quantity => line.Quantity,
:UnitPrice => line.UnitPrice,
:Pages =>
[
{
:PageNumber => line.PageNumber,
:Assets =>
[
{
:AssetNumber => line.AssetNumber,
:Name => line.Name,
:HiResImage => line.HiResImage,
:CropMode => line.CropMode
}
]
}
]
}
end.to_json,
:headers => { 'Content-Type' => 'application/json' })
end
With 'Lines' wrapper:
HTTParty.post("APIURL",
:body =>
{"Lines" =>
[
@all_lines.map do |line|
{
:ProductCode => line.ProductCode,
:Quantity => line.Quantity,
:UnitPrice => line.UnitPrice,
:Pages =>
[
{
:PageNumber => line.PageNumber,
:Assets =>
[
{
:AssetNumber => line.AssetNumber,
:Name => line.Name,
:HiResImage => line.HiResImage,
:CropMode => line.CropMode
}
]
}
]
}
end]}.to_json,
:headers => { "Content-Type" => "application/json" })