Class: PaczkomatyInpost::XmlGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/paczkomaty_inpost/xml_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeXmlGenerator

Returns a new instance of XmlGenerator.



8
9
10
# File 'lib/paczkomaty_inpost/xml_generator.rb', line 8

def initialize
  self.xml = Builder::XmlMarkup.new 
end

Instance Attribute Details

#xmlObject

Returns the value of attribute xml.



6
7
8
# File 'lib/paczkomaty_inpost/xml_generator.rb', line 6

def xml
  @xml
end

Instance Method Details

#generate_xml_for_confirm_printout(packcodes, test_printout) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/paczkomaty_inpost/xml_generator.rb', line 57

def generate_xml_for_confirm_printout(packcodes,test_printout)
  xml.paczkomaty do
    xml.testprintout test_printout
    if packcodes.kind_of?(Array)
      packcodes.each {|code| xml.pack { xml.packcode code }}
    else
      xml.pack { xml.packcode packcodes }
    end
  end

  return xml
end

#generate_xml_for_customer(customer_data) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/paczkomaty_inpost/xml_generator.rb', line 70

def generate_xml_for_customer(customer_data)
  xml.paczkomaty do
    xml.customer do
      xml.email customer_data[:email]
      xml.mobileNumber customer_data[:mobile_number] unless customer_data[:mobile_number].nil?
      xml.preferedBoxMachineName customer_data[:prefered_box_machine_name]
      xml.alternativeBoxMachineName customer_data[:alternative_box_machine_name] unless customer_data[:alternative_box_machine_name].nil?
      xml.phoneNum customer_data[:phone_num]
      xml.street customer_data[:street] unless customer_data[:street].nil?
      xml.town customer_data[:town] unless customer_data[:town].nil?
      xml.postCode customer_data[:post_code]
      xml.building customer_data[:building] unless customer_data[:building].nil?
      xml.flat customer_data[:flat] unless customer_data[:flat].nil?
      xml.firstName customer_data[:first_name] unless customer_data[:first_name].nil?
      xml.lastName customer_data[:last_name] unless customer_data[:last_name].nil?
      xml.companyName customer_data[:company_name] unless customer_data[:company_name].nil?
      xml.regon customer_data[:regon] unless customer_data[:regon].nil?
      xml.nip customer_data[:nip] unless customer_data[:nip].nil?
    end
  end

  return xml
end

#generate_xml_for_data_packs(packs_data, auto_labels, self_send) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/paczkomaty_inpost/xml_generator.rb', line 12

def generate_xml_for_data_packs(packs_data, auto_labels, self_send)
  xml.paczkomaty do
    xml.autoLabels auto_labels
    xml.selfSend self_send
    if packs_data.kind_of?(Array)
      packs_data.each {|pack| generate_xml_pack(pack)}
    else
      generate_xml_pack(packs_data)
    end
  end

  return xml
end

#generate_xml_pack(pack) ⇒ Object



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/paczkomaty_inpost/xml_generator.rb', line 26

def generate_xml_pack(pack)
  xml.pack do
    xml.id pack.temp_id
    xml.adreseeEmail pack.adresee_email
    xml.senderEmail pack.sender_email
    xml.phoneNum pack.phone_num
    xml.boxMachineName pack.box_machine_name
    xml.alternativeBoxMachineName pack.alternative_box_machine_name unless pack.alternative_box_machine_name.nil?
    xml.packType pack.pack_type
    xml.customerDelivering(pack.customer_delivering.nil? ? false : pack.customer_delivering)
    xml.insuranceAmount pack.insurance_amount
    xml.onDeliveryAmount pack.on_delivery_amount
    xml.customerRef pack.customer_ref unless pack.customer_ref.nil?
    xml.senderBoxMachineName pack.sender_box_machine_name unless pack.sender_box_machine_name.nil?
    unless pack.sender_address.nil? || pack.sender_address.empty?
      xml.senderAddress do
        xml.name pack.sender_address[:name] unless pack.sender_address[:name]
        xml.surName pack.sender_address[:surname] unless pack.sender_address[:surname]
        xml.email pack.sender_address[:email] unless pack.sender_address[:email]
        xml.phoneNum pack.sender_address[:phone_num] unless pack.sender_address[:phone_num]
        xml.street pack.sender_address[:street] unless pack.sender_address[:street]
        xml.buildingNo pack.sender_address[:building_no] unless pack.sender_address[:building_no]
        xml.flatNo pack.sender_address[:flat_no] unless pack.sender_address[:flat_no]
        xml.town pack.sender_address[:town] unless pack.sender_address[:town]
        xml.zipCode pack.sender_address[:zip_code] unless pack.sender_address[:zip_code]
        xml.province pack.sender_address[:province] unless pack.sender_address[:province]
      end
    end
  end
end