Class: FakeChargify::Subscription
- Inherits:
-
Object
- Object
- FakeChargify::Subscription
- Defined in:
- lib/fake_chargify/subscription.rb
Instance Attribute Summary collapse
-
#activated_at ⇒ Object
Returns the value of attribute activated_at.
-
#balance_in_cents ⇒ Object
Returns the value of attribute balance_in_cents.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#credit_card ⇒ Object
Returns the value of attribute credit_card.
-
#current_period_ends_at ⇒ Object
Returns the value of attribute current_period_ends_at.
-
#current_period_started_at ⇒ Object
Returns the value of attribute current_period_started_at.
-
#customer ⇒ Object
Returns the value of attribute customer.
-
#expires_at ⇒ Object
Returns the value of attribute expires_at.
-
#id ⇒ Object
Returns the value of attribute id.
-
#product ⇒ Object
Returns the value of attribute product.
-
#state ⇒ Object
Returns the value of attribute state.
-
#trial_ended_at ⇒ Object
Returns the value of attribute trial_ended_at.
-
#trial_started_at ⇒ Object
Returns the value of attribute trial_started_at.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#activated_at ⇒ Object
Returns the value of attribute activated_at.
7 8 9 |
# File 'lib/fake_chargify/subscription.rb', line 7 def activated_at @activated_at end |
#balance_in_cents ⇒ Object
Returns the value of attribute balance_in_cents.
7 8 9 |
# File 'lib/fake_chargify/subscription.rb', line 7 def balance_in_cents @balance_in_cents end |
#created_at ⇒ Object
Returns the value of attribute created_at.
7 8 9 |
# File 'lib/fake_chargify/subscription.rb', line 7 def created_at @created_at end |
#credit_card ⇒ Object
Returns the value of attribute credit_card.
7 8 9 |
# File 'lib/fake_chargify/subscription.rb', line 7 def credit_card @credit_card end |
#current_period_ends_at ⇒ Object
Returns the value of attribute current_period_ends_at.
7 8 9 |
# File 'lib/fake_chargify/subscription.rb', line 7 def current_period_ends_at @current_period_ends_at end |
#current_period_started_at ⇒ Object
Returns the value of attribute current_period_started_at.
7 8 9 |
# File 'lib/fake_chargify/subscription.rb', line 7 def current_period_started_at @current_period_started_at end |
#customer ⇒ Object
Returns the value of attribute customer.
7 8 9 |
# File 'lib/fake_chargify/subscription.rb', line 7 def customer @customer end |
#expires_at ⇒ Object
Returns the value of attribute expires_at.
7 8 9 |
# File 'lib/fake_chargify/subscription.rb', line 7 def expires_at @expires_at end |
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'lib/fake_chargify/subscription.rb', line 7 def id @id end |
#product ⇒ Object
Returns the value of attribute product.
7 8 9 |
# File 'lib/fake_chargify/subscription.rb', line 7 def product @product end |
#state ⇒ Object
Returns the value of attribute state.
7 8 9 |
# File 'lib/fake_chargify/subscription.rb', line 7 def state @state end |
#trial_ended_at ⇒ Object
Returns the value of attribute trial_ended_at.
7 8 9 |
# File 'lib/fake_chargify/subscription.rb', line 7 def trial_ended_at @trial_ended_at end |
#trial_started_at ⇒ Object
Returns the value of attribute trial_started_at.
7 8 9 |
# File 'lib/fake_chargify/subscription.rb', line 7 def trial_started_at @trial_started_at end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
7 8 9 |
# File 'lib/fake_chargify/subscription.rb', line 7 def updated_at @updated_at end |
Class Method Details
.from_xml(xml) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/fake_chargify/subscription.rb', line 33 def self.from_xml(xml) subscription = Subscription.new doc = Nokogiri::XML.parse(xml) doc.xpath('//subscription').map do |e| subscription.id = e.xpath('id').text.to_i subscription.balance_in_cents = e.xpath('balance_in_cents').text.to_i unless e.xpath('product_handle').empty? subscription.product = Product.new subscription.product.handle = e.xpath('product_handle').text end if e.xpath('customer_reference').empty? e.xpath('customer_attributes').map do |c| subscription.customer = Customer.new subscription.customer.first_name = c.xpath('first_name').text subscription.customer.last_name = c.xpath('last_name').text subscription.customer.email = c.xpath('email').text end else customers = FakeChargify.customers.repository.select { |c| c.reference == e.xpath('customer_reference').text } subscription.customer = customers.first end e.xpath('credit_card_attributes').map do |cc| subscription.credit_card = CreditCard.new subscription.credit_card.full_number = cc.xpath('full_number').text subscription.credit_card.expiration_month = cc.xpath('expiration_month').text.to_i subscription.credit_card.expiration_year = cc.xpath('expiration_year').text.to_i end end subscription end |
Instance Method Details
#to_xml ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/fake_chargify/subscription.rb', line 11 def to_xml builder = Nokogiri::XML::Builder.new do |xml| xml.subscription { xml.id_ id xml.state state xml.balance_in_cents balance_in_cents xml.current_period_started_at current_period_started_at xml.current_period_ends_at current_period_ends_at xml.trial_started_at trial_started_at xml.trial_ended_at trial_ended_at xml.activated_at activated_at xml.expires_at expires_at xml.created_at created_at xml.updated_at updated_at xml << Nokogiri.XML(customer.to_xml).root.to_xml unless customer.nil? xml << Nokogiri.XML(product.to_xml).root.to_xml unless product.nil? xml << Nokogiri.XML(credit_card.to_xml).root.to_xml unless credit_card.nil? } end builder.to_xml end |