Sha256: 2de00cc386b5cfdaa083a9ab676cd2dd426d58ca7705b1e259112fdd8cbb01e7

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

require 'nokogiri'

module FakeChargify
  class Customer
    attr_accessor :id, :first_name, :last_name, :email, :organization, :reference, :created_at, :updated_at
    
    def to_xml
      builder = Nokogiri::XML::Builder.new do |xml|
        xml.customer {
          xml.id_ id
          xml.first_name first_name
          xml.last_name last_name
          xml.email email
          xml.organization organization
          xml.reference reference
          xml.created_at created_at
          xml.updated_at updated_at
        }
      end
      builder.to_xml
    end
    
    def self.from_xml(xml)
      customer = Customer.new
      doc = Nokogiri::XML.parse(xml)
      doc.xpath('//customer').map do |e| 
        customer.id = e.xpath('id').text.to_i
        customer.first_name = e.xpath('first_name').text
        customer.last_name = e.xpath('last_name').text
        customer.email = e.xpath('email').text
        customer.organization = e.xpath('organization').text
        customer.reference = e.xpath('reference').text
        customer.created_at = Time.parse(e.xpath('created_at').text)
        customer.updated_at = Time.parse(e.xpath('updated_at').text)
      end
      customer
    end
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fake_chargify-0.1.0 lib/fake_chargify/customer.rb