I need to get some information from a delivery company who is using soap to get the list of delivery points. I finished my classes to call and execute the soap request and this is the format of the response :
{
:error_message=> "Code retour OK",
:liste_point_retrait =>
[
{
:horaires_ouverture_dimanche => "00:00-00:00 00:00-00:00",
:poids_maxi => "20000",
:conges_partiel => false,
:horaires_ouverture_vendredi => "09:00-12:00 14:30-18:00",
:acces_personne_mobilite_reduite => false,
:horaires_ouverture_jeudi => "09:00-12:00 14:30-17:30",
:nom => "BUREAU DE POSTE SAINT LEU D ESSERENT BP"
},
{
:horaires_ouverture_dimanche => "00:00-00:00 00:00-00:00",
:poids_maxi => "20000",
:conges_partiel => false,
:horaires_ouverture_vendredi => "09:00-12:00 14:00- 17:00",
:acces_personne_mobilite_reduite => true,
:horaires_ouverture_jeudi => "09:00-12:00 14:00-17:00",
:nom => "BUREAU DE POSTE PRECY SUR OISE BP"
},
{
:horaires_ouverture_dimanche => "00:00-00:00 00:00-00:00",
:poids_maxi=> "20000",
:conges_partiel => false,
:horaires_ouverture_vendredi => "08:30-12:00 14:30-17:00",
:acces_personne_mobilite_reduite => false,
:horaires_ouverture_jeudi => "08:30-12:00 14:30-17:00",
:nom => "BUREAU DE POSTE SAINT MAXIMIN BP"
}
],
:error_code=> "0",
:qualite_reponse=> "1",
:ws_request_id => "01587849465dc81b5eb19996cdd5d1cae4ead7766316f12e4fbfa6e86037caae"
}
The problem now is that I don’t like the way I currently get the information to display it in my views, for example if @points contains this hash I use this in my code:
<% @points[:liste_point_retrait].each do |point| %>
<%= point[:nom] %>
<% end %>
Is there a better way to handle this response? I would like to have the possibilty to do something like this :
<% @points.each do |point| %>
<%= point.name %>
<% end %>
If you only want the data inside of the
:liste_point_retraitkey then only use that key?:Then you can continue to traverse this with
If you would rather use
point.nomoverpoint[:nom]then you can create anOpenStructfrom each Hash element. That is:I see you have
namevsnomin your example and I’m not sure if that’s intentional or not. If so, you need to translate all of these keys yourself.