Class: ColissimoLabel::FindRelayPoint

Inherits:
Object
  • Object
show all
Defined in:
lib/colissimo_label/find_relay_point.rb

Instance Method Summary collapse

Constructor Details

#initialize(addressee_data, estimated_delivery_date, weight_package) ⇒ FindRelayPoint

Returns a new instance of FindRelayPoint.



7
8
9
10
11
12
# File 'lib/colissimo_label/find_relay_point.rb', line 7

def initialize(addressee_data, estimated_delivery_date, weight_package)
  @addressee_data          = addressee_data
  @estimated_delivery_date = estimated_delivery_date
  @weight_package          = weight_package
  @errors                  = []
end

Instance Method Details

#performObject

Raises:

  • (StandardError)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/colissimo_label/find_relay_point.rb', line 14

def perform
  response      = perform_request
  status        = response.code
  soap_response = response.to_param

  raise StandardError, soap_response if status != 200

  parse         = Nokogiri::XML(soap_response)
  root          = parse.root
  error_code    = root.xpath('//errorCode').text
  error_message = root.xpath('//errorMessage').text

  raise StandardError, error_message if error_code != '0'

  root.xpath('//listePointRetraitAcheminement').map do |point|
    {
      pickup_id:      point.at_xpath('identifiant').text,
      pickup_type:    point.at_xpath('typeDePoint
 ').text,
      name:           point.at_xpath('nom').text,
      address:        [point.at_xpath('adresse1'), point.at_xpath('adresse2'), point.at_xpath('adresse3')].map(&:text).select(&:present?).join(' '),
      postcode:       point.at_xpath('codePostal').text,
      city:           point.at_xpath('localite').text,
      country:        point.at_xpath('libellePays').text,
      country_code:   point.at_xpath('codePays').text,
      latitude:       point.at_xpath('coordGeolocalisationLatitude').text.to_f,
      longitude:      point.at_xpath('coordGeolocalisationLongitude').text.to_f,
      distance:       point.at_xpath('distanceEnMetre').text.to_i,
      max_weight:     point.at_xpath('poidsMaxi').text.to_i,
      parking:        point.at_xpath('parking').text.to_b,
      business_hours: {
        monday:    point.at_xpath('horairesOuvertureLundi').text,
        tuesday:   point.at_xpath('horairesOuvertureMardi').text,
        wednesday: point.at_xpath('horairesOuvertureMercredi').text,
        thursday:  point.at_xpath('horairesOuvertureJeudi').text,
        friday:    point.at_xpath('horairesOuvertureVendredi').text,
        saturday:  point.at_xpath('horairesOuvertureSamedi').text,
        sunday:    point.at_xpath('horairesOuvertureDimanche').text
      }
    }
  end
end