Class: TheCity::Donation

Inherits:
ApiObject show all
Defined in:
lib/api/donation.rb

Instance Attribute Summary

Attributes inherited from ApiObject

#error_messages, #marked_for_destruction

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApiObject

__tc_attributes, #delete, #initialize_from_json_object, #is_deleted?, #save, #set_attributes, tc_attr_accessor, #to_attributes

Constructor Details

#initialize(reader = nil) ⇒ Donation

Constructor.

Parameters:

  • reader (optional) (defaults to: nil)

    The object that has the data. This can be a TheCity::DonationReader or Hash object.



51
52
53
54
55
56
57
# File 'lib/api/donation.rb', line 51

def initialize(reader = nil)
  if reader.is_a?(DonationReader)
    initialize_from_json_object(reader.load_feed) 
  elsif reader.is_a?(Hash)
    initialize_from_json_object(reader)
  end
end

Class Method Details

.load_donation_by_id(pledge_id) ⇒ Object

Loads the donation by the specified ID.

Returns a new TheCity::Donation object.

Parameters:

  • donation_id

    The ID of the donation to load.



41
42
43
44
# File 'lib/api/donation.rb', line 41

def self.load_donation_by_id(pledge_id)
  donation_reader = DonationReader.new(Pledge_id)
  self.new(donation_reader)
end

Instance Method Details

#amount_centsObject

Convert amount to cents.

Returns:

  • Amount in cents.



62
63
64
# File 'lib/api/donation.rb', line 62

def amount_cents 
  (self.amount.to_f * 100).round.to_i
end